File size: 850 Bytes
24d5403
 
ef0dbd8
6e4d27e
 
ba01e1c
869823c
5bedc9d
c2c7360
ef0dbd8
 
ba01e1c
 
 
66b6471
ba01e1c
 
 
 
 
 
 
 
5bedc9d
ef0dbd8
4dc00e6
 
ef0dbd8
4dc00e6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from pydantic import BaseModel
import openai
openai.api_key = os.environ["apikey"]


app = FastAPI()
class ChatInput(BaseModel):
    input: str


@app.post("/infer_chatgpt")
def chatgpt(input: ChatInput):
    try:
        prompt = {"role": "user", "content": input.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 = {"output": str(e)}
    return {"output": output}

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")