-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (25 loc) · 888 Bytes
/
main.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
from fastapi import FastAPI
from typing import Optional
from pydantic import BaseModel
from common.response import get_reply
import logging
class Conversation(BaseModel):
user_id: int
sentence: str
character_name: str
def __str__(self):
return '{\n\tuser_id:%d\n\tsentence:%s\n\tcharacter_name:%s\n}' % (self.user_id, self.sentence, self.character_name)
app = FastAPI()
logging.basicConfig(
level=logging.DEBUG,
format="%(levelname)s: %(asctime)s - %(message)s"
)
@app.get("/test")
def test():
return {"message": "Server running"}
@app.post("/conversation")
def get_response(conversation: Conversation):
logging.debug('Request content\n' + str(conversation))
res = get_reply(user_id=str(conversation.user_id),
sentence=conversation.sentence, character_name=conversation.character_name)
return {"text": res}