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