mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
anthropic[patch]: always return content blocks if citations are generated (#29398)
We currently return string (and therefore no content blocks / citations)
if the response is of the form
```
[
{"text": "a claim", "citations": [...]},
]
```
There are other cases where we do return citations as-is:
```
[
{"text": "a claim", "citations": [...]},
{"text": "some other text"},
{"text": "another claim", "citations": [...]},
]
```
Here we update to return content blocks including citations in the first
case as well.
This commit is contained in:
@@ -764,7 +764,11 @@ class ChatAnthropic(BaseChatModel):
|
||||
llm_output = {
|
||||
k: v for k, v in data_dict.items() if k not in ("content", "role", "type")
|
||||
}
|
||||
if len(content) == 1 and content[0]["type"] == "text":
|
||||
if (
|
||||
len(content) == 1
|
||||
and content[0]["type"] == "text"
|
||||
and "citations" not in content[0]
|
||||
):
|
||||
msg = AIMessage(content=content[0]["text"])
|
||||
elif any(block["type"] == "tool_use" for block in content):
|
||||
tool_calls = extract_tool_calls(content)
|
||||
|
||||
Reference in New Issue
Block a user