Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions autogen/oai/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
with optional_import_block():
from anthropic import Anthropic, AnthropicBedrock, AnthropicVertex
from anthropic import __version__ as anthropic_version
from anthropic.types import Message, TextBlock, ToolUseBlock
from anthropic.types import Message, TextBlock, ThinkingBlock, ToolUseBlock

TOOL_ENABLED = anthropic_version >= "0.23.1"
if TOOL_ENABLED:
Expand Down Expand Up @@ -486,7 +486,14 @@ def _extract_json_response(self, response: Message) -> Any:
return response

# Extract content from response
content = response.content[0].text if response.content else ""
if response.content:
if type(response.content[0]) == TextBlock:
content = response.content[0].text

elif type(response.content[0]) == ThinkingBlock:
content = response.content[0].thinking
else:
content = ""

# Try to extract JSON from tags first
json_match = re.search(r"<json_response>(.*?)</json_response>", content, re.DOTALL)
Expand Down