anthropic 1.7.0 → 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 +34 -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 +2 -2
- 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_config.rb +19 -0
- data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +40 -0
- data/lib/anthropic/models/beta/beta_content_block.rb +8 -1
- data/lib/anthropic/models/beta/beta_content_block_param.rb +9 -1
- data/lib/anthropic/models/beta/beta_document_block.rb +56 -0
- 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 +10 -3
- data/lib/anthropic/models/beta/beta_request_document_block.rb +2 -2
- 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_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_result_block_param.rb +6 -4
- data/lib/anthropic/models/beta/beta_tool_union.rb +5 -1
- 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 +9 -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/document_block_param.rb +2 -2
- 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/tool_result_block_param.rb +6 -4
- data/lib/anthropic/models/tool_use_block.rb +8 -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 +39 -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_citation_config.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_content_block.rbi +3 -0
- data/rbi/anthropic/models/beta/beta_content_block_param.rbi +3 -0
- data/rbi/anthropic/models/beta/beta_document_block.rbi +95 -0
- data/rbi/anthropic/models/beta/beta_message.rbi +3 -0
- data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +6 -0
- data/rbi/anthropic/models/beta/beta_request_document_block.rbi +5 -3
- 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_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_result_block_param.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_tool_union.rbi +3 -1
- 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 +17 -53
- data/rbi/anthropic/models/beta/message_create_params.rbi +14 -52
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +14 -52
- data/rbi/anthropic/models/beta_error_response.rbi +10 -2
- data/rbi/anthropic/models/document_block_param.rbi +7 -3
- 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/tool_result_block_param.rbi +2 -1
- data/rbi/anthropic/resources/beta/messages.rbi +12 -75
- 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_citation_config.rbs +17 -0
- data/sig/anthropic/models/beta/beta_code_execution_tool_20250825.rbs +34 -0
- data/sig/anthropic/models/beta/beta_content_block.rbs +3 -0
- data/sig/anthropic/models/beta/beta_content_block_param.rbs +3 -0
- data/sig/anthropic/models/beta/beta_document_block.rbs +49 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +3 -0
- data/sig/anthropic/models/beta/beta_request_document_block.rbs +4 -8
- 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_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_result_block_param.rbs +1 -0
- data/sig/anthropic/models/beta/beta_tool_union.rbs +2 -0
- 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 +2 -0
- data/sig/anthropic/models/beta_error_response.rbs +13 -2
- data/sig/anthropic/models/document_block_param.rbs +4 -8
- data/sig/anthropic/models/error_response.rbs +13 -2
- data/sig/anthropic/models/tool_result_block_param.rbs +1 -0
- metadata +107 -2
@@ -22,7 +22,7 @@ module Anthropic
|
|
22
22
|
# @!attribute citations
|
23
23
|
#
|
24
24
|
# @return [Anthropic::Models::CitationsConfigParam, nil]
|
25
|
-
optional :citations, -> { Anthropic::CitationsConfigParam }
|
25
|
+
optional :citations, -> { Anthropic::CitationsConfigParam }, nil?: true
|
26
26
|
|
27
27
|
# @!attribute context
|
28
28
|
#
|
@@ -39,7 +39,7 @@ module Anthropic
|
|
39
39
|
#
|
40
40
|
# @param cache_control [Anthropic::Models::CacheControlEphemeral, nil] Create a cache control breakpoint at this content block.
|
41
41
|
#
|
42
|
-
# @param citations [Anthropic::Models::CitationsConfigParam]
|
42
|
+
# @param citations [Anthropic::Models::CitationsConfigParam, nil]
|
43
43
|
#
|
44
44
|
# @param context [String, nil]
|
45
45
|
#
|
@@ -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.
|
@@ -21,7 +21,7 @@ module Anthropic
|
|
21
21
|
|
22
22
|
# @!attribute content
|
23
23
|
#
|
24
|
-
# @return [String, Array<Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam>, nil]
|
24
|
+
# @return [String, Array<Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam, Anthropic::Models::DocumentBlockParam>, nil]
|
25
25
|
optional :content, union: -> { Anthropic::ToolResultBlockParam::Content }
|
26
26
|
|
27
27
|
# @!attribute is_error
|
@@ -34,7 +34,7 @@ module Anthropic
|
|
34
34
|
#
|
35
35
|
# @param cache_control [Anthropic::Models::CacheControlEphemeral, nil] Create a cache control breakpoint at this content block.
|
36
36
|
#
|
37
|
-
# @param content [String, Array<Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam>]
|
37
|
+
# @param content [String, Array<Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam, Anthropic::Models::DocumentBlockParam>]
|
38
38
|
#
|
39
39
|
# @param is_error [Boolean]
|
40
40
|
#
|
@@ -59,12 +59,14 @@ module Anthropic
|
|
59
59
|
|
60
60
|
variant :search_result, -> { Anthropic::SearchResultBlockParam }
|
61
61
|
|
62
|
+
variant :document, -> { Anthropic::DocumentBlockParam }
|
63
|
+
|
62
64
|
# @!method self.variants
|
63
|
-
# @return [Array(Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam)]
|
65
|
+
# @return [Array(Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam, Anthropic::Models::DocumentBlockParam)]
|
64
66
|
end
|
65
67
|
|
66
68
|
# @!method self.variants
|
67
|
-
# @return [Array(String, Array<Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam>)]
|
69
|
+
# @return [Array(String, Array<Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::SearchResultBlockParam, Anthropic::Models::DocumentBlockParam>)]
|
68
70
|
|
69
71
|
# @type [Anthropic::Internal::Type::Converter]
|
70
72
|
ContentArray =
|
@@ -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]
|
@@ -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, Anthropic::Models::Beta::BetaWebFetchTool20250910>] 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, Anthropic::Models::Beta::BetaWebFetchTool20250910>] 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, Anthropic::Models::Beta::BetaWebFetchTool20250910>] 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
data/lib/anthropic.rb
CHANGED
@@ -67,10 +67,19 @@ require_relative "anthropic/models/base64_pdf_source"
|
|
67
67
|
require_relative "anthropic/models/beta/beta_base64_image_source"
|
68
68
|
require_relative "anthropic/models/beta/beta_base64_pdf_block"
|
69
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"
|
70
78
|
require_relative "anthropic/models/beta/beta_cache_control_ephemeral"
|
71
79
|
require_relative "anthropic/models/beta/beta_cache_creation"
|
72
80
|
require_relative "anthropic/models/beta/beta_citation_char_location"
|
73
81
|
require_relative "anthropic/models/beta/beta_citation_char_location_param"
|
82
|
+
require_relative "anthropic/models/beta/beta_citation_config"
|
74
83
|
require_relative "anthropic/models/beta/beta_citation_content_block_location"
|
75
84
|
require_relative "anthropic/models/beta/beta_citation_content_block_location_param"
|
76
85
|
require_relative "anthropic/models/beta/beta_citation_page_location"
|
@@ -86,6 +95,7 @@ require_relative "anthropic/models/beta/beta_code_execution_output_block_param"
|
|
86
95
|
require_relative "anthropic/models/beta/beta_code_execution_result_block"
|
87
96
|
require_relative "anthropic/models/beta/beta_code_execution_result_block_param"
|
88
97
|
require_relative "anthropic/models/beta/beta_code_execution_tool_20250522"
|
98
|
+
require_relative "anthropic/models/beta/beta_code_execution_tool_20250825"
|
89
99
|
require_relative "anthropic/models/beta/beta_code_execution_tool_result_block"
|
90
100
|
require_relative "anthropic/models/beta/beta_code_execution_tool_result_block_content"
|
91
101
|
require_relative "anthropic/models/beta/beta_code_execution_tool_result_block_param"
|
@@ -100,6 +110,7 @@ require_relative "anthropic/models/beta/beta_content_block"
|
|
100
110
|
require_relative "anthropic/models/beta/beta_content_block_param"
|
101
111
|
require_relative "anthropic/models/beta/beta_content_block_source"
|
102
112
|
require_relative "anthropic/models/beta/beta_content_block_source_content"
|
113
|
+
require_relative "anthropic/models/beta/beta_document_block"
|
103
114
|
require_relative "anthropic/models/beta/beta_file_document_source"
|
104
115
|
require_relative "anthropic/models/beta/beta_file_image_source"
|
105
116
|
require_relative "anthropic/models/beta/beta_image_block_param"
|
@@ -138,6 +149,16 @@ require_relative "anthropic/models/beta/beta_text_block_param"
|
|
138
149
|
require_relative "anthropic/models/beta/beta_text_citation"
|
139
150
|
require_relative "anthropic/models/beta/beta_text_citation_param"
|
140
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"
|
141
162
|
require_relative "anthropic/models/beta/beta_thinking_block"
|
142
163
|
require_relative "anthropic/models/beta/beta_thinking_block_param"
|
143
164
|
require_relative "anthropic/models/beta/beta_thinking_config_disabled"
|
@@ -165,6 +186,14 @@ require_relative "anthropic/models/beta/beta_tool_use_block_param"
|
|
165
186
|
require_relative "anthropic/models/beta/beta_url_image_source"
|
166
187
|
require_relative "anthropic/models/beta/beta_url_pdf_source"
|
167
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"
|
168
197
|
require_relative "anthropic/models/beta/beta_web_search_result_block"
|
169
198
|
require_relative "anthropic/models/beta/beta_web_search_result_block_param"
|
170
199
|
require_relative "anthropic/models/beta/beta_web_search_tool_20250305"
|
@@ -339,3 +368,13 @@ require_relative "anthropic/resources/completions"
|
|
339
368
|
require_relative "anthropic/resources/messages"
|
340
369
|
require_relative "anthropic/resources/messages/batches"
|
341
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
@@ -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
|