Spaces:
Runtime error
Runtime error
| def generate_citations(search_results): | |
| """Generate citations from structured search results""" | |
| try: | |
| citations = [] | |
| for result in search_results: | |
| if result.get("type") == "source" and result.get("url"): | |
| citations.append({ | |
| "source": result.get("title", "Unknown Source"), | |
| "url": result.get("url") | |
| }) | |
| return citations | |
| except Exception as e: | |
| return [{"error": f"Citation generation failed: {str(e)}"}] | |
| def format_citations(citations): | |
| """Format citations for display""" | |
| if not citations: | |
| return "" | |
| formatted = "\n\n**Sources:**\n" | |
| for i, citation in enumerate(citations, 1): | |
| if "error" in citation: | |
| return f"\n\n**Citation Error:** {citation['error']}" | |
| formatted += f"{i}. [{citation.get('source', 'Unknown Source')}]({citation.get('url', '#')})\n" | |
| return formatted | |