22 lines
394 B
Python
22 lines
394 B
Python
import os
|
|
|
|
import openai
|
|
from fastapi import FastAPI
|
|
|
|
app = FastAPI()
|
|
|
|
openai.api_key = os.getenv("OPEN_AI_KEY")
|
|
|
|
|
|
@app.get("/getAns")
|
|
async def root(msg: str):
|
|
return {"ans": get_ans(msg)}
|
|
|
|
|
|
def get_ans(msg):
|
|
return openai.ChatCompletion.create(
|
|
model="gpt-3.5-turbo",
|
|
messages=[
|
|
{"role": "user", "content": msg},
|
|
]
|
|
).choices[0].message.content
|