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
9 changes: 6 additions & 3 deletions forecasting_tools/ai_models/general_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,19 @@ def _extract_citations(
return typeguard.check_type(citations, list[str])

# OpenRouter returns Perplexity citations as url_citation annotations
# rather than in model_extra["citations"]. URLs may be duplicated
# (e.g. once with titles, once without). We deduplicate while
# preserving first-seen order so urls[i] corresponds to [i+1].
# rather than in model_extra["citations"]. Annotations may arrive as
# dicts (older SDKs) or pydantic objects (newer SDKs). URLs may be
# duplicated (e.g. once with titles, once without). We deduplicate
# while preserving first-seen order so urls[i] corresponds to [i+1].
message = choices[0].message
annotations = getattr(message, "annotations", None)
if not annotations:
return []
seen: set[str] = set()
unique_urls: list[str] = []
for annotation in annotations:
if hasattr(annotation, "model_dump"):
annotation = annotation.model_dump()
if not isinstance(annotation, dict):
continue
if annotation.get("type") != "url_citation":
Expand Down
Loading