mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
Add support for server_tool_use and web_search_tool_result in FakeAnthropicMessagesStreamIterator
- Implemented handling for "server_tool_use" and "web_search_tool_result" block types in the FakeAnthropicMessagesStreamIterator. - Added logic to emit content_block_start and content_block_stop events for both block types, aligning with Anthropic's native streaming format. - Enhanced the iterator's functionality to support new message types, improving integration with external tools.
This commit is contained in:
parent
d210bd4c4e
commit
cf6c277386
1 changed files with 36 additions and 0 deletions
|
|
@ -169,6 +169,42 @@ class FakeAnthropicMessagesStreamIterator:
|
|||
block_dict = cast(Dict[str, Any], block)
|
||||
chunks.extend(self._create_content_block_chunks(block_dict, index))
|
||||
|
||||
elif block_type == "server_tool_use":
|
||||
# Emit the full block as content_block_start (same as
|
||||
# Anthropic's native streaming format).
|
||||
content_block_start = {
|
||||
"type": "content_block_start",
|
||||
"index": index,
|
||||
"content_block": block_dict,
|
||||
}
|
||||
chunks.append(
|
||||
f"event: content_block_start\ndata: {json.dumps(content_block_start)}\n\n".encode()
|
||||
)
|
||||
|
||||
# content_block_stop
|
||||
content_block_stop = {"type": "content_block_stop", "index": index}
|
||||
chunks.append(
|
||||
f"event: content_block_stop\ndata: {json.dumps(content_block_stop)}\n\n".encode()
|
||||
)
|
||||
|
||||
elif block_type == "web_search_tool_result":
|
||||
# Emit the full block as content_block_start (same as
|
||||
# Anthropic's native streaming format).
|
||||
content_block_start = {
|
||||
"type": "content_block_start",
|
||||
"index": index,
|
||||
"content_block": block_dict,
|
||||
}
|
||||
chunks.append(
|
||||
f"event: content_block_start\ndata: {json.dumps(content_block_start)}\n\n".encode()
|
||||
)
|
||||
|
||||
# content_block_stop
|
||||
content_block_stop = {"type": "content_block_stop", "index": index}
|
||||
chunks.append(
|
||||
f"event: content_block_stop\ndata: {json.dumps(content_block_stop)}\n\n".encode()
|
||||
)
|
||||
|
||||
# 5. message_delta event (with final usage and stop_reason)
|
||||
# Include cache usage fields so clients that only read message_delta
|
||||
# (like Claude Code's SDK) see the full input token breakdown.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue