fix: wire image uploads into correct chat endpoint (unified_chat_service)
The frontend calls /ai-sessions/{id}/chat (unified_chat_service), not
/assistant/chats/{id}/messages (assistant_chat_service). The previous
commit wired images into the wrong backend. This fixes it:
- ai_session.py schema: add upload_ids to ChatMessageRequest
- ai_sessions.py endpoint: fetch images via _fetch_upload_images
- unified_chat_service: accept and forward images to _call_ai
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -280,6 +280,12 @@ async def send_chat_message(
|
|||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
account_id = current_user.account_id
|
account_id = current_user.account_id
|
||||||
|
|
||||||
|
# Fetch attached images from S3 (if any)
|
||||||
|
images = None
|
||||||
|
if data.upload_ids:
|
||||||
|
from app.api.endpoints.assistant_chat import _fetch_upload_images
|
||||||
|
images = await _fetch_upload_images(data.upload_ids, account_id, db) or None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ai_content, suggested_flows, session = await unified_chat_service.send_chat_message(
|
ai_content, suggested_flows, session = await unified_chat_service.send_chat_message(
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
@@ -287,6 +293,7 @@ async def send_chat_message(
|
|||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
message=data.message,
|
message=data.message,
|
||||||
db=db,
|
db=db,
|
||||||
|
images=images,
|
||||||
)
|
)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ class ChatSessionCreateResponse(BaseModel):
|
|||||||
class ChatMessageRequest(BaseModel):
|
class ChatMessageRequest(BaseModel):
|
||||||
"""Send a message in a chat session."""
|
"""Send a message in a chat session."""
|
||||||
message: str = Field(..., min_length=1, max_length=8000)
|
message: str = Field(..., min_length=1, max_length=8000)
|
||||||
|
upload_ids: list[UUID] = Field(default_factory=list, max_length=10)
|
||||||
|
|
||||||
|
|
||||||
class ChatMessageResponse(BaseModel):
|
class ChatMessageResponse(BaseModel):
|
||||||
|
|||||||
@@ -57,9 +57,14 @@ async def send_chat_message(
|
|||||||
account_id: UUID,
|
account_id: UUID,
|
||||||
message: str,
|
message: str,
|
||||||
db: AsyncSession,
|
db: AsyncSession,
|
||||||
|
images: list[dict[str, Any]] | None = None,
|
||||||
) -> tuple[str, list[dict[str, Any]], AISession]:
|
) -> tuple[str, list[dict[str, Any]], AISession]:
|
||||||
"""Send a message in a chat session and get AI response.
|
"""Send a message in a chat session and get AI response.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
images: Optional list of {"media_type": str, "data": str (base64)}
|
||||||
|
for vision content attached to this message.
|
||||||
|
|
||||||
Returns (ai_content, suggested_flows, session).
|
Returns (ai_content, suggested_flows, session).
|
||||||
"""
|
"""
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
@@ -105,6 +110,7 @@ async def send_chat_message(
|
|||||||
rag_context=rag_context,
|
rag_context=rag_context,
|
||||||
history=ai_messages,
|
history=ai_messages,
|
||||||
new_message=message,
|
new_message=message,
|
||||||
|
images=images,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Append messages to conversation_messages
|
# Append messages to conversation_messages
|
||||||
|
|||||||
Reference in New Issue
Block a user