31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends
|
|
from fastapi.responses import StreamingResponse
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.clients.shared_ai_platform import SharedAIPlatformClient, build_shared_ai_platform_client
|
|
from app.api.reviews import require_current_user
|
|
from app.db import get_db_session
|
|
from app.schemas.chat import ChatStreamRequest
|
|
|
|
router = APIRouter(prefix="/chat", tags=["chat"])
|
|
ROUTE_PERMISSION_SCOPE = "chat"
|
|
ROUTE_PERMISSION_ACTIONS = {
|
|
"stream": "chat:stream",
|
|
}
|
|
|
|
|
|
def get_shared_ai_platform_client(db: Session = Depends(get_db_session)) -> SharedAIPlatformClient:
|
|
return build_shared_ai_platform_client(db)
|
|
|
|
|
|
@router.post("/stream")
|
|
def stream_chat(
|
|
payload: ChatStreamRequest,
|
|
shared_ai_platform_client: SharedAIPlatformClient = Depends(get_shared_ai_platform_client),
|
|
current_user: dict = Depends(require_current_user),
|
|
):
|
|
return StreamingResponse(
|
|
shared_ai_platform_client.stream_answer(current_user, payload.conversation_id, payload.message, payload.review_context),
|
|
media_type="text/event-stream",
|
|
)
|