|
69 | 69 | BetaCacheControlEphemeralParam, |
70 | 70 | BetaCitationsConfigParam, |
71 | 71 | BetaCitationsDelta, |
| 72 | + BetaCodeExecutionTool20250522Param, |
72 | 73 | BetaCodeExecutionToolResultBlock, |
73 | 74 | BetaCodeExecutionToolResultBlockContent, |
74 | 75 | BetaCodeExecutionToolResultBlockParam, |
|
81 | 82 | BetaMCPToolResultBlock, |
82 | 83 | BetaMCPToolUseBlock, |
83 | 84 | BetaMCPToolUseBlockParam, |
| 85 | + BetaMemoryTool20250818Param, |
84 | 86 | BetaMessage, |
85 | 87 | BetaMessageParam, |
86 | 88 | BetaMessageTokensCount, |
@@ -158,8 +160,6 @@ class AnthropicModelSettings(ModelSettings, total=False): |
158 | 160 | Contains `user_id`, an external identifier for the user who is associated with the request. |
159 | 161 | """ |
160 | 162 |
|
161 | | - |
162 | | - |
163 | 163 | anthropic_thinking: BetaThinkingConfigParam |
164 | 164 | """Determine whether the model should generate a thinking block. |
165 | 165 |
|
@@ -409,21 +409,19 @@ async def _messages_create( |
409 | 409 | extra_headers=extra_headers, |
410 | 410 | extra_body=model_settings.get('extra_body'), |
411 | 411 | ) |
412 | | - |
413 | | - # If streaming, return immediately |
414 | | - if stream: |
415 | | - return response |
416 | | - |
| 412 | + |
417 | 413 | # Handle pause_turn for non-streaming |
418 | 414 | assert isinstance(response, BetaMessage) |
419 | 415 | if response.stop_reason == 'pause_turn': |
420 | 416 | # Append assistant message to history and continue |
421 | | - anthropic_messages.append({ |
422 | | - 'role': 'assistant', |
423 | | - 'content': response.content, |
424 | | - }) |
| 417 | + anthropic_messages.append( |
| 418 | + { |
| 419 | + 'role': 'assistant', |
| 420 | + 'content': response.content, |
| 421 | + } |
| 422 | + ) |
425 | 423 | continue |
426 | | - |
| 424 | + |
427 | 425 | return response |
428 | 426 |
|
429 | 427 | except APIStatusError as e: |
@@ -501,8 +499,6 @@ async def _messages_count_tokens( |
501 | 499 | except APIConnectionError as e: |
502 | 500 | raise ModelAPIError(model_name=self.model_name, message=e.message) from e |
503 | 501 |
|
504 | | - |
505 | | - |
506 | 502 | def _process_response(self, response: BetaMessage) -> ModelResponse: |
507 | 503 | """Process a non-streamed response, and prepare a message to return.""" |
508 | 504 | items: list[ModelResponsePart] = [] |
@@ -558,7 +554,7 @@ def _process_response(self, response: BetaMessage) -> ModelResponse: |
558 | 554 | if raw_finish_reason := response.stop_reason: # pragma: no branch |
559 | 555 | provider_details = {'finish_reason': raw_finish_reason} |
560 | 556 | finish_reason = _FINISH_REASON_MAP.get(raw_finish_reason) |
561 | | - |
| 557 | + |
562 | 558 | return ModelResponse( |
563 | 559 | parts=items, |
564 | 560 | usage=_map_usage(response, self._provider.name, self._provider.base_url, self._model_name), |
@@ -1207,11 +1203,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]: |
1207 | 1203 | vendor_part_id=event.index, |
1208 | 1204 | part=_map_code_execution_tool_result_block(current_block, self.provider_name), |
1209 | 1205 | ) |
1210 | | - elif isinstance(current_block, BetaBashCodeExecutionToolResultBlock): |
1211 | | - yield self._parts_manager.handle_part( |
1212 | | - vendor_part_id=event.index, |
1213 | | - part=_map_bash_code_execution_tool_result_block(current_block, self.provider_name), |
1214 | | - ) |
| 1206 | + |
1215 | 1207 | elif isinstance(current_block, BetaWebFetchToolResultBlock): # pragma: lax no cover |
1216 | 1208 | yield self._parts_manager.handle_part( |
1217 | 1209 | vendor_part_id=event.index, |
@@ -1410,19 +1402,3 @@ def _map_mcp_server_result_block( |
1410 | 1402 | content=item.model_dump(mode='json', include={'content', 'is_error'}), |
1411 | 1403 | tool_call_id=item.tool_use_id, |
1412 | 1404 | ) |
1413 | | - |
1414 | | - |
1415 | | -def _map_bash_code_execution_tool_result_block( |
1416 | | - item: BetaBashCodeExecutionToolResultBlock, provider_name: str |
1417 | | -) -> BuiltinToolReturnPart: |
1418 | | - # We use the same content type adapter as code execution for now, assuming structure is similar |
1419 | | - # or we might need a new one if `BetaBashCodeExecutionToolResultBlock` has different content structure. |
1420 | | - # Assuming it's compatible or we can dump it as json. |
1421 | | - # If `BetaBashCodeExecutionToolResultBlock` content is different, we should use its own type. |
1422 | | - # But since we don't have a specific type adapter for it yet, we'll rely on model_dump. |
1423 | | - return BuiltinToolReturnPart( |
1424 | | - provider_name=provider_name, |
1425 | | - tool_name=CodeExecutionTool.kind, |
1426 | | - content=item.model_dump(mode='json', include={'content'}), |
1427 | | - tool_call_id=item.tool_use_id, |
1428 | | - ) |
0 commit comments