TintinMeimei commited on
Commit
4dc00e6
1 Parent(s): 296977c

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -4
main.py CHANGED
@@ -4,8 +4,18 @@ openai.api_key = "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"
4
 
5
  app = FastAPI()
6
 
 
 
7
  @app.get("/")
8
- def read_root():
9
- input = {"role": "user", "content": "Translate this sentence to French. Sentence: I can speak Chinese."}
10
- output = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[input])
11
- return {"Input": input, "Output": output}
 
 
 
 
 
 
 
 
 
4
 
5
  app = FastAPI()
6
 
7
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
8
+
9
  @app.get("/")
10
+ def index() -> FileResponse:
11
+ return FileResponse(path="/app/static/index.html", media_type="text/html")
12
+
13
+ @app.get("/infer_chatgpt")
14
+ def chatgpt(input):
15
+ try:
16
+ prompt = {"role": "user", "content": input}
17
+ result = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[prompt])
18
+ output = result.get('choices')[0].get('message').get('content')
19
+ except Exception as e:
20
+ output = str(e)
21
+ return {"output": output}