-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(anthropic): add new citation types #11462
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
e94a61f to
fda7157
Compare
aayush-kapoor
left a comment
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.
do you have a specific instance of a code snippet where anthropic will return these types? will make it very easy to verify. no worries if not
|
Here is the examples provided in the official documentation: content_block_location: https://platform.claude.com/docs/en/build-with-claude/citations#custom-content-documents search_result_location: https://platform.claude.com/docs/en/build-with-claude/search-results#example-direct-search-results |
Move the citation schema definition to a shared constant to avoid duplication and improve maintainability
…n to textCitationSchema
1c18681 to
a69f307
Compare
|
i have approved it - but before merging, please add unit tests (using fixtures as described in https://github.com/vercel/ai/blob/main/contributing/testing.md#manual-testing) |
aayush-kapoor
left a comment
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.
i also realised we need to make the proper changes in anthropic-messages-language-model.ts to allow for these citation types to be passed
|
Hello, I’ve carefully reviewed the use cases provided by Claude and identified the following issue:
For example: https://platform.claude.com/docs/en/build-with-claude/search-results#example-direct-search-results messages: [
{
role: "user",
content: [
{
type: "search_result" as const,
source: "https://docs.company.com/api-reference",
title: "API Reference - Authentication",
content: [
{
type: "text" as const,
text: "All API requests must include an API key in the Authorization header. Keys can be generated from the dashboard. Rate limits: 1000 requests per hour for standard tier, 10000 for premium."
}
],
citations: { enabled: true }
},
{
type: "search_result" as const,
source: "https://docs.company.com/quickstart",
title: "Getting Started Guide",
content: [
{
type: "text" as const,
text: "To get started: 1) Sign up for an account, 2) Generate an API key from the dashboard, 3) Install our SDK using pip install company-sdk, 4) Initialize the client with your API key."
}
],
citations: { enabled: true }
},
{
type: "text" as const,
text: "Based on these search results, how do I authenticate API requests and what are the rate limits?"
}
]
}
]As you can see, there is a Claude-specific
This type of content does not belong to any of the current UserContent interfaces. This means we need to make more changes than we’d imagined to support this feature, because we don’t currently support this type of UserContent.
See: https://platform.claude.com/docs/en/build-with-claude/citations#custom-content-documents {
"type": "document",
"source": {
"type": "content",
"content": [
{"type": "text", "text": "First chunk"},
{"type": "text", "text": "Second chunk"}
]
},
"title": "Document Title", # optional
"context": "Context about the document that will not be cited from", # optional
"citations": {"enabled": True}
}Here, we might want to use ai/packages/anthropic/src/convert-to-anthropic-messages-prompt.ts Lines 183 to 185 in 8940d47
Of course, we could also use Since these two features require significant changes, I don’t think they should all be implemented in this single PR. Additionally, given that implementing these features may very likely necessitate modifying existing generic interfaces, we should discuss further whether it is truly necessary to implement them. |
Background
The Anthropic API has added new text citation types (
content_block_locationandsearch_result_location) that are not yet supported by the AI SDK. Additionally, the citation schema was duplicated in both response and chunk schemas, making maintenance harder.See https://platform.claude.com/docs/en/api/typescript/messages#text_citation
Summary
textCitationSchemafor reuse across response and chunk schemas, improving maintainabilitycontent_block_locationandsearch_result_locationManual Verification
N/A - schema changes only, no runtime behavior change for existing citation types.
Checklist
pnpm changesetin the project root)