Spaces:
Sleeping
Sleeping
| """Response formatting helpers.""" | |
| import json | |
| from typing import Any, Dict, List | |
| def build_context_block(results: List[Dict]) -> str: | |
| context_parts = [] | |
| for i, r in enumerate(results, 1): | |
| context_parts.append( | |
| f"[Source {i}: {r.get('document_name', 'Unknown')}, " | |
| f"Page {r.get('page_number', '?')}, " | |
| f"Section: {r.get('section', 'general')}]\n{r.get('text', '')}" | |
| ) | |
| return "\n\n---\n\n".join(context_parts) | |
| def format_sse_event(event_type: str, data: Any) -> str: | |
| payload = {"type": event_type, "data": data} | |
| return f"data: {json.dumps(payload)}\n\n" | |
| def format_citation(source: Dict) -> str: | |
| return ( | |
| f"{source.get('document_name', 'Unknown')} " | |
| f"(p.{source.get('page_number', '?')}, {source.get('section', 'general')})" | |
| ) | |