Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Revert "Merge pull request #14126 from TomeHirata/citation-supported-text-2"

Ishaan Jaff20811372d8ae
diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py
index 378ca75da5f..ce874bfde9a 100644
--- a/litellm/llms/anthropic/chat/transformation.py
+++ b/litellm/llms/anthropic/chat/transformation.py
@@ -797,15 +797,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
if content.get("citations") is not None:
if citations is None:
citations = []
- citations.append(
- [
- {
- **citation,
- "supported_text": content.get("text", ""),
- }
- for citation in content["citations"]
- ]
- )
+ citations.append(content["citations"])
if thinking_blocks is not None:
reasoning_content = ""
for block in thinking_blocks:
diff --git a/tests/llm_translation/test_anthropic_completion.py b/tests/llm_translation/test_anthropic_completion.py
index f4bd7531b0b..45702a261e2 100644
--- a/tests/llm_translation/test_anthropic_completion.py
+++ b/tests/llm_translation/test_anthropic_completion.py
@@ -920,14 +920,6 @@ 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():
@@ -963,11 +955,11 @@ def test_anthropic_citations_api_streaming():
has_citations = False
for chunk in resp:
print(f"returned chunk: {chunk}")
- if provider_specific_fields := chunk.choices[0].delta.provider_specific_fields:
- if "citation" in provider_specific_fields:
- has_citations = True
-
- assert "chunk_type" in provider_specific_fields
+ if (
+ chunk.choices[0].delta.provider_specific_fields
+ and "citation" in chunk.choices[0].delta.provider_specific_fields
+ ):
+ has_citations = True
assert has_citations
diff --git a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
index dcca87baf32..ff454968d9c 100644
--- a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
+++ b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
@@ -115,11 +115,16 @@ def test_calculate_usage_nulls(usage_object, expected_usage):
assert hasattr(usage, k)
assert getattr(usage, k) == v
-
- "usage_object",
- [{"server_tool_use": {"web_search_requests": None}}, {"server_tool_use": None}],
-)
[email protected]("usage_object", [
+ {
+ "server_tool_use": {
+ "web_search_requests": None
+ }
+ },
+ {
+ "server_tool_use": None
+ }
+])
def test_calculate_usage_server_tool_null(usage_object):
"""
Correctly deal with null values in usage object
@@ -127,11 +132,10 @@ def test_calculate_usage_server_tool_null(usage_object):
Fixes https://github.com/BerriAI/litellm/issues/11920
"""
config = AnthropicConfig()
-
+
usage = config.calculate_usage(usage_object=usage_object, reasoning_content=None)
assert not hasattr(usage, "server_tool_use")
-
def test_extract_response_content_with_citations():
config = AnthropicConfig()
@@ -184,30 +188,7 @@ def test_extract_response_content_with_citations():
}
_, citations, _, _, _ = config.extract_response_content(completion_response)
- 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",
- },
- ],
- ]
+ assert citations is not None
def test_map_tool_helper():