define api spec
This commit is contained in:
parent
7fee4dc118
commit
1d1c70be6f
|
@ -0,0 +1,32 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class GetAiChatResponseInput(BaseModel):
|
||||
message: str
|
||||
user_name: str
|
||||
|
||||
|
||||
class GetAiChatResponseOutput(BaseModel):
|
||||
response: str
|
||||
|
||||
|
||||
class GetUserChatHistoryInput(BaseModel):
|
||||
user_name: str
|
||||
last_n: int
|
||||
|
||||
|
||||
class UserChatMessage(BaseModel):
|
||||
type: str
|
||||
text: str
|
||||
|
||||
|
||||
type GetUserChatHistoryOutput = list[UserChatMessage]
|
||||
|
||||
|
||||
class GetChatStatusTodayInput(BaseModel):
|
||||
user_name: str
|
||||
|
||||
|
||||
class GetChatStatusTodayOutput(BaseModel):
|
||||
user_name: str
|
||||
chat_cnt: int
|
|
@ -0,0 +1,36 @@
|
|||
from typing import Union
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .entity import GetAiChatResponseInput
|
||||
from .entity import GetAiChatResponseOutput
|
||||
from .entity import GetUserChatHistoryInput
|
||||
from .entity import GetUserChatHistoryOutput
|
||||
from .entity import GetChatStatusTodayInput
|
||||
from .entity import GetChatStatusTodayOutput
|
||||
from .entity import UserChatMessage
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def read_root():
|
||||
return {"Hello": "World"}
|
||||
|
||||
|
||||
@app.post("/api/v1/get_ai_chat_response")
|
||||
async def get_ai_chat_response(req: GetAiChatResponseInput) -> GetAiChatResponseOutput:
|
||||
res = GetAiChatResponseOutput(response="Hello World")
|
||||
return res
|
||||
|
||||
|
||||
@app.post("/api/v1/get_user_chat_history")
|
||||
async def get_user_chat_history(req: GetUserChatHistoryInput) -> GetUserChatHistoryOutput:
|
||||
res = [UserChatMessage(type="user", text="echo")]
|
||||
return res
|
||||
|
||||
|
||||
@app.post("/api/v1/get_chat_status_today")
|
||||
async def get_chat_status_today(req: GetChatStatusTodayInput) -> GetChatStatusTodayOutput:
|
||||
res = GetChatStatusTodayOutput(user_name=req.user_name, chat_cnt=0)
|
||||
return res
|
Loading…
Reference in New Issue