-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
45 lines (31 loc) · 945 Bytes
/
app.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
import uuid
import json
import logging
import uvicorn
from main import chat_interface
from fastapi import FastAPI, Response
from pydantic import BaseModel, HttpUrl
logger = logging.getLogger(__name__)
app = FastAPI()
class ChatRequest(BaseModel):
message: str
@app.get("/api/health")
def health_check():
return {"status": "ok"}
@app.post("/api/chat")
def chat(request: ChatRequest):
message = request.message
chat_id = str(uuid.uuid4())
json_file_path = f"chats/{chat_id}.json"
with open(json_file_path, "w") as f:
json.dump(
{
"chat_id": chat_id,
"messages": []
},
f
)
html_path = chat_interface(chat_id, message)
return {"status": "ok", "cooking_wiki_page": html_path, "chat_id": chat_id, "json_file_path": json_file_path}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)