Merge pull request #14164 from TomeHirata/citation-supported-text-3
Add supported text field to anthropic citation response
This commit is contained in:
commit
e132ad63f1
@ -804,7 +804,15 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
||||
if content.get("citations") is not None:
|
||||
if citations is None:
|
||||
citations = []
|
||||
citations.append(content["citations"])
|
||||
citations.append(
|
||||
[
|
||||
{
|
||||
**citation,
|
||||
"supported_text": content.get("text", ""),
|
||||
}
|
||||
for citation in content["citations"]
|
||||
]
|
||||
)
|
||||
if thinking_blocks is not None:
|
||||
reasoning_content = ""
|
||||
for block in thinking_blocks:
|
||||
|
||||
@ -256,7 +256,6 @@ def test_anthropic_tool_streaming():
|
||||
for chunk in anthropic_chunk_list:
|
||||
parsed_chunk = response_iter.chunk_parser(chunk)
|
||||
if tool_use := parsed_chunk.get("tool_use"):
|
||||
|
||||
# We only increment when a new block starts
|
||||
if tool_use.get("id") is not None:
|
||||
correct_tool_index += 1
|
||||
@ -920,6 +919,14 @@ def test_anthropic_citations_api():
|
||||
citations = resp.choices[0].message.provider_specific_fields["citations"]
|
||||
|
||||
assert citations is not None
|
||||
if citations:
|
||||
citation = citations[0][0]
|
||||
assert "supported_text" in citation
|
||||
assert "cited_text" in citation
|
||||
assert "document_index" in citation
|
||||
assert "document_title" in citation
|
||||
assert "start_char_index" in citation
|
||||
assert "end_char_index" in citation
|
||||
|
||||
|
||||
def test_anthropic_citations_api_streaming():
|
||||
@ -955,11 +962,9 @@ def test_anthropic_citations_api_streaming():
|
||||
has_citations = False
|
||||
for chunk in resp:
|
||||
print(f"returned chunk: {chunk}")
|
||||
if (
|
||||
chunk.choices[0].delta.provider_specific_fields
|
||||
and "citation" in chunk.choices[0].delta.provider_specific_fields
|
||||
):
|
||||
has_citations = True
|
||||
if provider_specific_fields := chunk.choices[0].delta.provider_specific_fields:
|
||||
if "citation" in provider_specific_fields:
|
||||
has_citations = True
|
||||
|
||||
assert has_citations
|
||||
|
||||
|
||||
@ -183,7 +183,30 @@ def test_extract_response_content_with_citations():
|
||||
}
|
||||
|
||||
_, citations, _, _, _ = config.extract_response_content(completion_response)
|
||||
assert citations is not None
|
||||
assert citations == [
|
||||
[
|
||||
{
|
||||
"type": "char_location",
|
||||
"cited_text": "The grass is green. ",
|
||||
"document_index": 0,
|
||||
"document_title": "My Document",
|
||||
"start_char_index": 0,
|
||||
"end_char_index": 20,
|
||||
"supported_text": "the grass is green",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "char_location",
|
||||
"cited_text": "The sky is blue.",
|
||||
"document_index": 0,
|
||||
"document_title": "My Document",
|
||||
"start_char_index": 20,
|
||||
"end_char_index": 36,
|
||||
"supported_text": "the sky is blue",
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
def test_map_tool_helper():
|
||||
|
||||
Loading…
Reference in New Issue
Block a user