Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async def handle_chat():

# Extract request fields
conversation_id = data.get("conversation_id") or str(uuid.uuid4())
user_id = data.get("user_id", "anonymous")
user_id = data.get("user_id") or "anonymous"
message = data.get("message", "")
action = data.get("action")
payload = data.get("payload", {})
Expand Down Expand Up @@ -337,7 +337,7 @@ async def _handle_parse_brief(

if not has_existing_title:
title_service = get_title_service()
generated_title = await title_service.generate_title(message)
generated_title = await title_service.generate_title(message, user_id=user_id, conversation_id=conversation_id)

await cosmos_service.add_message_to_conversation(
conversation_id=conversation_id,
Expand All @@ -353,7 +353,8 @@ async def _handle_parse_brief(
logger.exception(f"Failed to save message to CosmosDB: {e}")

# Parse the brief
brief, questions, blocked = await orchestrator.parse_brief(message)
brief, questions, blocked = await orchestrator.parse_brief(message, user_id=user_id, conversation_id=conversation_id)
brief, questions, blocked = await orchestrator.parse_brief(message, user_id=user_id, conversation_id=conversation_id)
Comment on lines +356 to +357

if blocked:
track_event_if_configured("Error_RAI_Check_Failed", {"conversation_id": conversation_id, "user_id": user_id, "status": "Brief parse blocked by RAI"})
Expand Down Expand Up @@ -537,7 +538,7 @@ async def _handle_refine_brief(
logger.exception(f"Failed to save refinement message: {e}")

# Use orchestrator to refine the brief
brief, questions, blocked = await orchestrator.parse_brief(message)
brief, questions, blocked = await orchestrator.parse_brief(message, user_id=user_id, conversation_id=conversation_id)

if blocked:
track_event_if_configured("Error_RAI_Check_Failed", {"conversation_id": conversation_id, "user_id": user_id, "status": "Brief refinement blocked by RAI"})
Expand Down Expand Up @@ -943,7 +944,9 @@ async def _run_regeneration_task(
modification_request=modification_request,
brief=brief,
products=products_data,
previous_image_prompt=previous_image_prompt
previous_image_prompt=previous_image_prompt,
user_id=user_id,
conversation_id=conversation_id
)

# Check for RAI block
Expand Down Expand Up @@ -1132,7 +1135,7 @@ async def _handle_general_chat(

if not has_existing_title:
title_service = get_title_service()
generated_title = await title_service.generate_title(message)
generated_title = await title_service.generate_title(message, user_id=user_id, conversation_id=conversation_id)

await cosmos_service.add_message_to_conversation(
conversation_id=conversation_id,
Expand All @@ -1151,7 +1154,8 @@ async def _handle_general_chat(
response_content = ""
async for response in orchestrator.process_message(
message=message,
conversation_id=conversation_id
conversation_id=conversation_id,
user_id=user_id
):
if response.get("content"):
response_content += response.get("content", "")
Expand Down Expand Up @@ -1197,7 +1201,9 @@ async def _run_generation_task(task_id: str, brief: CreativeBrief, products_data
response = await orchestrator.generate_content(
brief=brief,
products=products_data,
generate_images=generate_images
generate_images=generate_images,
user_id=user_id,
conversation_id=conversation_id
)

logger.info(f"Generation task {task_id} completed. Response keys: {list(response.keys()) if response else 'None'}")
Expand Down Expand Up @@ -1303,7 +1309,7 @@ async def start_generation():
products_data = data.get("products", [])
generate_images = data.get("generate_images", True)
conversation_id = data.get("conversation_id") or str(uuid.uuid4())
user_id = data.get("user_id", "anonymous")
user_id = data.get("user_id") or "anonymous"

try:
brief = CreativeBrief(**brief_data)
Expand Down
Loading