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")
|
@app.post("/api/v1/get_ai_chat_response")
|
||||||
async def get_ai_chat_response(req: GetAiChatResponseInput) -> GetAiChatResponseOutput:
|
async def get_ai_chat_response(req: GetAiChatResponseInput) -> GetAiChatResponseOutput:
|
||||||
svc = Services(req)
|
svc = Services(req)
|
||||||
response = await svc.chat.get_ai_chat_response(req)
|
res = await svc.chat.get_ai_chat_response(req)
|
||||||
res = GetAiChatResponseOutput(response=response)
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/v1/get_user_chat_history")
|
@app.post("/api/v1/get_user_chat_history")
|
||||||
async def get_user_chat_history(req: GetUserChatHistoryInput) -> GetUserChatHistoryOutput:
|
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
|
return res
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/v1/get_chat_status_today")
|
@app.post("/api/v1/get_chat_status_today")
|
||||||
async def get_chat_status_today(req: GetChatStatusTodayInput) -> GetChatStatusTodayOutput:
|
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
|
return res
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from typing import Any
|
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
|
from simplylab.providers import Providers
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,8 +9,17 @@ class ChatService:
|
||||||
def __init__(self, ctx: Any):
|
def __init__(self, ctx: Any):
|
||||||
self.ctx = ctx
|
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()
|
pvd = Providers()
|
||||||
message = req.message
|
message = req.message
|
||||||
response_content = await pvd.openrouter.chat(content=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