coolai / main.py
TintinMeimei's picture
Update main.py
4dc00e6
raw
history blame
677 Bytes
from fastapi import FastAPI
import openai
openai.api_key = "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"
app = FastAPI()
app.mount("/", StaticFiles(directory="static", html=True), name="static")
@app.get("/")
def index() -> FileResponse:
return FileResponse(path="/app/static/index.html", media_type="text/html")
@app.get("/infer_chatgpt")
def chatgpt(input):
try:
prompt = {"role": "user", "content": input}
result = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[prompt])
output = result.get('choices')[0].get('message').get('content')
except Exception as e:
output = str(e)
return {"output": output}