Description
Anthropic has introduced relatively recently the Citations feature, which forces the model to add references/footnotes, also called "Grounding" by other providers.
In addition to helping creating content with sources and footnotes, it also apparently helps the model to not hallucinate.
I'm sorry to be that person posting an issue to ask for a feature support :)
But I feel this would be a great add-on to RubyLLM.
That being said, it might have quite a bit impact on how RubyLLM handles the model response, as with citations enabled, the API returns the text sliced intro fragments (with some of them having citations, and some other without any), all this in a JSON payload.
Here is a response payload example (coming from Anthropic's doc):
{
"content": [
{
"type": "text",
"text": "According to the document, "
},
{
"type": "text",
"text": "the grass is green",
"citations": [{
"type": "char_location",
"cited_text": "The grass is green.",
"document_index": 0,
"document_title": "Example Document",
"start_char_index": 0,
"end_char_index": 20
}]
},
{
"type": "text",
"text": " and "
},
{
"type": "text",
"text": "the sky is blue",
"citations": [{
"type": "char_location",
"cited_text": "The sky is blue.",
"document_index": 0,
"document_title": "Example Document",
"start_char_index": 20,
"end_char_index": 36
}]
}
]
}
Also, I'll be happy to discuss how to modelise these citations in the RubyLLM response object.
Source: https://docs.anthropic.com/en/docs/build-with-claude/citations
I'll try to dive into the source code later today to find out the first steps toward the citations support.
Also, let me know if you feel this is out of scope.
Thanks