aef8791151
- Added Appshell component with responsive navbar and main content area - Integrated ColorSchemeToggle for light/dark mode switching - Created Welcome component with styled title and introductory text - Developed ChatPage for LLM interaction with WebSocket support - Implemented Biblioteca for managing notes with rich text editor - Added LoginPage for user authentication with error handling - Introduced MessageList and MessageBubble components for chat messages - Styled components with CSS modules for consistent design
45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
# backend/domains/llm/agent_endpoints.py
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from fastapi.responses import StreamingResponse
|
|
from pydantic import BaseModel
|
|
from fastapi.concurrency import run_in_threadpool
|
|
|
|
from backend.backend_domains.llms.llm_chat_srvc import construir_agente_llm, responder, responder_stream
|
|
from domains.Logger.logger_db import LoggerDB, logger
|
|
from entrypoint.init_db import db_credencial
|
|
|
|
LoggerDB(db_credencial, "logger_llm", created_by="sistema")
|
|
|
|
router = APIRouter()
|
|
agente = construir_agente_llm() # inicializa el agente una vez
|
|
|
|
# 📥 Schema para entrada de prompt
|
|
class ChatInput(BaseModel):
|
|
prompt: str
|
|
|
|
# ✅ Endpoint de respuesta simple
|
|
@router.post("/chat", summary="Enviar prompt y obtener respuesta completa del agente")
|
|
async def chat_endpoint(data: ChatInput):
|
|
try:
|
|
return await responder(data.prompt, agente)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
except Exception as e:
|
|
logger.exception("[ERROR] Fallo durante respuesta del agente:")
|
|
raise HTTPException(status_code=500, detail="Error interno al procesar la solicitud.")
|
|
|
|
# 🔁 Endpoint de streaming
|
|
@router.post("/chat-stream", summary="Enviar prompt y recibir respuesta del agente en streaming")
|
|
async def chat_stream_endpoint(data: ChatInput):
|
|
try:
|
|
return StreamingResponse(
|
|
responder_stream(data.prompt, agente),
|
|
media_type="text/plain"
|
|
)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
except Exception as e:
|
|
logger.exception("[ERROR] Fallo durante respuesta en streaming:")
|
|
raise HTTPException(status_code=500, detail="Error interno en el agente.")
|