mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-05-24 14:33:26 +00:00
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
import uuid
|
|
|
|
import fastapi
|
|
|
|
import lib.agent as agent
|
|
import lib.models as models
|
|
|
|
|
|
class AgentHandler:
|
|
def __init__(self, chat_history_repository: agent.ChatHistoryRepository):
|
|
self.chat_history_repository = chat_history_repository
|
|
self.router = fastapi.APIRouter()
|
|
self.router.add_api_route(
|
|
"/",
|
|
self.get_agent,
|
|
methods=["GET"],
|
|
summary="Статус работоспособности",
|
|
description="Проверяет доступность сервиса FastAPI.",
|
|
)
|
|
self.router.add_api_route(
|
|
"/add",
|
|
self.add_message,
|
|
methods=["GET"],
|
|
summary="Статус работоспособности",
|
|
description="Проверяет доступность сервиса FastAPI.",
|
|
)
|
|
|
|
async def get_agent(self):
|
|
request = models.RequestLastSessionId(channel="test", user_id="user_id_1", minutes_ago=3)
|
|
response = await self.chat_history_repository.get_last_session_id(request=request)
|
|
print("RESPONSE: ", response)
|
|
return {"response": response}
|
|
|
|
async def add_message(self):
|
|
sid: uuid.UUID = uuid.UUID("0cd3c882-affd-4929-aff1-e1724f5b54f2")
|
|
import faker
|
|
fake = faker.Faker()
|
|
|
|
message = models.ChatMessage(
|
|
session_id=sid, user_id="user_id_1", channel="test", message={"role": "system", "content": fake.sentence()}
|
|
)
|
|
await self.chat_history_repository.add_message(request=message)
|
|
return {"response": "ok"}
|