Skip to content
Open
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
14 changes: 11 additions & 3 deletions application/api/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import traceback
from fastapi import APIRouter, WebSocket, WebSocketDisconnect, status
from fastapi import APIRouter, WebSocket, WebSocketDisconnect, status, HTTPException

from nlq.business.log_store import LogManagement
from nlq.business.profile import ProfileManagement
Expand Down Expand Up @@ -33,7 +33,15 @@ def option(id: str=None):
@router.get("/get_custom_question", response_model=CustomQuestion)
def get_custom_question(data_profile: str):
all_profiles = ProfileManagement.get_all_profiles_with_info()
comments = all_profiles[data_profile]['comments']

# FIX: Check if profile exists before accessing
if data_profile not in all_profiles:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Profile '{data_profile}' not found."
)

comments = all_profiles[data_profile].get('comments', '')
comments_questions = []
if len(comments.split("Examples:")) > 1:
comments_questions_txt = comments.split("Examples:")[1]
Expand Down Expand Up @@ -233,4 +241,4 @@ async def response_websocket(websocket: WebSocket, session_id: str, content,
}
logger.info(content_obj)
final_content = json.dumps(content_obj, default=serialize_timestamp)
await websocket.send_text(final_content)
await websocket.send_text(final_content)