move res to service
This commit is contained in:
parent
012f23a745
commit
a201a779e7
|
@ -24,18 +24,19 @@ async def read_root():
|
|||
@app.post("/api/v1/get_ai_chat_response")
|
||||
async def get_ai_chat_response(req: GetAiChatResponseInput) -> GetAiChatResponseOutput:
|
||||
svc = Services(req)
|
||||
response = await svc.chat.get_ai_chat_response(req)
|
||||
res = GetAiChatResponseOutput(response=response)
|
||||
res = await svc.chat.get_ai_chat_response(req)
|
||||
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")]
|
||||
svc = Services(req)
|
||||
res = await svc.chat.get_user_chat_history(req)
|
||||
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)
|
||||
svc = Services(req)
|
||||
res = await svc.chat.get_chat_status_today(req)
|
||||
return res
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from typing import Any
|
||||
|
||||
from simplylab.entity import GetAiChatResponseInput
|
||||
from simplylab.entity import GetAiChatResponseInput, GetUserChatHistoryInput, GetChatStatusTodayInput, UserChatMessage, \
|
||||
GetChatStatusTodayOutput, GetAiChatResponseOutput, GetUserChatHistoryOutput
|
||||
from simplylab.providers import Providers
|
||||
|
||||
|
||||
|
@ -8,8 +9,17 @@ class ChatService:
|
|||
def __init__(self, ctx: Any):
|
||||
self.ctx = ctx
|
||||
|
||||
async def get_ai_chat_response(self, req: GetAiChatResponseInput) -> str:
|
||||
async def get_ai_chat_response(self, req: GetAiChatResponseInput) -> GetAiChatResponseOutput:
|
||||
pvd = Providers()
|
||||
message = req.message
|
||||
response_content = await pvd.openrouter.chat(content=message)
|
||||
return response_content
|
||||
res = GetAiChatResponseOutput(response=response_content)
|
||||
return res
|
||||
|
||||
async def get_user_chat_history(self, req: GetUserChatHistoryInput) -> GetUserChatHistoryOutput:
|
||||
res = [UserChatMessage(type="user", text="echo")]
|
||||
return res
|
||||
|
||||
async def get_chat_status_today(self, req: GetChatStatusTodayInput) -> GetChatStatusTodayOutput:
|
||||
res = GetChatStatusTodayOutput(user_name=req.user_name, chat_cnt=0)
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue