anthropic 1.6.0 → 1.8.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 +33 -0
- data/README.md +1 -1
- 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/message_stream.rb +41 -1
- data/lib/anthropic/input_schema.rb +10 -0
- data/lib/anthropic/internal/stream.rb +2 -1
- data/lib/anthropic/internal/transport/base_client.rb +1 -2
- data/lib/anthropic/internal/transport/pooled_net_requester.rb +1 -9
- data/lib/anthropic/internal/type/base_model.rb +2 -9
- data/lib/anthropic/internal/util.rb +1 -1
- 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_code_execution_tool_20250825.rb +40 -0
- data/lib/anthropic/models/beta/beta_content_block.rb +6 -1
- data/lib/anthropic/models/beta/beta_content_block_param.rb +7 -1
- data/lib/anthropic/models/beta/beta_message.rb +2 -2
- data/lib/anthropic/models/beta/beta_message_param.rb +3 -3
- data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +8 -3
- data/lib/anthropic/models/beta/beta_server_tool_use_block.rb +2 -0
- data/lib/anthropic/models/beta/beta_server_tool_use_block_param.rb +2 -0
- 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_union.rb +3 -1
- data/lib/anthropic/models/beta/message_count_tokens_params.rb +7 -30
- data/lib/anthropic/models/beta/message_create_params.rb +3 -26
- data/lib/anthropic/models/beta/messages/batch_create_params.rb +6 -36
- 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/error_response.rb +7 -1
- data/lib/anthropic/models/message_count_tokens_params.rb +1 -24
- data/lib/anthropic/models/message_create_params.rb +1 -24
- data/lib/anthropic/models/messages/batch_create_params.rb +2 -28
- data/lib/anthropic/models/model.rb +6 -0
- data/lib/anthropic/models/tool_use_block.rb +8 -0
- data/lib/anthropic/models/usage.rb +9 -1
- data/lib/anthropic/models.rb +2 -0
- data/lib/anthropic/resources/beta/messages.rb +3 -3
- data/lib/anthropic/resources/messages.rb +85 -1
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +30 -0
- data/rbi/anthropic/errors.rbi +2 -2
- 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/structured_output.rbi +16 -0
- data/rbi/anthropic/input_schema.rbi +12 -0
- 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_code_execution_tool_20250825.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_content_block.rbi +2 -0
- data/rbi/anthropic/models/beta/beta_content_block_param.rbi +2 -0
- data/rbi/anthropic/models/beta/beta_message.rbi +2 -0
- data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +4 -0
- data/rbi/anthropic/models/beta/beta_server_tool_use_block.rbi +10 -0
- data/rbi/anthropic/models/beta/beta_server_tool_use_block_param.rbi +10 -0
- 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_union.rbi +1 -0
- data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +7 -48
- data/rbi/anthropic/models/beta/message_create_params.rbi +6 -48
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +6 -48
- 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/error_response.rbi +10 -2
- data/rbi/anthropic/models/message_count_tokens_params.rbi +2 -48
- data/rbi/anthropic/models/message_create_params.rbi +2 -48
- data/rbi/anthropic/models/messages/batch_create_params.rbi +2 -48
- data/rbi/anthropic/models/usage.rbi +13 -0
- data/rbi/anthropic/models.rbi +2 -0
- data/rbi/anthropic/resources/beta/messages.rbi +6 -72
- data/rbi/anthropic/resources/messages.rbi +3 -72
- 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_code_execution_tool_20250825.rbs +34 -0
- data/sig/anthropic/models/beta/beta_content_block.rbs +2 -0
- data/sig/anthropic/models/beta/beta_content_block_param.rbs +2 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +2 -0
- data/sig/anthropic/models/beta/beta_server_tool_use_block.rbs +7 -1
- data/sig/anthropic/models/beta/beta_server_tool_use_block_param.rbs +7 -1
- 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_union.rbs +1 -0
- data/sig/anthropic/models/beta/message_count_tokens_params.rbs +1 -0
- 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/error_response.rbs +13 -2
- data/sig/anthropic/models/usage.rbs +5 -0
- data/sig/anthropic/models.rbs +2 -0
- metadata +80 -2
@@ -80,30 +80,7 @@ module Anthropic
|
|
80
80
|
# { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
81
81
|
# ```
|
82
82
|
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
# ```json
|
86
|
-
# {
|
87
|
-
# "role": "user",
|
88
|
-
# "content": [
|
89
|
-
# {
|
90
|
-
# "type": "image",
|
91
|
-
# "source": {
|
92
|
-
# "type": "base64",
|
93
|
-
# "media_type": "image/jpeg",
|
94
|
-
# "data": "/9j/4AAQSkZJRg..."
|
95
|
-
# }
|
96
|
-
# },
|
97
|
-
# { "type": "text", "text": "What is in this image?" }
|
98
|
-
# ]
|
99
|
-
# }
|
100
|
-
# ```
|
101
|
-
#
|
102
|
-
# We currently support the `base64` source type for images, and the `image/jpeg`,
|
103
|
-
# `image/png`, `image/gif`, and `image/webp` media types.
|
104
|
-
#
|
105
|
-
# See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
106
|
-
# more input examples.
|
83
|
+
# See [input examples](https://docs.anthropic.com/en/api/messages-examples).
|
107
84
|
#
|
108
85
|
# Note that if you want to include a
|
109
86
|
# [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
@@ -287,7 +264,7 @@ module Anthropic
|
|
287
264
|
#
|
288
265
|
# See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
|
289
266
|
#
|
290
|
-
# @return [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>, nil]
|
267
|
+
# @return [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaCodeExecutionTool20250825, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>, nil]
|
291
268
|
optional :tools, -> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::Beta::BetaToolUnion] }
|
292
269
|
|
293
270
|
# @!attribute top_k
|
@@ -350,7 +327,7 @@ module Anthropic
|
|
350
327
|
#
|
351
328
|
# @param tool_choice [Anthropic::Models::Beta::BetaToolChoiceAuto, Anthropic::Models::Beta::BetaToolChoiceAny, Anthropic::Models::Beta::BetaToolChoiceTool, Anthropic::Models::Beta::BetaToolChoiceNone] How the model should use the provided tools. The model can use a specific tool,
|
352
329
|
#
|
353
|
-
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Definitions of tools that the model may use.
|
330
|
+
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaCodeExecutionTool20250825, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Definitions of tools that the model may use.
|
354
331
|
#
|
355
332
|
# @param top_k [Integer] Only sample from the top K options for each subsequent token.
|
356
333
|
#
|
@@ -15,9 +15,7 @@ module Anthropic
|
|
15
15
|
#
|
16
16
|
# @return [Array<Anthropic::Models::Beta::Messages::BatchCreateParams::Request>]
|
17
17
|
required :requests,
|
18
|
-
-> {
|
19
|
-
Anthropic::Internal::Type::ArrayOf[Anthropic::Beta::Messages::BatchCreateParams::Request]
|
20
|
-
}
|
18
|
+
-> { Anthropic::Internal::Type::ArrayOf[Anthropic::Beta::Messages::BatchCreateParams::Request] }
|
21
19
|
|
22
20
|
# @!attribute betas
|
23
21
|
# Optional header to specify the beta version(s) you want to use.
|
@@ -135,30 +133,7 @@ module Anthropic
|
|
135
133
|
# { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
136
134
|
# ```
|
137
135
|
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
# ```json
|
141
|
-
# {
|
142
|
-
# "role": "user",
|
143
|
-
# "content": [
|
144
|
-
# {
|
145
|
-
# "type": "image",
|
146
|
-
# "source": {
|
147
|
-
# "type": "base64",
|
148
|
-
# "media_type": "image/jpeg",
|
149
|
-
# "data": "/9j/4AAQSkZJRg..."
|
150
|
-
# }
|
151
|
-
# },
|
152
|
-
# { "type": "text", "text": "What is in this image?" }
|
153
|
-
# ]
|
154
|
-
# }
|
155
|
-
# ```
|
156
|
-
#
|
157
|
-
# We currently support the `base64` source type for images, and the `image/jpeg`,
|
158
|
-
# `image/png`, `image/gif`, and `image/webp` media types.
|
159
|
-
#
|
160
|
-
# See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
161
|
-
# more input examples.
|
136
|
+
# See [input examples](https://docs.anthropic.com/en/api/messages-examples).
|
162
137
|
#
|
163
138
|
# Note that if you want to include a
|
164
139
|
# [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
@@ -189,9 +164,7 @@ module Anthropic
|
|
189
164
|
#
|
190
165
|
# @return [Array<Anthropic::Models::Beta::BetaRequestMCPServerURLDefinition>, nil]
|
191
166
|
optional :mcp_servers,
|
192
|
-
-> {
|
193
|
-
Anthropic::Internal::Type::ArrayOf[Anthropic::Beta::BetaRequestMCPServerURLDefinition]
|
194
|
-
}
|
167
|
+
-> { Anthropic::Internal::Type::ArrayOf[Anthropic::Beta::BetaRequestMCPServerURLDefinition] }
|
195
168
|
|
196
169
|
# @!attribute metadata
|
197
170
|
# An object describing metadata about the request.
|
@@ -356,11 +329,8 @@ module Anthropic
|
|
356
329
|
#
|
357
330
|
# See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
|
358
331
|
#
|
359
|
-
# @return [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>, nil]
|
360
|
-
optional :tools,
|
361
|
-
-> {
|
362
|
-
Anthropic::Internal::Type::ArrayOf[union: Anthropic::Beta::BetaToolUnion]
|
363
|
-
}
|
332
|
+
# @return [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaCodeExecutionTool20250825, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>, nil]
|
333
|
+
optional :tools, -> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::Beta::BetaToolUnion] }
|
364
334
|
|
365
335
|
# @!attribute top_k
|
366
336
|
# Only sample from the top K options for each subsequent token.
|
@@ -424,7 +394,7 @@ module Anthropic
|
|
424
394
|
#
|
425
395
|
# @param tool_choice [Anthropic::Models::Beta::BetaToolChoiceAuto, Anthropic::Models::Beta::BetaToolChoiceAny, Anthropic::Models::Beta::BetaToolChoiceTool, Anthropic::Models::Beta::BetaToolChoiceNone] How the model should use the provided tools. The model can use a specific tool,
|
426
396
|
#
|
427
|
-
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Definitions of tools that the model may use.
|
397
|
+
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaCodeExecutionTool20250825, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Definitions of tools that the model may use.
|
428
398
|
#
|
429
399
|
# @param top_k [Integer] Only sample from the top K options for each subsequent token.
|
430
400
|
#
|
@@ -56,10 +56,7 @@ module Anthropic
|
|
56
56
|
# Processing status of the Message Batch.
|
57
57
|
#
|
58
58
|
# @return [Symbol, Anthropic::Models::Beta::Messages::BetaMessageBatch::ProcessingStatus]
|
59
|
-
required :processing_status,
|
60
|
-
enum: -> {
|
61
|
-
Anthropic::Beta::Messages::BetaMessageBatch::ProcessingStatus
|
62
|
-
}
|
59
|
+
required :processing_status, enum: -> { Anthropic::Beta::Messages::BetaMessageBatch::ProcessingStatus }
|
63
60
|
|
64
61
|
# @!attribute request_counts
|
65
62
|
# Tallies requests within the Message Batch, categorized by their status.
|
@@ -8,13 +8,19 @@ module Anthropic
|
|
8
8
|
# @return [Anthropic::Models::BetaInvalidRequestError, Anthropic::Models::BetaAuthenticationError, Anthropic::Models::BetaBillingError, Anthropic::Models::BetaPermissionError, Anthropic::Models::BetaNotFoundError, Anthropic::Models::BetaRateLimitError, Anthropic::Models::BetaGatewayTimeoutError, Anthropic::Models::BetaAPIError, Anthropic::Models::BetaOverloadedError]
|
9
9
|
required :error, union: -> { Anthropic::BetaError }
|
10
10
|
|
11
|
+
# @!attribute request_id
|
12
|
+
#
|
13
|
+
# @return [String, nil]
|
14
|
+
required :request_id, String, nil?: true
|
15
|
+
|
11
16
|
# @!attribute type
|
12
17
|
#
|
13
18
|
# @return [Symbol, :error]
|
14
19
|
required :type, const: :error
|
15
20
|
|
16
|
-
# @!method initialize(error:, type: :error)
|
21
|
+
# @!method initialize(error:, request_id:, type: :error)
|
17
22
|
# @param error [Anthropic::Models::BetaInvalidRequestError, Anthropic::Models::BetaAuthenticationError, Anthropic::Models::BetaBillingError, Anthropic::Models::BetaPermissionError, Anthropic::Models::BetaNotFoundError, Anthropic::Models::BetaRateLimitError, Anthropic::Models::BetaGatewayTimeoutError, Anthropic::Models::BetaAPIError, Anthropic::Models::BetaOverloadedError]
|
23
|
+
# @param request_id [String, nil]
|
18
24
|
# @param type [Symbol, :error]
|
19
25
|
end
|
20
26
|
end
|
@@ -8,8 +8,46 @@ module Anthropic
|
|
8
8
|
# @return [Symbol, :ephemeral]
|
9
9
|
required :type, const: :ephemeral
|
10
10
|
|
11
|
-
# @!
|
11
|
+
# @!attribute ttl
|
12
|
+
# The time-to-live for the cache control breakpoint.
|
13
|
+
#
|
14
|
+
# This may be one the following values:
|
15
|
+
#
|
16
|
+
# - `5m`: 5 minutes
|
17
|
+
# - `1h`: 1 hour
|
18
|
+
#
|
19
|
+
# Defaults to `5m`.
|
20
|
+
#
|
21
|
+
# @return [Symbol, Anthropic::Models::CacheControlEphemeral::TTL, nil]
|
22
|
+
optional :ttl, enum: -> { Anthropic::CacheControlEphemeral::TTL }
|
23
|
+
|
24
|
+
# @!method initialize(ttl: nil, type: :ephemeral)
|
25
|
+
# Some parameter documentations has been truncated, see
|
26
|
+
# {Anthropic::Models::CacheControlEphemeral} for more details.
|
27
|
+
#
|
28
|
+
# @param ttl [Symbol, Anthropic::Models::CacheControlEphemeral::TTL] The time-to-live for the cache control breakpoint.
|
29
|
+
#
|
12
30
|
# @param type [Symbol, :ephemeral]
|
31
|
+
|
32
|
+
# The time-to-live for the cache control breakpoint.
|
33
|
+
#
|
34
|
+
# This may be one the following values:
|
35
|
+
#
|
36
|
+
# - `5m`: 5 minutes
|
37
|
+
# - `1h`: 1 hour
|
38
|
+
#
|
39
|
+
# Defaults to `5m`.
|
40
|
+
#
|
41
|
+
# @see Anthropic::Models::CacheControlEphemeral#ttl
|
42
|
+
module TTL
|
43
|
+
extend Anthropic::Internal::Type::Enum
|
44
|
+
|
45
|
+
TTL_5M = :"5m"
|
46
|
+
TTL_1H = :"1h"
|
47
|
+
|
48
|
+
# @!method self.values
|
49
|
+
# @return [Array<Symbol>]
|
50
|
+
end
|
13
51
|
end
|
14
52
|
end
|
15
53
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Models
|
5
|
+
class CacheCreation < Anthropic::Internal::Type::BaseModel
|
6
|
+
# @!attribute ephemeral_1h_input_tokens
|
7
|
+
# The number of input tokens used to create the 1 hour cache entry.
|
8
|
+
#
|
9
|
+
# @return [Integer]
|
10
|
+
required :ephemeral_1h_input_tokens, Integer
|
11
|
+
|
12
|
+
# @!attribute ephemeral_5m_input_tokens
|
13
|
+
# The number of input tokens used to create the 5 minute cache entry.
|
14
|
+
#
|
15
|
+
# @return [Integer]
|
16
|
+
required :ephemeral_5m_input_tokens, Integer
|
17
|
+
|
18
|
+
# @!method initialize(ephemeral_1h_input_tokens:, ephemeral_5m_input_tokens:)
|
19
|
+
# @param ephemeral_1h_input_tokens [Integer] The number of input tokens used to create the 1 hour cache entry.
|
20
|
+
#
|
21
|
+
# @param ephemeral_5m_input_tokens [Integer] The number of input tokens used to create the 5 minute cache entry.
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -8,13 +8,19 @@ module Anthropic
|
|
8
8
|
# @return [Anthropic::Models::InvalidRequestError, Anthropic::Models::AuthenticationError, Anthropic::Models::BillingError, Anthropic::Models::PermissionError, Anthropic::Models::NotFoundError, Anthropic::Models::RateLimitError, Anthropic::Models::GatewayTimeoutError, Anthropic::Models::APIErrorObject, Anthropic::Models::OverloadedError]
|
9
9
|
required :error, union: -> { Anthropic::ErrorObject }
|
10
10
|
|
11
|
+
# @!attribute request_id
|
12
|
+
#
|
13
|
+
# @return [String, nil]
|
14
|
+
required :request_id, String, nil?: true
|
15
|
+
|
11
16
|
# @!attribute type
|
12
17
|
#
|
13
18
|
# @return [Symbol, :error]
|
14
19
|
required :type, const: :error
|
15
20
|
|
16
|
-
# @!method initialize(error:, type: :error)
|
21
|
+
# @!method initialize(error:, request_id:, type: :error)
|
17
22
|
# @param error [Anthropic::Models::InvalidRequestError, Anthropic::Models::AuthenticationError, Anthropic::Models::BillingError, Anthropic::Models::PermissionError, Anthropic::Models::NotFoundError, Anthropic::Models::RateLimitError, Anthropic::Models::GatewayTimeoutError, Anthropic::Models::APIErrorObject, Anthropic::Models::OverloadedError]
|
23
|
+
# @param request_id [String, nil]
|
18
24
|
# @param type [Symbol, :error]
|
19
25
|
end
|
20
26
|
end
|
@@ -65,30 +65,7 @@ module Anthropic
|
|
65
65
|
# { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
66
66
|
# ```
|
67
67
|
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# ```json
|
71
|
-
# {
|
72
|
-
# "role": "user",
|
73
|
-
# "content": [
|
74
|
-
# {
|
75
|
-
# "type": "image",
|
76
|
-
# "source": {
|
77
|
-
# "type": "base64",
|
78
|
-
# "media_type": "image/jpeg",
|
79
|
-
# "data": "/9j/4AAQSkZJRg..."
|
80
|
-
# }
|
81
|
-
# },
|
82
|
-
# { "type": "text", "text": "What is in this image?" }
|
83
|
-
# ]
|
84
|
-
# }
|
85
|
-
# ```
|
86
|
-
#
|
87
|
-
# We currently support the `base64` source type for images, and the `image/jpeg`,
|
88
|
-
# `image/png`, `image/gif`, and `image/webp` media types.
|
89
|
-
#
|
90
|
-
# See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
91
|
-
# more input examples.
|
68
|
+
# See [input examples](https://docs.anthropic.com/en/api/messages-examples).
|
92
69
|
#
|
93
70
|
# Note that if you want to include a
|
94
71
|
# [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
@@ -79,30 +79,7 @@ module Anthropic
|
|
79
79
|
# { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
80
80
|
# ```
|
81
81
|
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
# ```json
|
85
|
-
# {
|
86
|
-
# "role": "user",
|
87
|
-
# "content": [
|
88
|
-
# {
|
89
|
-
# "type": "image",
|
90
|
-
# "source": {
|
91
|
-
# "type": "base64",
|
92
|
-
# "media_type": "image/jpeg",
|
93
|
-
# "data": "/9j/4AAQSkZJRg..."
|
94
|
-
# }
|
95
|
-
# },
|
96
|
-
# { "type": "text", "text": "What is in this image?" }
|
97
|
-
# ]
|
98
|
-
# }
|
99
|
-
# ```
|
100
|
-
#
|
101
|
-
# We currently support the `base64` source type for images, and the `image/jpeg`,
|
102
|
-
# `image/png`, `image/gif`, and `image/webp` media types.
|
103
|
-
#
|
104
|
-
# See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
105
|
-
# more input examples.
|
82
|
+
# See [input examples](https://docs.anthropic.com/en/api/messages-examples).
|
106
83
|
#
|
107
84
|
# Note that if you want to include a
|
108
85
|
# [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
@@ -123,30 +123,7 @@ module Anthropic
|
|
123
123
|
# { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
124
124
|
# ```
|
125
125
|
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
# ```json
|
129
|
-
# {
|
130
|
-
# "role": "user",
|
131
|
-
# "content": [
|
132
|
-
# {
|
133
|
-
# "type": "image",
|
134
|
-
# "source": {
|
135
|
-
# "type": "base64",
|
136
|
-
# "media_type": "image/jpeg",
|
137
|
-
# "data": "/9j/4AAQSkZJRg..."
|
138
|
-
# }
|
139
|
-
# },
|
140
|
-
# { "type": "text", "text": "What is in this image?" }
|
141
|
-
# ]
|
142
|
-
# }
|
143
|
-
# ```
|
144
|
-
#
|
145
|
-
# We currently support the `base64` source type for images, and the `image/jpeg`,
|
146
|
-
# `image/png`, `image/gif`, and `image/webp` media types.
|
147
|
-
#
|
148
|
-
# See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
149
|
-
# more input examples.
|
126
|
+
# See [input examples](https://docs.anthropic.com/en/api/messages-examples).
|
150
127
|
#
|
151
128
|
# Note that if you want to include a
|
152
129
|
# [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
@@ -180,10 +157,7 @@ module Anthropic
|
|
180
157
|
# [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
|
181
158
|
#
|
182
159
|
# @return [Symbol, Anthropic::Models::Messages::BatchCreateParams::Request::Params::ServiceTier, nil]
|
183
|
-
optional :service_tier,
|
184
|
-
enum: -> {
|
185
|
-
Anthropic::Messages::BatchCreateParams::Request::Params::ServiceTier
|
186
|
-
}
|
160
|
+
optional :service_tier, enum: -> { Anthropic::Messages::BatchCreateParams::Request::Params::ServiceTier }
|
187
161
|
|
188
162
|
# @!attribute stop_sequences
|
189
163
|
# Custom text sequences that will cause the model to stop generating.
|
@@ -78,8 +78,14 @@ module Anthropic
|
|
78
78
|
CLAUDE_3_5_SONNET_LATEST = :"claude-3-5-sonnet-latest"
|
79
79
|
|
80
80
|
# Our previous most intelligent model
|
81
|
+
# @deprecated Will reach end-of-life on October 22, 2025. Please migrate to a newer model.
|
82
|
+
# Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more
|
83
|
+
# information.
|
81
84
|
CLAUDE_3_5_SONNET_20241022 = :"claude-3-5-sonnet-20241022"
|
82
85
|
|
86
|
+
# @deprecated Will reach end-of-life on October 22, 2025. Please migrate to a newer model.
|
87
|
+
# Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more
|
88
|
+
# information.
|
83
89
|
CLAUDE_3_5_SONNET_20240620 = :"claude-3-5-sonnet-20240620"
|
84
90
|
|
85
91
|
# Our most capable model
|
@@ -29,6 +29,14 @@ module Anthropic
|
|
29
29
|
# Used by streaming helpers to reconstruct complete JSON input from deltas.
|
30
30
|
optional :json_buf, String
|
31
31
|
|
32
|
+
response_only do
|
33
|
+
# @api public
|
34
|
+
#
|
35
|
+
# Parsed input data coerced to the tool's input schema model.
|
36
|
+
# Only present when tools are defined using the InputSchema DSL.
|
37
|
+
optional :parsed, Anthropic::Internal::Type::Unknown
|
38
|
+
end
|
39
|
+
|
32
40
|
# @!method initialize(id:, input:, name:, type: :tool_use)
|
33
41
|
# @param id [String]
|
34
42
|
# @param input [Object]
|
@@ -3,6 +3,12 @@
|
|
3
3
|
module Anthropic
|
4
4
|
module Models
|
5
5
|
class Usage < Anthropic::Internal::Type::BaseModel
|
6
|
+
# @!attribute cache_creation
|
7
|
+
# Breakdown of cached tokens by TTL
|
8
|
+
#
|
9
|
+
# @return [Anthropic::Models::CacheCreation, nil]
|
10
|
+
required :cache_creation, -> { Anthropic::CacheCreation }, nil?: true
|
11
|
+
|
6
12
|
# @!attribute cache_creation_input_tokens
|
7
13
|
# The number of input tokens used to create the cache entry.
|
8
14
|
#
|
@@ -39,7 +45,9 @@ module Anthropic
|
|
39
45
|
# @return [Symbol, Anthropic::Models::Usage::ServiceTier, nil]
|
40
46
|
required :service_tier, enum: -> { Anthropic::Usage::ServiceTier }, nil?: true
|
41
47
|
|
42
|
-
# @!method initialize(cache_creation_input_tokens:, cache_read_input_tokens:, input_tokens:, output_tokens:, server_tool_use:, service_tier:)
|
48
|
+
# @!method initialize(cache_creation:, cache_creation_input_tokens:, cache_read_input_tokens:, input_tokens:, output_tokens:, server_tool_use:, service_tier:)
|
49
|
+
# @param cache_creation [Anthropic::Models::CacheCreation, nil] Breakdown of cached tokens by TTL
|
50
|
+
#
|
43
51
|
# @param cache_creation_input_tokens [Integer, nil] The number of input tokens used to create the cache entry.
|
44
52
|
#
|
45
53
|
# @param cache_read_input_tokens [Integer, nil] The number of input tokens read from the cache.
|
data/lib/anthropic/models.rb
CHANGED
@@ -77,6 +77,8 @@ module Anthropic
|
|
77
77
|
|
78
78
|
CacheControlEphemeral = Anthropic::Models::CacheControlEphemeral
|
79
79
|
|
80
|
+
CacheCreation = Anthropic::Models::CacheCreation
|
81
|
+
|
80
82
|
CitationCharLocation = Anthropic::Models::CitationCharLocation
|
81
83
|
|
82
84
|
CitationCharLocationParam = Anthropic::Models::CitationCharLocationParam
|
@@ -46,7 +46,7 @@ module Anthropic
|
|
46
46
|
#
|
47
47
|
# @param tool_choice [Anthropic::Models::Beta::BetaToolChoiceAuto, Anthropic::Models::Beta::BetaToolChoiceAny, Anthropic::Models::Beta::BetaToolChoiceTool, Anthropic::Models::Beta::BetaToolChoiceNone] Body param: How the model should use the provided tools. The model can use a spe
|
48
48
|
#
|
49
|
-
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Body param: Definitions of tools that the model may use.
|
49
|
+
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaCodeExecutionTool20250825, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Body param: Definitions of tools that the model may use.
|
50
50
|
#
|
51
51
|
# @param top_k [Integer] Body param: Only sample from the top K options for each subsequent token.
|
52
52
|
#
|
@@ -128,7 +128,7 @@ module Anthropic
|
|
128
128
|
#
|
129
129
|
# @param tool_choice [Anthropic::Models::Beta::BetaToolChoiceAuto, Anthropic::Models::Beta::BetaToolChoiceAny, Anthropic::Models::Beta::BetaToolChoiceTool, Anthropic::Models::Beta::BetaToolChoiceNone] Body param: How the model should use the provided tools. The model can use a spe
|
130
130
|
#
|
131
|
-
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Body param: Definitions of tools that the model may use.
|
131
|
+
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaCodeExecutionTool20250825, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Body param: Definitions of tools that the model may use.
|
132
132
|
#
|
133
133
|
# @param top_k [Integer] Body param: Only sample from the top K options for each subsequent token.
|
134
134
|
#
|
@@ -259,7 +259,7 @@ module Anthropic
|
|
259
259
|
#
|
260
260
|
# @param tool_choice [Anthropic::Models::Beta::BetaToolChoiceAuto, Anthropic::Models::Beta::BetaToolChoiceAny, Anthropic::Models::Beta::BetaToolChoiceTool, Anthropic::Models::Beta::BetaToolChoiceNone] Body param: How the model should use the provided tools. The model can use a spe
|
261
261
|
#
|
262
|
-
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Body param: Definitions of tools that the model may use.
|
262
|
+
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::BetaToolBash20241022, Anthropic::Models::Beta::BetaToolBash20250124, Anthropic::Models::Beta::BetaCodeExecutionTool20250522, Anthropic::Models::Beta::BetaCodeExecutionTool20250825, Anthropic::Models::Beta::BetaToolComputerUse20241022, Anthropic::Models::Beta::BetaToolComputerUse20250124, Anthropic::Models::Beta::BetaToolTextEditor20241022, Anthropic::Models::Beta::BetaToolTextEditor20250124, Anthropic::Models::Beta::BetaToolTextEditor20250429, Anthropic::Models::Beta::BetaToolTextEditor20250728, Anthropic::Models::Beta::BetaWebSearchTool20250305>] Body param: Definitions of tools that the model may use.
|
263
263
|
#
|
264
264
|
# @param betas [Array<String, Symbol, Anthropic::Models::AnthropicBeta>] Header param: Optional header to specify the beta version(s) you want to use.
|
265
265
|
#
|
@@ -59,6 +59,12 @@ module Anthropic
|
|
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,6 +82,7 @@ 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
|
@@ -133,6 +140,9 @@ module Anthropic
|
|
133
140
|
raise ArgumentError.new(message)
|
134
141
|
end
|
135
142
|
parsed.store(:stream, true)
|
143
|
+
|
144
|
+
tool_models = get_structured_output_models(parsed)
|
145
|
+
|
136
146
|
raw_stream = @client.request(
|
137
147
|
method: :post,
|
138
148
|
path: "v1/messages",
|
@@ -142,7 +152,10 @@ module Anthropic
|
|
142
152
|
model: Anthropic::Models::RawMessageStreamEvent,
|
143
153
|
options: options
|
144
154
|
)
|
145
|
-
Anthropic::Streaming::MessageStream.new(
|
155
|
+
Anthropic::Streaming::MessageStream.new(
|
156
|
+
raw_stream: raw_stream,
|
157
|
+
tool_models: tool_models
|
158
|
+
)
|
146
159
|
end
|
147
160
|
|
148
161
|
# See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
|
@@ -257,6 +270,77 @@ module Anthropic
|
|
257
270
|
@client = client
|
258
271
|
@batches = Anthropic::Resources::Messages::Batches.new(client: client)
|
259
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
|
260
344
|
end
|
261
345
|
end
|
262
346
|
end
|
data/lib/anthropic/version.rb
CHANGED