anthropic 1.1.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +170 -0
- data/README.md +32 -16
- data/lib/anthropic/client.rb +5 -2
- data/lib/anthropic/errors.rb +22 -0
- data/lib/anthropic/helpers/bedrock/client.rb +34 -4
- data/lib/anthropic/helpers/input_schema/array_of.rb +41 -0
- data/lib/anthropic/helpers/input_schema/base_model.rb +86 -0
- data/lib/anthropic/helpers/input_schema/boolean.rb +29 -0
- data/lib/anthropic/helpers/input_schema/enum_of.rb +63 -0
- data/lib/anthropic/helpers/input_schema/json_schema_converter.rb +199 -0
- data/lib/anthropic/helpers/input_schema/parsed_json.rb +39 -0
- data/lib/anthropic/helpers/input_schema/property_mapping.rb +47 -0
- data/lib/anthropic/helpers/input_schema/union_of.rb +56 -0
- data/lib/anthropic/helpers/input_schema.rb +16 -0
- data/lib/anthropic/helpers/streaming/events.rb +141 -0
- data/lib/anthropic/helpers/streaming/message_stream.rb +278 -0
- data/lib/anthropic/helpers/streaming.rb +37 -0
- data/lib/anthropic/helpers/vertex/client.rb +4 -1
- data/lib/anthropic/input_schema.rb +10 -0
- data/lib/anthropic/internal/stream.rb +6 -3
- data/lib/anthropic/internal/transport/base_client.rb +30 -5
- data/lib/anthropic/internal/transport/pooled_net_requester.rb +1 -9
- data/lib/anthropic/internal/type/array_of.rb +7 -1
- data/lib/anthropic/internal/type/base_model.rb +81 -32
- data/lib/anthropic/internal/type/base_stream.rb +3 -1
- data/lib/anthropic/internal/type/boolean.rb +7 -1
- data/lib/anthropic/internal/type/converter.rb +69 -34
- data/lib/anthropic/internal/type/enum.rb +16 -5
- data/lib/anthropic/internal/type/file_input.rb +6 -1
- data/lib/anthropic/internal/type/hash_of.rb +7 -1
- data/lib/anthropic/internal/type/union.rb +26 -16
- data/lib/anthropic/internal/type/unknown.rb +7 -1
- data/lib/anthropic/internal/util.rb +10 -11
- data/lib/anthropic/models/anthropic_beta.rb +3 -0
- data/lib/anthropic/models/beta/beta_base64_pdf_block.rb +1 -65
- data/lib/anthropic/models/beta/beta_bash_code_execution_output_block.rb +25 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_output_block_param.rb +25 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_result_block.rb +44 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_result_block_param.rb +44 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rb +43 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rb +53 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rb +39 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rb +39 -0
- data/lib/anthropic/models/beta/beta_citation_char_location.rb +7 -1
- data/lib/anthropic/models/beta/beta_citation_config.rb +19 -0
- data/lib/anthropic/models/beta/beta_citation_content_block_location.rb +7 -1
- data/lib/anthropic/models/beta/beta_citation_page_location.rb +7 -1
- data/lib/anthropic/models/beta/beta_citation_search_result_location.rb +55 -0
- data/lib/anthropic/models/beta/beta_citation_search_result_location_param.rb +55 -0
- data/lib/anthropic/models/beta/beta_citations_delta.rb +5 -3
- data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +40 -0
- data/lib/anthropic/models/beta/beta_content_block.rb +12 -5
- data/lib/anthropic/models/beta/beta_content_block_param.rb +28 -17
- data/lib/anthropic/models/beta/beta_document_block.rb +56 -0
- data/lib/anthropic/models/beta/beta_message.rb +6 -2
- data/lib/anthropic/models/beta/beta_message_param.rb +3 -3
- data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +14 -7
- data/lib/anthropic/models/beta/beta_request_document_block.rb +75 -0
- data/lib/anthropic/models/beta/beta_search_result_block_param.rb +55 -0
- data/lib/anthropic/models/beta/beta_server_tool_usage.rb +9 -1
- data/lib/anthropic/models/beta/beta_server_tool_use_block.rb +3 -0
- data/lib/anthropic/models/beta/beta_server_tool_use_block_param.rb +3 -0
- data/lib/anthropic/models/beta/beta_text_block.rb +2 -2
- data/lib/anthropic/models/beta/beta_text_block_param.rb +2 -2
- data/lib/anthropic/models/beta/beta_text_citation.rb +3 -1
- data/lib/anthropic/models/beta/beta_text_citation_param.rb +3 -1
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rb +25 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rb +26 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rb +49 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rb +50 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rb +47 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rb +57 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rb +45 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rb +46 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rb +61 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rb +62 -0
- data/lib/anthropic/models/beta/beta_tool.rb +7 -1
- data/lib/anthropic/models/beta/beta_tool_result_block_param.rb +8 -4
- data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +49 -0
- data/lib/anthropic/models/beta/beta_tool_union.rb +12 -6
- data/lib/anthropic/models/beta/beta_web_fetch_block.rb +42 -0
- data/lib/anthropic/models/beta/beta_web_fetch_block_param.rb +42 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_20250910.rb +82 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_block.rb +43 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rb +53 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rb +25 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rb +25 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rb +25 -0
- data/lib/anthropic/models/beta/message_count_tokens_params.rb +23 -36
- data/lib/anthropic/models/beta/message_create_params.rb +10 -27
- data/lib/anthropic/models/beta/messages/batch_create_params.rb +13 -37
- data/lib/anthropic/models/beta/messages/beta_message_batch.rb +1 -4
- data/lib/anthropic/models/beta_error_response.rb +7 -1
- data/lib/anthropic/models/cache_control_ephemeral.rb +39 -1
- data/lib/anthropic/models/cache_creation.rb +24 -0
- data/lib/anthropic/models/citation_char_location.rb +7 -1
- data/lib/anthropic/models/citation_content_block_location.rb +7 -1
- data/lib/anthropic/models/citation_page_location.rb +7 -1
- data/lib/anthropic/models/citation_search_result_location_param.rb +51 -0
- data/lib/anthropic/models/citations_delta.rb +5 -3
- data/lib/anthropic/models/citations_search_result_location.rb +51 -0
- data/lib/anthropic/models/content_block.rb +5 -5
- data/lib/anthropic/models/content_block_param.rb +14 -11
- data/lib/anthropic/models/document_block_param.rb +2 -2
- data/lib/anthropic/models/error_response.rb +7 -1
- data/lib/anthropic/models/message.rb +6 -2
- data/lib/anthropic/models/message_count_tokens_params.rb +10 -27
- data/lib/anthropic/models/message_count_tokens_tool.rb +5 -1
- data/lib/anthropic/models/message_create_params.rb +10 -27
- data/lib/anthropic/models/message_param.rb +3 -3
- data/lib/anthropic/models/messages/batch_create_params.rb +11 -31
- data/lib/anthropic/models/model.rb +16 -21
- data/lib/anthropic/models/raw_content_block_start_event.rb +7 -7
- data/lib/anthropic/models/search_result_block_param.rb +51 -0
- data/lib/anthropic/models/text_block.rb +2 -2
- data/lib/anthropic/models/text_block_param.rb +2 -2
- data/lib/anthropic/models/text_citation.rb +3 -1
- data/lib/anthropic/models/text_citation_param.rb +3 -1
- data/lib/anthropic/models/tool.rb +7 -1
- data/lib/anthropic/models/tool_result_block_param.rb +8 -4
- data/lib/anthropic/models/tool_text_editor_20250429.rb +36 -0
- data/lib/anthropic/models/tool_text_editor_20250728.rb +45 -0
- data/lib/anthropic/models/tool_union.rb +5 -1
- data/lib/anthropic/models/tool_use_block.rb +14 -0
- data/lib/anthropic/models/usage.rb +9 -1
- data/lib/anthropic/models.rb +16 -4
- data/lib/anthropic/resources/beta/messages.rb +73 -6
- data/lib/anthropic/resources/messages.rb +152 -7
- data/lib/anthropic/streaming.rb +5 -0
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +54 -0
- data/rbi/anthropic/errors.rbi +18 -2
- data/rbi/anthropic/helpers/bedrock/client.rbi +17 -6
- data/rbi/anthropic/helpers/input_schema/array_of.rbi +16 -0
- data/rbi/anthropic/helpers/input_schema/base_model.rbi +21 -0
- data/rbi/anthropic/helpers/input_schema/boolean.rbi +11 -0
- data/rbi/anthropic/helpers/input_schema/enum_of.rbi +30 -0
- data/rbi/anthropic/helpers/input_schema/json_schema_converter.rbi +89 -0
- data/rbi/anthropic/helpers/input_schema/union_of.rbi +23 -0
- data/rbi/anthropic/helpers/streaming/events.rbi +95 -0
- data/rbi/anthropic/helpers/streaming/message_stream.rbi +73 -0
- data/rbi/anthropic/helpers/structured_output.rbi +16 -0
- data/rbi/anthropic/helpers/vertex/client.rbi +17 -6
- data/rbi/anthropic/input_schema.rbi +12 -0
- data/rbi/anthropic/internal/transport/base_client.rbi +1 -1
- data/rbi/anthropic/internal/type/base_stream.rbi +8 -1
- data/rbi/anthropic/internal/type/boolean.rbi +2 -0
- data/rbi/anthropic/internal/type/converter.rbi +69 -15
- data/rbi/anthropic/internal/type/union.rbi +14 -2
- data/rbi/anthropic/internal/type/unknown.rbi +2 -0
- data/rbi/anthropic/internal/util.rbi +2 -0
- data/rbi/anthropic/models/anthropic_beta.rbi +2 -0
- data/rbi/anthropic/models/beta/beta_base64_pdf_block.rbi +1 -128
- data/rbi/anthropic/models/beta/beta_bash_code_execution_output_block.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_output_block_param.rbi +34 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_result_block.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_result_block_param.rbi +77 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rbi +86 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rbi +110 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rbi +101 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rbi +101 -0
- data/rbi/anthropic/models/beta/beta_citation_char_location.rbi +6 -0
- data/rbi/anthropic/models/beta/beta_citation_config.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_citation_content_block_location.rbi +6 -0
- data/rbi/anthropic/models/beta/beta_citation_page_location.rbi +6 -0
- data/rbi/anthropic/models/beta/beta_citation_search_result_location.rbi +78 -0
- data/rbi/anthropic/models/beta/beta_citation_search_result_location_param.rbi +79 -0
- data/rbi/anthropic/models/beta/beta_citations_delta.rbi +4 -2
- data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_content_block.rbi +6 -3
- data/rbi/anthropic/models/beta/beta_content_block_param.rbi +11 -7
- data/rbi/anthropic/models/beta/beta_document_block.rbi +95 -0
- data/rbi/anthropic/models/beta/beta_message.rbi +14 -3
- data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +12 -6
- data/rbi/anthropic/models/beta/beta_request_document_block.rbi +142 -0
- data/rbi/anthropic/models/beta/beta_search_result_block_param.rbi +91 -0
- data/rbi/anthropic/models/beta/beta_server_tool_usage.rbi +17 -2
- data/rbi/anthropic/models/beta/beta_server_tool_use_block.rbi +15 -0
- data/rbi/anthropic/models/beta/beta_server_tool_use_block_param.rbi +15 -0
- data/rbi/anthropic/models/beta/beta_text_block.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_text_block_param.rbi +6 -3
- data/rbi/anthropic/models/beta/beta_text_citation.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_text_citation_param.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rbi +41 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rbi +41 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rbi +73 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rbi +73 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rbi +90 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rbi +118 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rbi +110 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rbi +110 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rbi +118 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rbi +118 -0
- data/rbi/anthropic/models/beta/beta_tool.rbi +14 -5
- data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +3 -1
- data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +82 -0
- data/rbi/anthropic/models/beta/beta_tool_union.rbi +7 -4
- data/rbi/anthropic/models/beta/beta_web_fetch_block.rbi +67 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_block_param.rbi +71 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_20250910.rbi +125 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_block.rbi +81 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rbi +109 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rbi +51 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rbi +50 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rbi +70 -0
- data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +51 -70
- data/rbi/anthropic/models/beta/message_create_params.rbi +44 -66
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +44 -66
- data/rbi/anthropic/models/beta_error_response.rbi +10 -2
- data/rbi/anthropic/models/cache_control_ephemeral.rbi +68 -3
- data/rbi/anthropic/models/cache_creation.rbi +45 -0
- data/rbi/anthropic/models/citation_char_location.rbi +6 -0
- data/rbi/anthropic/models/citation_content_block_location.rbi +6 -0
- data/rbi/anthropic/models/citation_page_location.rbi +6 -0
- data/rbi/anthropic/models/citation_search_result_location_param.rbi +74 -0
- data/rbi/anthropic/models/citations_delta.rbi +4 -2
- data/rbi/anthropic/models/citations_search_result_location.rbi +74 -0
- data/rbi/anthropic/models/content_block.rbi +3 -3
- data/rbi/anthropic/models/content_block_param.rbi +6 -5
- data/rbi/anthropic/models/document_block_param.rbi +7 -3
- data/rbi/anthropic/models/error_response.rbi +10 -2
- data/rbi/anthropic/models/message.rbi +11 -3
- data/rbi/anthropic/models/message_count_tokens_params.rbi +24 -50
- data/rbi/anthropic/models/message_count_tokens_tool.rbi +2 -0
- data/rbi/anthropic/models/message_create_params.rbi +24 -50
- data/rbi/anthropic/models/messages/batch_create_params.rbi +24 -50
- data/rbi/anthropic/models/model.rbi +4 -8
- data/rbi/anthropic/models/raw_content_block_start_event.rbi +6 -6
- data/rbi/anthropic/models/search_result_block_param.rbi +77 -0
- data/rbi/anthropic/models/text_block.rbi +2 -1
- data/rbi/anthropic/models/text_block_param.rbi +6 -3
- data/rbi/anthropic/models/text_citation.rbi +2 -1
- data/rbi/anthropic/models/text_citation_param.rbi +2 -1
- data/rbi/anthropic/models/tool.rbi +16 -5
- data/rbi/anthropic/models/tool_result_block_param.rbi +6 -1
- data/rbi/anthropic/models/tool_text_editor_20250429.rbi +62 -0
- data/rbi/anthropic/models/tool_text_editor_20250728.rbi +72 -0
- data/rbi/anthropic/models/tool_union.rbi +2 -0
- data/rbi/anthropic/models/usage.rbi +13 -0
- data/rbi/anthropic/models.rbi +14 -0
- data/rbi/anthropic/resources/beta/messages.rbi +45 -87
- data/rbi/anthropic/resources/messages.rbi +315 -69
- data/rbi/anthropic/streaming.rbi +5 -0
- data/sig/anthropic/errors.rbs +9 -0
- data/sig/anthropic/helpers/streaming/events.rbs +117 -0
- data/sig/anthropic/helpers/streaming/message_stream.rbs +57 -0
- data/sig/anthropic/internal/transport/base_client.rbs +1 -1
- data/sig/anthropic/internal/type/base_stream.rbs +4 -0
- data/sig/anthropic/internal/type/converter.rbs +24 -1
- data/sig/anthropic/internal/type/union.rbs +2 -2
- data/sig/anthropic/models/anthropic_beta.rbs +2 -0
- data/sig/anthropic/models/beta/beta_base64_pdf_block.rbs +1 -58
- data/sig/anthropic/models/beta/beta_bash_code_execution_output_block.rbs +23 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_output_block_param.rbs +23 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_result_block.rbs +44 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_result_block_param.rbs +44 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rbs +44 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rbs +49 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rbs +48 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rbs +48 -0
- data/sig/anthropic/models/beta/beta_citation_char_location.rbs +5 -0
- data/sig/anthropic/models/beta/beta_citation_config.rbs +17 -0
- data/sig/anthropic/models/beta/beta_citation_content_block_location.rbs +5 -0
- data/sig/anthropic/models/beta/beta_citation_page_location.rbs +5 -0
- data/sig/anthropic/models/beta/beta_citation_search_result_location.rbs +54 -0
- data/sig/anthropic/models/beta/beta_citation_search_result_location_param.rbs +54 -0
- data/sig/anthropic/models/beta/beta_citations_delta.rbs +1 -0
- data/sig/anthropic/models/beta/beta_code_execution_tool_20250825.rbs +34 -0
- data/sig/anthropic/models/beta/beta_content_block.rbs +5 -2
- data/sig/anthropic/models/beta/beta_content_block_param.rbs +12 -8
- data/sig/anthropic/models/beta/beta_document_block.rbs +49 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +5 -2
- data/sig/anthropic/models/beta/beta_request_document_block.rbs +62 -0
- data/sig/anthropic/models/beta/beta_search_result_block_param.rbs +53 -0
- data/sig/anthropic/models/beta/beta_server_tool_usage.rbs +12 -3
- data/sig/anthropic/models/beta/beta_server_tool_use_block.rbs +9 -1
- data/sig/anthropic/models/beta/beta_server_tool_use_block_param.rbs +9 -1
- data/sig/anthropic/models/beta/beta_text_citation.rbs +1 -0
- data/sig/anthropic/models/beta/beta_text_citation_param.rbs +1 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rbs +29 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rbs +29 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rbs +49 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rbs +49 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rbs +46 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rbs +51 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rbs +53 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rbs +53 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rbs +61 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rbs +61 -0
- data/sig/anthropic/models/beta/beta_tool.rbs +14 -3
- data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +2 -0
- data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +39 -0
- data/sig/anthropic/models/beta/beta_tool_union.rbs +7 -4
- data/sig/anthropic/models/beta/beta_web_fetch_block.rbs +39 -0
- data/sig/anthropic/models/beta/beta_web_fetch_block_param.rbs +39 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_20250910.rbs +59 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_block.rbs +44 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rbs +49 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rbs +29 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rbs +29 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rbs +32 -0
- data/sig/anthropic/models/beta/message_count_tokens_params.rbs +7 -4
- data/sig/anthropic/models/beta_error_response.rbs +13 -2
- data/sig/anthropic/models/cache_control_ephemeral.rbs +27 -3
- data/sig/anthropic/models/cache_creation.rbs +25 -0
- data/sig/anthropic/models/citation_char_location.rbs +5 -0
- data/sig/anthropic/models/citation_content_block_location.rbs +5 -0
- data/sig/anthropic/models/citation_page_location.rbs +5 -0
- data/sig/anthropic/models/citation_search_result_location_param.rbs +50 -0
- data/sig/anthropic/models/citations_delta.rbs +1 -0
- data/sig/anthropic/models/citations_search_result_location.rbs +50 -0
- data/sig/anthropic/models/content_block.rbs +2 -2
- data/sig/anthropic/models/content_block_param.rbs +6 -5
- data/sig/anthropic/models/document_block_param.rbs +4 -8
- data/sig/anthropic/models/error_response.rbs +13 -2
- data/sig/anthropic/models/message_count_tokens_tool.rbs +2 -0
- data/sig/anthropic/models/model.rbs +4 -10
- data/sig/anthropic/models/raw_content_block_start_event.rbs +2 -2
- data/sig/anthropic/models/search_result_block_param.rbs +49 -0
- data/sig/anthropic/models/text_citation.rbs +1 -0
- data/sig/anthropic/models/text_citation_param.rbs +1 -0
- data/sig/anthropic/models/tool.rbs +14 -3
- data/sig/anthropic/models/tool_result_block_param.rbs +5 -1
- data/sig/anthropic/models/tool_text_editor_20250429.rbs +30 -0
- data/sig/anthropic/models/tool_text_editor_20250728.rbs +35 -0
- data/sig/anthropic/models/tool_union.rbs +2 -0
- data/sig/anthropic/models/usage.rbs +5 -0
- data/sig/anthropic/models.rbs +12 -0
- data/sig/anthropic/streaming.rbs +3 -0
- metadata +152 -3
@@ -6,7 +6,7 @@ module Anthropic
|
|
6
6
|
# @return [Anthropic::Resources::Messages::Batches]
|
7
7
|
attr_reader :batches
|
8
8
|
|
9
|
-
# See {Anthropic::Resources::Messages#
|
9
|
+
# See {Anthropic::Resources::Messages#stream} for streaming counterpart.
|
10
10
|
#
|
11
11
|
# Some parameter documentations has been truncated, see
|
12
12
|
# {Anthropic::Models::MessageCreateParams} for more details.
|
@@ -41,7 +41,7 @@ module Anthropic
|
|
41
41
|
#
|
42
42
|
# @param tool_choice [Anthropic::Models::ToolChoiceAuto, Anthropic::Models::ToolChoiceAny, Anthropic::Models::ToolChoiceTool, Anthropic::Models::ToolChoiceNone] How the model should use the provided tools. The model can use a specific tool,
|
43
43
|
#
|
44
|
-
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
44
|
+
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::ToolTextEditor20250429, Anthropic::Models::ToolTextEditor20250728, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
45
45
|
#
|
46
46
|
# @param top_k [Integer] Only sample from the top K options for each subsequent token.
|
47
47
|
#
|
@@ -55,10 +55,16 @@ module Anthropic
|
|
55
55
|
def create(params)
|
56
56
|
parsed, options = Anthropic::MessageCreateParams.dump_request(params)
|
57
57
|
if parsed[:stream]
|
58
|
-
message = "Please use `#
|
58
|
+
message = "Please use `#stream` for the streaming use case."
|
59
59
|
raise ArgumentError.new(message)
|
60
60
|
end
|
61
61
|
|
62
|
+
tool_models = get_structured_output_models(parsed)
|
63
|
+
|
64
|
+
unwrap = if tool_models.any?
|
65
|
+
->(raw) { parse_structured_outputs!(raw, tool_models) }
|
66
|
+
end
|
67
|
+
|
62
68
|
if options.empty? && @client.timeout == Anthropic::Client::DEFAULT_TIMEOUT_IN_SECONDS
|
63
69
|
model = parsed[:model].to_sym
|
64
70
|
max_tokens = parsed[:max_tokens].to_i
|
@@ -76,12 +82,80 @@ module Anthropic
|
|
76
82
|
path: "v1/messages",
|
77
83
|
body: parsed,
|
78
84
|
model: Anthropic::Message,
|
85
|
+
unwrap: unwrap,
|
79
86
|
options: options
|
80
87
|
)
|
81
88
|
end
|
82
89
|
|
83
|
-
|
84
|
-
|
90
|
+
# See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
|
91
|
+
#
|
92
|
+
# Some parameter documentations has been truncated, see
|
93
|
+
# {Anthropic::Models::MessageCreateParams} for more details.
|
94
|
+
#
|
95
|
+
# Send a structured list of input messages with text and/or image content, and the
|
96
|
+
# model will generate the next message in the conversation with streaming.
|
97
|
+
#
|
98
|
+
# The Messages API can be used for either single queries or stateless multi-turn
|
99
|
+
# conversations.
|
100
|
+
#
|
101
|
+
# Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
|
102
|
+
#
|
103
|
+
# @overload stream(max_tokens:, messages:, model:, metadata: nil, service_tier: nil, stop_sequences: nil, system_: nil, temperature: nil, thinking: nil, tool_choice: nil, tools: nil, top_k: nil, top_p: nil, request_options: {})
|
104
|
+
#
|
105
|
+
# @param max_tokens [Integer] The maximum number of tokens to generate before stopping.
|
106
|
+
#
|
107
|
+
# @param messages [Array<Anthropic::Models::MessageParam>] Input messages.
|
108
|
+
#
|
109
|
+
# @param model [Symbol, String, Anthropic::Models::Model] The model that will complete your prompt.\n\nSee [models](https://docs.anthropic
|
110
|
+
#
|
111
|
+
# @param metadata [Anthropic::Models::Metadata] An object describing metadata about the request.
|
112
|
+
#
|
113
|
+
# @param service_tier [Symbol, Anthropic::Models::MessageCreateParams::ServiceTier] Determines whether to use priority capacity (if available) or standard capacity
|
114
|
+
#
|
115
|
+
# @param stop_sequences [Array<String>] Custom text sequences that will cause the model to stop generating.
|
116
|
+
#
|
117
|
+
# @param system_ [String, Array<Anthropic::Models::TextBlockParam>] System prompt.
|
118
|
+
#
|
119
|
+
# @param temperature [Float] Amount of randomness injected into the response.
|
120
|
+
#
|
121
|
+
# @param thinking [Anthropic::Models::ThinkingConfigEnabled, Anthropic::Models::ThinkingConfigDisabled] Configuration for enabling Claude's extended thinking.
|
122
|
+
#
|
123
|
+
# @param tool_choice [Anthropic::Models::ToolChoiceAuto, Anthropic::Models::ToolChoiceAny, Anthropic::Models::ToolChoiceTool, Anthropic::Models::ToolChoiceNone] How the model should use the provided tools. The model can use a specific tool,
|
124
|
+
#
|
125
|
+
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
126
|
+
#
|
127
|
+
# @param top_k [Integer] Only sample from the top K options for each subsequent token.
|
128
|
+
#
|
129
|
+
# @param top_p [Float] Use nucleus sampling.
|
130
|
+
#
|
131
|
+
# @param request_options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil]
|
132
|
+
#
|
133
|
+
# @return [Anthropic::Streaming::MessageStream]
|
134
|
+
#
|
135
|
+
# @see Anthropic::Models::MessageCreateParams
|
136
|
+
def stream(params)
|
137
|
+
parsed, options = Anthropic::Models::MessageCreateParams.dump_request(params)
|
138
|
+
unless parsed.fetch(:stream, true)
|
139
|
+
message = "Please use `#create` for the non-streaming use case."
|
140
|
+
raise ArgumentError.new(message)
|
141
|
+
end
|
142
|
+
parsed.store(:stream, true)
|
143
|
+
|
144
|
+
tool_models = get_structured_output_models(parsed)
|
145
|
+
|
146
|
+
raw_stream = @client.request(
|
147
|
+
method: :post,
|
148
|
+
path: "v1/messages",
|
149
|
+
headers: {"accept" => "text/event-stream"},
|
150
|
+
body: parsed,
|
151
|
+
stream: Anthropic::Internal::Stream,
|
152
|
+
model: Anthropic::Models::RawMessageStreamEvent,
|
153
|
+
options: options
|
154
|
+
)
|
155
|
+
Anthropic::Streaming::MessageStream.new(
|
156
|
+
raw_stream: raw_stream,
|
157
|
+
tool_models: tool_models
|
158
|
+
)
|
85
159
|
end
|
86
160
|
|
87
161
|
# See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
|
@@ -119,7 +193,7 @@ module Anthropic
|
|
119
193
|
#
|
120
194
|
# @param tool_choice [Anthropic::Models::ToolChoiceAuto, Anthropic::Models::ToolChoiceAny, Anthropic::Models::ToolChoiceTool, Anthropic::Models::ToolChoiceNone] How the model should use the provided tools. The model can use a specific tool,
|
121
195
|
#
|
122
|
-
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
196
|
+
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::ToolTextEditor20250429, Anthropic::Models::ToolTextEditor20250728, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
123
197
|
#
|
124
198
|
# @param top_k [Integer] Only sample from the top K options for each subsequent token.
|
125
199
|
#
|
@@ -171,7 +245,7 @@ module Anthropic
|
|
171
245
|
#
|
172
246
|
# @param tool_choice [Anthropic::Models::ToolChoiceAuto, Anthropic::Models::ToolChoiceAny, Anthropic::Models::ToolChoiceTool, Anthropic::Models::ToolChoiceNone] How the model should use the provided tools. The model can use a specific tool,
|
173
247
|
#
|
174
|
-
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
248
|
+
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::ToolTextEditor20250429, Anthropic::Models::ToolTextEditor20250728, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
175
249
|
#
|
176
250
|
# @param request_options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil]
|
177
251
|
#
|
@@ -196,6 +270,77 @@ module Anthropic
|
|
196
270
|
@client = client
|
197
271
|
@batches = Anthropic::Resources::Messages::Batches.new(client: client)
|
198
272
|
end
|
273
|
+
|
274
|
+
private
|
275
|
+
|
276
|
+
# Extract tool models from the request and convert them to JSON Schema
|
277
|
+
# Returns a hash mapping tool name to Ruby model.
|
278
|
+
def get_structured_output_models(parsed)
|
279
|
+
tool_models = {}
|
280
|
+
|
281
|
+
case parsed
|
282
|
+
in {tools: Array => tools}
|
283
|
+
mapped = tools.map do |tool|
|
284
|
+
case tool
|
285
|
+
# Direct tool class:
|
286
|
+
in Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
287
|
+
name = tool.name.split("::").last
|
288
|
+
description = extract_class_description(tool)
|
289
|
+
tool_models.store(name, tool)
|
290
|
+
{
|
291
|
+
name: name,
|
292
|
+
description: description,
|
293
|
+
input_schema: tool.to_json_schema
|
294
|
+
}
|
295
|
+
# Tool with explicit name/description and BaseModel as input_schema:
|
296
|
+
in {name: String => name,
|
297
|
+
input_schema: Anthropic::Helpers::InputSchema::JsonSchemaConverter => model,
|
298
|
+
**rest}
|
299
|
+
tool_models.store(name, model)
|
300
|
+
rest.merge(
|
301
|
+
name: name,
|
302
|
+
input_schema: model.to_json_schema
|
303
|
+
)
|
304
|
+
else
|
305
|
+
# Any other format (pass through unchanged)
|
306
|
+
# This includes raw JSON schemas and any other tool definitions.
|
307
|
+
tool
|
308
|
+
end
|
309
|
+
end
|
310
|
+
tools.replace(mapped)
|
311
|
+
else
|
312
|
+
end
|
313
|
+
|
314
|
+
tool_models
|
315
|
+
end
|
316
|
+
|
317
|
+
# Extract class description from a BaseModel class
|
318
|
+
def extract_class_description(klass)
|
319
|
+
klass.respond_to?(:doc_string) ? klass.doc_string : nil
|
320
|
+
end
|
321
|
+
|
322
|
+
def parse_structured_outputs!(raw, tool_models)
|
323
|
+
return raw if tool_models.empty?
|
324
|
+
|
325
|
+
raw[:content]&.each do |content|
|
326
|
+
next unless content[:type] == "tool_use"
|
327
|
+
|
328
|
+
model = tool_models[content[:name]]
|
329
|
+
next unless model
|
330
|
+
|
331
|
+
begin
|
332
|
+
parsed_input = content[:input]
|
333
|
+
|
334
|
+
coerced = Anthropic::Internal::Type::Converter.coerce(model, parsed_input)
|
335
|
+
|
336
|
+
content.store(:parsed, coerced)
|
337
|
+
rescue StandardError => e
|
338
|
+
content.store(:parsed, {error: e.message})
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
raw
|
343
|
+
end
|
199
344
|
end
|
200
345
|
end
|
201
346
|
end
|
data/lib/anthropic/version.rb
CHANGED
data/lib/anthropic.rb
CHANGED
@@ -58,6 +58,7 @@ require_relative "anthropic/vertex"
|
|
58
58
|
require_relative "anthropic/internal/stream"
|
59
59
|
require_relative "anthropic/internal/jsonl_stream"
|
60
60
|
require_relative "anthropic/internal/page"
|
61
|
+
require_relative "anthropic/models/beta/beta_request_document_block"
|
61
62
|
require_relative "anthropic/models/anthropic_beta"
|
62
63
|
require_relative "anthropic/models/api_error_object"
|
63
64
|
require_relative "anthropic/models/authentication_error"
|
@@ -66,16 +67,27 @@ require_relative "anthropic/models/base64_pdf_source"
|
|
66
67
|
require_relative "anthropic/models/beta/beta_base64_image_source"
|
67
68
|
require_relative "anthropic/models/beta/beta_base64_pdf_block"
|
68
69
|
require_relative "anthropic/models/beta/beta_base64_pdf_source"
|
70
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_output_block"
|
71
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_output_block_param"
|
72
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_result_block"
|
73
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_result_block_param"
|
74
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_tool_result_block"
|
75
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_tool_result_block_param"
|
76
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_tool_result_error"
|
77
|
+
require_relative "anthropic/models/beta/beta_bash_code_execution_tool_result_error_param"
|
69
78
|
require_relative "anthropic/models/beta/beta_cache_control_ephemeral"
|
70
79
|
require_relative "anthropic/models/beta/beta_cache_creation"
|
71
80
|
require_relative "anthropic/models/beta/beta_citation_char_location"
|
72
81
|
require_relative "anthropic/models/beta/beta_citation_char_location_param"
|
82
|
+
require_relative "anthropic/models/beta/beta_citation_config"
|
73
83
|
require_relative "anthropic/models/beta/beta_citation_content_block_location"
|
74
84
|
require_relative "anthropic/models/beta/beta_citation_content_block_location_param"
|
75
85
|
require_relative "anthropic/models/beta/beta_citation_page_location"
|
76
86
|
require_relative "anthropic/models/beta/beta_citation_page_location_param"
|
77
87
|
require_relative "anthropic/models/beta/beta_citations_config_param"
|
78
88
|
require_relative "anthropic/models/beta/beta_citations_delta"
|
89
|
+
require_relative "anthropic/models/beta/beta_citation_search_result_location"
|
90
|
+
require_relative "anthropic/models/beta/beta_citation_search_result_location_param"
|
79
91
|
require_relative "anthropic/models/beta/beta_citations_web_search_result_location"
|
80
92
|
require_relative "anthropic/models/beta/beta_citation_web_search_result_location_param"
|
81
93
|
require_relative "anthropic/models/beta/beta_code_execution_output_block"
|
@@ -83,6 +95,7 @@ require_relative "anthropic/models/beta/beta_code_execution_output_block_param"
|
|
83
95
|
require_relative "anthropic/models/beta/beta_code_execution_result_block"
|
84
96
|
require_relative "anthropic/models/beta/beta_code_execution_result_block_param"
|
85
97
|
require_relative "anthropic/models/beta/beta_code_execution_tool_20250522"
|
98
|
+
require_relative "anthropic/models/beta/beta_code_execution_tool_20250825"
|
86
99
|
require_relative "anthropic/models/beta/beta_code_execution_tool_result_block"
|
87
100
|
require_relative "anthropic/models/beta/beta_code_execution_tool_result_block_content"
|
88
101
|
require_relative "anthropic/models/beta/beta_code_execution_tool_result_block_param"
|
@@ -97,6 +110,7 @@ require_relative "anthropic/models/beta/beta_content_block"
|
|
97
110
|
require_relative "anthropic/models/beta/beta_content_block_param"
|
98
111
|
require_relative "anthropic/models/beta/beta_content_block_source"
|
99
112
|
require_relative "anthropic/models/beta/beta_content_block_source_content"
|
113
|
+
require_relative "anthropic/models/beta/beta_document_block"
|
100
114
|
require_relative "anthropic/models/beta/beta_file_document_source"
|
101
115
|
require_relative "anthropic/models/beta/beta_file_image_source"
|
102
116
|
require_relative "anthropic/models/beta/beta_image_block_param"
|
@@ -124,6 +138,7 @@ require_relative "anthropic/models/beta/beta_redacted_thinking_block_param"
|
|
124
138
|
require_relative "anthropic/models/beta/beta_request_mcp_server_tool_configuration"
|
125
139
|
require_relative "anthropic/models/beta/beta_request_mcp_server_url_definition"
|
126
140
|
require_relative "anthropic/models/beta/beta_request_mcp_tool_result_block_param"
|
141
|
+
require_relative "anthropic/models/beta/beta_search_result_block_param"
|
127
142
|
require_relative "anthropic/models/beta/beta_server_tool_usage"
|
128
143
|
require_relative "anthropic/models/beta/beta_server_tool_use_block"
|
129
144
|
require_relative "anthropic/models/beta/beta_server_tool_use_block_param"
|
@@ -134,6 +149,16 @@ require_relative "anthropic/models/beta/beta_text_block_param"
|
|
134
149
|
require_relative "anthropic/models/beta/beta_text_citation"
|
135
150
|
require_relative "anthropic/models/beta/beta_text_citation_param"
|
136
151
|
require_relative "anthropic/models/beta/beta_text_delta"
|
152
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_create_result_block"
|
153
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param"
|
154
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block"
|
155
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param"
|
156
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_tool_result_block"
|
157
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param"
|
158
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_tool_result_error"
|
159
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param"
|
160
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_view_result_block"
|
161
|
+
require_relative "anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param"
|
137
162
|
require_relative "anthropic/models/beta/beta_thinking_block"
|
138
163
|
require_relative "anthropic/models/beta/beta_thinking_block_param"
|
139
164
|
require_relative "anthropic/models/beta/beta_thinking_config_disabled"
|
@@ -154,12 +179,21 @@ require_relative "anthropic/models/beta/beta_tool_result_block_param"
|
|
154
179
|
require_relative "anthropic/models/beta/beta_tool_text_editor_20241022"
|
155
180
|
require_relative "anthropic/models/beta/beta_tool_text_editor_20250124"
|
156
181
|
require_relative "anthropic/models/beta/beta_tool_text_editor_20250429"
|
182
|
+
require_relative "anthropic/models/beta/beta_tool_text_editor_20250728"
|
157
183
|
require_relative "anthropic/models/beta/beta_tool_union"
|
158
184
|
require_relative "anthropic/models/beta/beta_tool_use_block"
|
159
185
|
require_relative "anthropic/models/beta/beta_tool_use_block_param"
|
160
186
|
require_relative "anthropic/models/beta/beta_url_image_source"
|
161
187
|
require_relative "anthropic/models/beta/beta_url_pdf_source"
|
162
188
|
require_relative "anthropic/models/beta/beta_usage"
|
189
|
+
require_relative "anthropic/models/beta/beta_web_fetch_block"
|
190
|
+
require_relative "anthropic/models/beta/beta_web_fetch_block_param"
|
191
|
+
require_relative "anthropic/models/beta/beta_web_fetch_tool_20250910"
|
192
|
+
require_relative "anthropic/models/beta/beta_web_fetch_tool_result_block"
|
193
|
+
require_relative "anthropic/models/beta/beta_web_fetch_tool_result_block_param"
|
194
|
+
require_relative "anthropic/models/beta/beta_web_fetch_tool_result_error_block"
|
195
|
+
require_relative "anthropic/models/beta/beta_web_fetch_tool_result_error_block_param"
|
196
|
+
require_relative "anthropic/models/beta/beta_web_fetch_tool_result_error_code"
|
163
197
|
require_relative "anthropic/models/beta/beta_web_search_result_block"
|
164
198
|
require_relative "anthropic/models/beta/beta_web_search_result_block_param"
|
165
199
|
require_relative "anthropic/models/beta/beta_web_search_tool_20250305"
|
@@ -209,6 +243,7 @@ require_relative "anthropic/models/beta_permission_error"
|
|
209
243
|
require_relative "anthropic/models/beta_rate_limit_error"
|
210
244
|
require_relative "anthropic/models/billing_error"
|
211
245
|
require_relative "anthropic/models/cache_control_ephemeral"
|
246
|
+
require_relative "anthropic/models/cache_creation"
|
212
247
|
require_relative "anthropic/models/citation_char_location"
|
213
248
|
require_relative "anthropic/models/citation_char_location_param"
|
214
249
|
require_relative "anthropic/models/citation_content_block_location"
|
@@ -217,6 +252,8 @@ require_relative "anthropic/models/citation_page_location"
|
|
217
252
|
require_relative "anthropic/models/citation_page_location_param"
|
218
253
|
require_relative "anthropic/models/citations_config_param"
|
219
254
|
require_relative "anthropic/models/citations_delta"
|
255
|
+
require_relative "anthropic/models/citation_search_result_location_param"
|
256
|
+
require_relative "anthropic/models/citations_search_result_location"
|
220
257
|
require_relative "anthropic/models/citations_web_search_result_location"
|
221
258
|
require_relative "anthropic/models/citation_web_search_result_location_param"
|
222
259
|
require_relative "anthropic/models/completion"
|
@@ -274,6 +311,7 @@ require_relative "anthropic/models/raw_message_stop_event"
|
|
274
311
|
require_relative "anthropic/models/raw_message_stream_event"
|
275
312
|
require_relative "anthropic/models/redacted_thinking_block"
|
276
313
|
require_relative "anthropic/models/redacted_thinking_block_param"
|
314
|
+
require_relative "anthropic/models/search_result_block_param"
|
277
315
|
require_relative "anthropic/models/server_tool_usage"
|
278
316
|
require_relative "anthropic/models/server_tool_use_block"
|
279
317
|
require_relative "anthropic/models/server_tool_use_block_param"
|
@@ -299,6 +337,8 @@ require_relative "anthropic/models/tool_choice_none"
|
|
299
337
|
require_relative "anthropic/models/tool_choice_tool"
|
300
338
|
require_relative "anthropic/models/tool_result_block_param"
|
301
339
|
require_relative "anthropic/models/tool_text_editor_20250124"
|
340
|
+
require_relative "anthropic/models/tool_text_editor_20250429"
|
341
|
+
require_relative "anthropic/models/tool_text_editor_20250728"
|
302
342
|
require_relative "anthropic/models/tool_union"
|
303
343
|
require_relative "anthropic/models/tool_use_block"
|
304
344
|
require_relative "anthropic/models/tool_use_block_param"
|
@@ -314,6 +354,10 @@ require_relative "anthropic/models/web_search_tool_result_block_content"
|
|
314
354
|
require_relative "anthropic/models/web_search_tool_result_block_param"
|
315
355
|
require_relative "anthropic/models/web_search_tool_result_block_param_content"
|
316
356
|
require_relative "anthropic/models/web_search_tool_result_error"
|
357
|
+
require_relative "anthropic/helpers/streaming/events"
|
358
|
+
require_relative "anthropic/helpers/streaming/message_stream"
|
359
|
+
require_relative "anthropic/helpers/streaming"
|
360
|
+
require_relative "anthropic/streaming"
|
317
361
|
require_relative "anthropic/models"
|
318
362
|
require_relative "anthropic/resources/beta"
|
319
363
|
require_relative "anthropic/resources/beta/files"
|
@@ -324,3 +368,13 @@ require_relative "anthropic/resources/completions"
|
|
324
368
|
require_relative "anthropic/resources/messages"
|
325
369
|
require_relative "anthropic/resources/messages/batches"
|
326
370
|
require_relative "anthropic/resources/models"
|
371
|
+
require_relative "anthropic/helpers/input_schema"
|
372
|
+
require_relative "anthropic/helpers/input_schema/property_mapping"
|
373
|
+
require_relative "anthropic/helpers/input_schema/json_schema_converter"
|
374
|
+
require_relative "anthropic/helpers/input_schema/base_model"
|
375
|
+
require_relative "anthropic/helpers/input_schema/array_of"
|
376
|
+
require_relative "anthropic/helpers/input_schema/boolean"
|
377
|
+
require_relative "anthropic/helpers/input_schema/enum_of"
|
378
|
+
require_relative "anthropic/helpers/input_schema/union_of"
|
379
|
+
require_relative "anthropic/helpers/input_schema/parsed_json"
|
380
|
+
require_relative "anthropic/input_schema"
|
data/rbi/anthropic/errors.rbi
CHANGED
@@ -8,6 +8,22 @@ module Anthropic
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class ConversionError < Anthropic::Errors::Error
|
11
|
+
sig { returns(T.nilable(StandardError)) }
|
12
|
+
def cause
|
13
|
+
end
|
14
|
+
|
15
|
+
# @api private
|
16
|
+
sig do
|
17
|
+
params(
|
18
|
+
on: T::Class[StandardError],
|
19
|
+
method: Symbol,
|
20
|
+
target: T.anything,
|
21
|
+
value: T.anything,
|
22
|
+
cause: T.nilable(StandardError)
|
23
|
+
).returns(T.attached_class)
|
24
|
+
end
|
25
|
+
def self.new(on:, method:, target:, value:, cause: nil)
|
26
|
+
end
|
11
27
|
end
|
12
28
|
|
13
29
|
class APIError < Anthropic::Errors::Error
|
@@ -43,10 +59,10 @@ module Anthropic
|
|
43
59
|
end
|
44
60
|
|
45
61
|
class APIConnectionError < Anthropic::Errors::APIError
|
46
|
-
sig {
|
62
|
+
sig { returns(NilClass) }
|
47
63
|
attr_accessor :status
|
48
64
|
|
49
|
-
sig {
|
65
|
+
sig { returns(NilClass) }
|
50
66
|
attr_accessor :body
|
51
67
|
|
52
68
|
# @api private
|
@@ -21,10 +21,15 @@ module Anthropic
|
|
21
21
|
# @api private
|
22
22
|
sig do
|
23
23
|
override
|
24
|
-
.params(
|
24
|
+
.params(
|
25
|
+
req:
|
26
|
+
Anthropic::Internal::Transport::BaseClient::RequestComponents,
|
27
|
+
opts: Anthropic::Internal::AnyHash
|
28
|
+
)
|
25
29
|
.returns(Anthropic::Internal::Transport::BaseClient::RequestInput)
|
26
30
|
end
|
27
|
-
private def build_request(req, opts)
|
31
|
+
private def build_request(req, opts)
|
32
|
+
end
|
28
33
|
|
29
34
|
sig do
|
30
35
|
params(
|
@@ -45,10 +50,15 @@ module Anthropic
|
|
45
50
|
end
|
46
51
|
|
47
52
|
sig do
|
48
|
-
params(
|
49
|
-
|
53
|
+
params(
|
54
|
+
request_components:
|
55
|
+
Anthropic::Internal::Transport::BaseClient::RequestComponents
|
56
|
+
).returns(
|
57
|
+
Anthropic::Internal::Transport::BaseClient::RequestComponents
|
58
|
+
)
|
59
|
+
end
|
60
|
+
private def fit_req_to_bedrock_specs!(request_components)
|
50
61
|
end
|
51
|
-
private def fit_req_to_bedrock_specs!(request_components) end
|
52
62
|
|
53
63
|
sig do
|
54
64
|
params(
|
@@ -75,7 +85,8 @@ module Anthropic
|
|
75
85
|
aws_secret_key: nil,
|
76
86
|
aws_session_token: nil,
|
77
87
|
aws_profile: nil
|
78
|
-
)
|
88
|
+
)
|
89
|
+
end
|
79
90
|
end
|
80
91
|
end
|
81
92
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
class ArrayOf < Anthropic::Internal::Type::ArrayOf
|
7
|
+
include Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
8
|
+
|
9
|
+
Elem = type_member(:out)
|
10
|
+
|
11
|
+
sig { returns(String) }
|
12
|
+
attr_reader :description
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
# Represents a response from Anthropic's API where the model's output has been structured according to a schema predefined by the user.
|
7
|
+
#
|
8
|
+
# This class is specifically used when making requests with the `response_format` parameter set to use structured output (e.g., JSON).
|
9
|
+
#
|
10
|
+
# See {examples/input_schemas.rb} for a complete example of use
|
11
|
+
class BaseModel < Anthropic::Internal::Type::BaseModel
|
12
|
+
extend Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
13
|
+
|
14
|
+
class << self
|
15
|
+
sig { params(doc: T.nilable(String)).void }
|
16
|
+
attr_writer :doc
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
# @example
|
7
|
+
# example = Anthropic::EnumOf[:foo, :bar, :zoo]
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# example = Anthropic::EnumOf[1, 2, 3]
|
11
|
+
class EnumOf
|
12
|
+
include Anthropic::Internal::Type::Enum
|
13
|
+
include Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
14
|
+
|
15
|
+
sig do
|
16
|
+
params(
|
17
|
+
values: T.any(NilClass, T::Boolean, Integer, Float, Symbol)
|
18
|
+
).returns(T.attached_class)
|
19
|
+
end
|
20
|
+
def self.[](*values)
|
21
|
+
end
|
22
|
+
|
23
|
+
sig do
|
24
|
+
returns(T::Array[T.any(NilClass, T::Boolean, Integer, Float, Symbol)])
|
25
|
+
end
|
26
|
+
attr_reader :values
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
JsonSchema = T.type_alias { Anthropic::Internal::AnyHash }
|
7
|
+
|
8
|
+
# To customize the JSON schema conversion for a type, implement the `JsonSchemaConverter` interface.
|
9
|
+
module JsonSchemaConverter
|
10
|
+
POINTER = T.let(Object.new.freeze, T.anything)
|
11
|
+
COUNTER = T.let(Object.new.freeze, T.anything)
|
12
|
+
|
13
|
+
Input =
|
14
|
+
T.type_alias do
|
15
|
+
T.any(
|
16
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter,
|
17
|
+
T::Class[T.anything]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
State =
|
21
|
+
T.type_alias do
|
22
|
+
{ defs: T::Hash[Object, String], path: T::Array[String] }
|
23
|
+
end
|
24
|
+
|
25
|
+
# The exact JSON schema produced is subject to improvement between minor release versions.
|
26
|
+
sig do
|
27
|
+
params(
|
28
|
+
state: Anthropic::Helpers::InputSchema::JsonSchemaConverter::State
|
29
|
+
).returns(Anthropic::Helpers::InputSchema::JsonSchema)
|
30
|
+
end
|
31
|
+
def to_json_schema_inner(state:)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Internal helpers methods.
|
35
|
+
class << self
|
36
|
+
# @api private
|
37
|
+
sig do
|
38
|
+
params(schema: Anthropic::Helpers::InputSchema::JsonSchema).returns(
|
39
|
+
Anthropic::Helpers::InputSchema::JsonSchema
|
40
|
+
)
|
41
|
+
end
|
42
|
+
def to_nilable(schema)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @api private
|
46
|
+
sig do
|
47
|
+
params(
|
48
|
+
schema: Anthropic::Helpers::InputSchema::JsonSchema,
|
49
|
+
meta: Anthropic::Internal::AnyHash
|
50
|
+
).void
|
51
|
+
end
|
52
|
+
def assoc_meta!(schema, meta:)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @api private
|
56
|
+
sig do
|
57
|
+
params(
|
58
|
+
state:
|
59
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter::State,
|
60
|
+
type: Anthropic::Helpers::InputSchema::JsonSchemaConverter::Input,
|
61
|
+
blk: T.proc.returns(Anthropic::Helpers::InputSchema::JsonSchema)
|
62
|
+
).void
|
63
|
+
end
|
64
|
+
def cache_def!(state, type:, &blk)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @api private
|
68
|
+
sig do
|
69
|
+
params(
|
70
|
+
type: Anthropic::Helpers::InputSchema::JsonSchemaConverter::Input
|
71
|
+
).returns(Anthropic::Helpers::InputSchema::JsonSchema)
|
72
|
+
end
|
73
|
+
def to_json_schema(type)
|
74
|
+
end
|
75
|
+
|
76
|
+
# @api private
|
77
|
+
sig do
|
78
|
+
params(
|
79
|
+
type: Anthropic::Helpers::InputSchema::JsonSchemaConverter::Input,
|
80
|
+
state: Anthropic::Helpers::InputSchema::JsonSchemaConverter::State
|
81
|
+
).returns(Anthropic::Helpers::InputSchema::JsonSchema)
|
82
|
+
end
|
83
|
+
def to_json_schema_inner(type, state:)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
# @example
|
7
|
+
# example = Anthropic::UnionOf[Float, Anthropic::ArrayOf[Integer]]
|
8
|
+
class UnionOf
|
9
|
+
include Anthropic::Internal::Type::Union
|
10
|
+
include Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
11
|
+
|
12
|
+
sig do
|
13
|
+
params(
|
14
|
+
variants:
|
15
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter::Input
|
16
|
+
).returns(T.attached_class)
|
17
|
+
end
|
18
|
+
def self.[](*variants)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|