-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add Anthropic Citation API support #8721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for Anthropic's Citation API through two new types: dspy.Document
for providing source content to language models and dspy.Citations
for handling citation responses. The implementation enables citation-enabled responses from models like Claude, allowing developers to track which parts of the generated text reference specific source documents.
Key changes:
- Added
Document
type for representing citable source content with metadata - Added
Citations
type for handling citation responses with character-level location information - Integrated citation extraction into the base language model processing pipeline
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
dspy/adapters/types/document.py |
New Document type with content, title, and metadata fields for citation-enabled content |
dspy/adapters/types/citation.py |
New Citations type with nested Citation class for handling citation responses |
dspy/clients/base_lm.py |
Added citation extraction from LiteLLM provider-specific fields |
dspy/adapters/base.py |
Integrated citation processing into adapter postprocessing pipeline |
dspy/adapters/__init__.py |
Exported new Citation and Document types |
dspy/__init__.py |
Made Citation and Document types available at package level |
tests/adapters/test_document.py |
Comprehensive tests for Document type validation and formatting |
tests/adapters/test_citation.py |
Tests for Citation types, extraction, and adapter integration |
Comments suppressed due to low confidence (1)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Add support for Anthropic Citation API through new types (dspy.Document, dspy.Citation). The design strategy is the same as dspy.Tool & dspy.ToolCalls.
Example
References