Spaces:
Runtime error
Runtime error
File size: 949 Bytes
ab6d29f 001a1f0 ab6d29f 001a1f0 ab6d29f 001a1f0 ab6d29f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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
|