docs: add citation guides for OpenAI and Anthropic#3146
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| } | ||
|
|
||
| // Publish the AI response message | ||
| const { serials: [msgSerial] } = await channel.publish('response', fullText); |
There was a problem hiding this comment.
where does fullText come from? we never actually call processResponse?
There was a problem hiding this comment.
fullText is further up.
I've removed the initiation of processResponse, console logged and then call processResponse when it's created in a later step.
| await channel.subscribe((message) => { | ||
| switch (message.action) { | ||
| case 'message.create': | ||
| console.log('\n[New response]'); | ||
| console.log('Serial:', message.serial); | ||
| console.log('Content:', message.data); | ||
| responses.set(message.serial, { content: message.data, citations: [] }); | ||
| break; | ||
|
|
||
| case 'message.update': | ||
| // Handle streamed content updates | ||
| const response = responses.get(message.serial); | ||
| if (response) { | ||
| response.content = message.data; | ||
| console.log('\n[Response updated]'); | ||
| console.log('Content:', message.data); | ||
| } | ||
| break; | ||
| } | ||
| }); | ||
|
|
||
| // Subscribe to individual citation annotations | ||
| await channel.annotations.subscribe((annotation) => { |
There was a problem hiding this comment.
channel.subscribe(...) isn't processing message.summary action, and channel.annotations.subscribe(...) is for raw annotations.
So this doesn't match the header: "Step 4: Subscribe to citation summaries " which references summaries
There was a problem hiding this comment.
The openapi guide has a different set of headers here that works better to fix this problem
There was a problem hiding this comment.
I've aligned anthropic with the openai guide: 4dd9be4
| // Create response with web search enabled | ||
| async function getOpenAIResponseWithCitations(question) { | ||
| const response = await openai.responses.create({ | ||
| model: "gpt-4.1", |
There was a problem hiding this comment.
we're using gpt-5 in the openai-message-per-response doc, lets just be consistent
854d3df to
f555560
Compare
| --- | ||
|
|
||
| This guide shows you how to attach source citations to AI responses from Anthropic's [Messages API](https://docs.anthropic.com/en/api/messages) using Ably [message annotations](/docs/messages/annotations). When Anthropic provides citations from documents or search results, you can publish them as annotations on Ably messages, enabling clients to display source references alongside AI responses in realtime. | ||
|
|
||
| Using Ably to distribute citations enables you to separate citation metadata from response content, display citation summaries updated in realtime, and retrieve detailed citation data on demand. | ||
|
|
||
| <Aside data-type="further-reading"> | ||
| To learn more about the citations pattern and how message annotations work, see the [citations](/docs/ai-transport/messaging/citations) documentation. | ||
| </Aside> | ||
|
|
There was a problem hiding this comment.
Do we know / have an idea on why you would want to include citations? Like.. why would I care about adding annotations to a message?
There was a problem hiding this comment.
You're right, missing a key bit here. Why use citations. I've updated the intro text: adbef67
7c06253 to
91b3c04
Compare
|
|
||
| This guide shows you how to attach source citations to AI responses from Anthropic's [Messages API](https://docs.anthropic.com/en/api/messages) using Ably [message annotations](/docs/messages/annotations). When Anthropic provides citations from documents or search results, you can publish them as annotations on Ably messages, enabling clients to display source references alongside AI responses in realtime. | ||
|
|
||
| Attaching citations to AI responses enables your users to verify claims against original sources, explore topics in depth, and properly attribute content creators. For enterprises, citations provide explicit traceability between LLM responses and the information sources that were consulted when generating them. |
There was a problem hiding this comment.
what's "enterprises" got to do with it?
This reads a bit janky, around "verify claims against original sources", etc.
Add two new AI Transport guides demonstrating how to attach source citations to AI responses using Ably message annotations: - openai-citations.mdx: Attach citations from OpenAI web search - anthropic-citations.mdx: Attach citations from Anthropic documents Both guides cover: - Enabling message annotations via channel rules - Publishing responses and citations to Ably - Subscribing to citation summaries and individual citations - Combining citations with streaming responses
3033daf to
340e08f
Compare
Add two new AI Transport guides demonstrating how to attach source citations to AI responses using Ably message annotations:
Both guides cover: