From 605f84688ee0bcfbb57612e73728a92ed9fe59e9 Mon Sep 17 00:00:00 2001 From: Jeremy Yin Date: Fri, 15 Mar 2024 22:45:53 +0800 Subject: [PATCH] change to get --- simplylab/main.py | 10 +++++----- simplylab/services/chat.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/simplylab/main.py b/simplylab/main.py index 4018e6d..22f9170 100644 --- a/simplylab/main.py +++ b/simplylab/main.py @@ -83,15 +83,15 @@ async def get_ai_chat_response(request: Request, req: GetAiChatResponseInput) -> return res -@app.post("/api/v1/get_user_chat_history") -async def get_user_chat_history(request: Request, req: GetUserChatHistoryInput) -> GetUserChatHistoryOutput: +@app.get("/api/v1/get_user_chat_history") +async def get_user_chat_history(request: Request, user_name: str, last_n: int) -> GetUserChatHistoryOutput: pvd = Providers(db=request.app.db) - user = await pvd.user.get_user_by_name(req.user_name) + user = await pvd.user.get_user_by_name(user_name) if not user: - raise UserNotFoundError(req.user_name) + raise UserNotFoundError(user_name) ctx = Context(user=user) svc = Services(ctx, pvd) - res = await svc.chat.get_user_chat_history(req) + res = await svc.chat.get_user_chat_history(last_n=last_n) return res diff --git a/simplylab/services/chat.py b/simplylab/services/chat.py index 5e06ea5..6050ff1 100644 --- a/simplylab/services/chat.py +++ b/simplylab/services/chat.py @@ -40,8 +40,8 @@ class ChatService: res = GetAiChatResponseOutput(response=response_content) return res - async def get_user_chat_history(self, req: GetUserChatHistoryInput) -> GetUserChatHistoryOutput: - messages = await self.pvd.chat.get_user_chat_messages(user_id=self.ctx.user.id, limit=req.last_n) + async def get_user_chat_history(self, last_n: int) -> GetUserChatHistoryOutput: + messages = await self.pvd.chat.get_user_chat_messages(user_id=self.ctx.user.id, limit=last_n) res = [] for message in messages: res.append(UserChatMessage(type=message.type.value, text=message.text))