Spaces:
Configuration error
Configuration error
File size: 1,462 Bytes
aa15bce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from fastapi import APIRouter
from fastapi.responses import JSONResponse
from ..models import ChatHistoryClearResponse, ChatHistoryResponse, ChatRequest
from ..services import get_conversation_log, get_trigger_service, handle_chat_request
router = APIRouter(prefix="/chat", tags=["chat"])
@router.post("/send", response_class=JSONResponse, summary="Submit a chat message and receive a completion")
# Handle incoming chat messages and route them to the interaction agent
async def chat_send(
payload: ChatRequest,
) -> JSONResponse:
return await handle_chat_request(payload)
@router.get("/history", response_model=ChatHistoryResponse)
# Retrieve the conversation history from the log
def chat_history() -> ChatHistoryResponse:
log = get_conversation_log()
return ChatHistoryResponse(messages=log.to_chat_messages())
@router.delete("/history", response_model=ChatHistoryClearResponse)
def clear_history() -> ChatHistoryClearResponse:
from ..services import get_execution_agent_logs, get_agent_roster
# Clear conversation log
log = get_conversation_log()
log.clear()
# Clear execution agent logs
execution_logs = get_execution_agent_logs()
execution_logs.clear_all()
# Clear agent roster
roster = get_agent_roster()
roster.clear()
# Clear stored triggers
trigger_service = get_trigger_service()
trigger_service.clear_all()
return ChatHistoryClearResponse()
__all__ = ["router"]
|