define api spec

This commit is contained in:
Jeremy Yin 2024-03-14 17:33:11 +08:00
parent 7fee4dc118
commit 1d1c70be6f
5 changed files with 68 additions and 0 deletions

0
src/simplylab/conf.py Normal file
View File

32
src/simplylab/entity.py Normal file
View File

@ -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

36
src/simplylab/main.py Normal file
View File

@ -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

View File

0
src/simplylab/service.py Normal file
View File