-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.py
45 lines (35 loc) · 1.02 KB
/
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
'''
Description:
Author: colin gao
Date: 2023-05-17 15:54:12
LastEditTime: 2023-05-26 23:05:56
'''
from fastapi.middleware.cors import CORSMiddleware
from fastapi import FastAPI
from schema import ChatItem
from chatbot import get_chain
from utils import logger, test_youtube_access
from dotenv import load_dotenv
load_dotenv()
test_youtube_access()
app = FastAPI()
app.add_middleware(CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"])
conversation_chat = get_chain()
@app.post("/chat", summary="chat接口", description="该接口为chat的接口")
def chat(item: ChatItem):
question = item.text
result = conversation_chat(question)
logger.info(f"chat result is {result['response']}")
return {
"result": result['response']
}
@app.get("/ping")
async def ping():
return "pong!!"
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=9000)