Skip to content
Merged
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
10 changes: 9 additions & 1 deletion backend/app/rag/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ def generate_document_summary(filePath: str, max_sentences: int = 3) -> str | No
max_tokens=settings.SUMMARY_MAX_TOKENS,
temperature=settings.LLM_TEMPERATURE,
)
summary = response.choices[0].message.content.strip() if response.choices else None

# Defensive check for malformed or empty response structures
summary = None
if response and getattr(response, "choices", None):
first_choice = response.choices[0]
message = getattr(first_choice, "message", None)
content = getattr(message, "content", None)
if content:
summary = content.strip()

return summary if summary else None

Expand Down
Loading