Skip to content

Commit 2081137

Browse files
committed
Revert "Merge pull request #14126 from TomeHirata/citation-supported-text-2"
This reverts commit 3f2881c, reversing changes made to 04f9ff1.
1 parent 62f14de commit 2081137

File tree

3 files changed

+18
-53
lines changed

3 files changed

+18
-53
lines changed

litellm/llms/anthropic/chat/transformation.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -797,15 +797,7 @@ def extract_response_content(self, completion_response: dict) -> Tuple[
797797
if content.get("citations") is not None:
798798
if citations is None:
799799
citations = []
800-
citations.append(
801-
[
802-
{
803-
**citation,
804-
"supported_text": content.get("text", ""),
805-
}
806-
for citation in content["citations"]
807-
]
808-
)
800+
citations.append(content["citations"])
809801
if thinking_blocks is not None:
810802
reasoning_content = ""
811803
for block in thinking_blocks:

tests/llm_translation/test_anthropic_completion.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,6 @@ def test_anthropic_citations_api():
920920
citations = resp.choices[0].message.provider_specific_fields["citations"]
921921

922922
assert citations is not None
923-
if citations:
924-
citation = citations[0][0]
925-
assert "supported_text" in citation
926-
assert "cited_text" in citation
927-
assert "document_index" in citation
928-
assert "document_title" in citation
929-
assert "start_char_index" in citation
930-
assert "end_char_index" in citation
931923

932924

933925
def test_anthropic_citations_api_streaming():
@@ -963,11 +955,11 @@ def test_anthropic_citations_api_streaming():
963955
has_citations = False
964956
for chunk in resp:
965957
print(f"returned chunk: {chunk}")
966-
if provider_specific_fields := chunk.choices[0].delta.provider_specific_fields:
967-
if "citation" in provider_specific_fields:
968-
has_citations = True
969-
970-
assert "chunk_type" in provider_specific_fields
958+
if (
959+
chunk.choices[0].delta.provider_specific_fields
960+
and "citation" in chunk.choices[0].delta.provider_specific_fields
961+
):
962+
has_citations = True
971963

972964
assert has_citations
973965

tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,27 @@ def test_calculate_usage_nulls(usage_object, expected_usage):
115115
assert hasattr(usage, k)
116116
assert getattr(usage, k) == v
117117

118-
119-
@pytest.mark.parametrize(
120-
"usage_object",
121-
[{"server_tool_use": {"web_search_requests": None}}, {"server_tool_use": None}],
122-
)
118+
@pytest.mark.parametrize("usage_object", [
119+
{
120+
"server_tool_use": {
121+
"web_search_requests": None
122+
}
123+
},
124+
{
125+
"server_tool_use": None
126+
}
127+
])
123128
def test_calculate_usage_server_tool_null(usage_object):
124129
"""
125130
Correctly deal with null values in usage object
126131
127132
Fixes https://github.com/BerriAI/litellm/issues/11920
128133
"""
129134
config = AnthropicConfig()
130-
135+
131136
usage = config.calculate_usage(usage_object=usage_object, reasoning_content=None)
132137
assert not hasattr(usage, "server_tool_use")
133138

134-
135139
def test_extract_response_content_with_citations():
136140
config = AnthropicConfig()
137141

@@ -184,30 +188,7 @@ def test_extract_response_content_with_citations():
184188
}
185189

186190
_, citations, _, _, _ = config.extract_response_content(completion_response)
187-
assert citations == [
188-
[
189-
{
190-
"type": "char_location",
191-
"cited_text": "The grass is green. ",
192-
"document_index": 0,
193-
"document_title": "My Document",
194-
"start_char_index": 0,
195-
"end_char_index": 20,
196-
"supported_text": "the grass is green",
197-
},
198-
],
199-
[
200-
{
201-
"type": "char_location",
202-
"cited_text": "The sky is blue.",
203-
"document_index": 0,
204-
"document_title": "My Document",
205-
"start_char_index": 20,
206-
"end_char_index": 36,
207-
"supported_text": "the sky is blue",
208-
},
209-
],
210-
]
191+
assert citations is not None
211192

212193

213194
def test_map_tool_helper():

0 commit comments

Comments
 (0)