From 1d1c70be6f2600cd86aa99eac4579aa4761004d3 Mon Sep 17 00:00:00 2001 From: Jeremy Yin Date: Thu, 14 Mar 2024 17:33:11 +0800 Subject: [PATCH] define api spec --- src/simplylab/conf.py | 0 src/simplylab/entity.py | 32 ++++++++++++++++++++++++++++++++ src/simplylab/main.py | 36 ++++++++++++++++++++++++++++++++++++ src/simplylab/provider.py | 0 src/simplylab/service.py | 0 5 files changed, 68 insertions(+) create mode 100644 src/simplylab/conf.py create mode 100644 src/simplylab/entity.py create mode 100644 src/simplylab/main.py create mode 100644 src/simplylab/provider.py create mode 100644 src/simplylab/service.py diff --git a/src/simplylab/conf.py b/src/simplylab/conf.py new file mode 100644 index 0000000..e69de29 diff --git a/src/simplylab/entity.py b/src/simplylab/entity.py new file mode 100644 index 0000000..ed402ac --- /dev/null +++ b/src/simplylab/entity.py @@ -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 diff --git a/src/simplylab/main.py b/src/simplylab/main.py new file mode 100644 index 0000000..33251d9 --- /dev/null +++ b/src/simplylab/main.py @@ -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 diff --git a/src/simplylab/provider.py b/src/simplylab/provider.py new file mode 100644 index 0000000..e69de29 diff --git a/src/simplylab/service.py b/src/simplylab/service.py new file mode 100644 index 0000000..e69de29