lmt commited on
Commit ·
9c1b67f
1
Parent(s): b9f9a37
更新
Browse files
main.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from typing import Dict, List
|
| 2 |
import os
|
| 3 |
from fastapi import FastAPI
|
|
|
|
| 4 |
import requests
|
| 5 |
|
| 6 |
api_key = os.environ.get('api_key')
|
|
@@ -15,9 +16,16 @@ def read_root():
|
|
| 15 |
return {"Hello": "World!"}
|
| 16 |
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
@app.post("/api/chat")
|
| 19 |
-
def chat(
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
res = get_response(initial_prompt, history)
|
| 22 |
return res
|
| 23 |
|
|
|
|
| 1 |
from typing import Dict, List
|
| 2 |
import os
|
| 3 |
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
import requests
|
| 6 |
|
| 7 |
api_key = os.environ.get('api_key')
|
|
|
|
| 16 |
return {"Hello": "World!"}
|
| 17 |
|
| 18 |
|
| 19 |
+
class Item(BaseModel):
|
| 20 |
+
input: str
|
| 21 |
+
history: List[Dict] = []
|
| 22 |
+
|
| 23 |
+
|
| 24 |
@app.post("/api/chat")
|
| 25 |
+
def chat(item: Item):
|
| 26 |
+
item_dict = item.dict()
|
| 27 |
+
|
| 28 |
+
history = item_dict.history.append(construct_user(item_dict.input))
|
| 29 |
res = get_response(initial_prompt, history)
|
| 30 |
return res
|
| 31 |
|