anthropic 1.1.1 → 1.6.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 +123 -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/streaming/events.rb +141 -0
- data/lib/anthropic/helpers/streaming/message_stream.rb +238 -0
- data/lib/anthropic/helpers/streaming.rb +37 -0
- data/lib/anthropic/helpers/vertex/client.rb +4 -1
- data/lib/anthropic/internal/stream.rb +4 -2
- data/lib/anthropic/internal/transport/base_client.rb +29 -3
- data/lib/anthropic/internal/type/array_of.rb +7 -1
- data/lib/anthropic/internal/type/base_model.rb +80 -24
- 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 +8 -9
- 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_citation_char_location.rb +7 -1
- 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_content_block.rb +5 -5
- data/lib/anthropic/models/beta/beta_content_block_param.rb +20 -17
- 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 +7 -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_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_tool.rb +7 -1
- data/lib/anthropic/models/beta/beta_tool_result_block_param.rb +6 -4
- data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +49 -0
- data/lib/anthropic/models/beta/beta_tool_union.rb +9 -7
- data/lib/anthropic/models/beta/message_count_tokens_params.rb +18 -10
- data/lib/anthropic/models/beta/message_create_params.rb +9 -3
- data/lib/anthropic/models/beta/messages/batch_create_params.rb +9 -3
- 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/message.rb +6 -2
- data/lib/anthropic/models/message_count_tokens_params.rb +9 -3
- data/lib/anthropic/models/message_count_tokens_tool.rb +5 -1
- data/lib/anthropic/models/message_create_params.rb +9 -3
- data/lib/anthropic/models/message_param.rb +3 -3
- data/lib/anthropic/models/messages/batch_create_params.rb +9 -3
- data/lib/anthropic/models/model.rb +10 -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 +6 -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 +6 -0
- data/lib/anthropic/models.rb +14 -4
- data/lib/anthropic/resources/beta/messages.rb +73 -6
- data/lib/anthropic/resources/messages.rb +68 -7
- data/lib/anthropic/streaming.rb +5 -0
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +14 -0
- data/rbi/anthropic/errors.rbi +16 -0
- data/rbi/anthropic/helpers/bedrock/client.rbi +17 -6
- data/rbi/anthropic/helpers/streaming/events.rbi +95 -0
- data/rbi/anthropic/helpers/streaming/message_stream.rbi +73 -0
- data/rbi/anthropic/helpers/vertex/client.rbi +17 -6
- 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_citation_char_location.rbi +6 -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_content_block.rbi +3 -3
- data/rbi/anthropic/models/beta/beta_content_block_param.rbi +8 -7
- data/rbi/anthropic/models/beta/beta_message.rbi +11 -3
- data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +6 -6
- data/rbi/anthropic/models/beta/beta_request_document_block.rbi +140 -0
- data/rbi/anthropic/models/beta/beta_search_result_block_param.rbi +91 -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_tool.rbi +14 -5
- data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +82 -0
- data/rbi/anthropic/models/beta/beta_tool_union.rbi +6 -5
- data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +44 -27
- data/rbi/anthropic/models/beta/message_create_params.rbi +38 -22
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +38 -22
- 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/message.rbi +11 -3
- data/rbi/anthropic/models/message_count_tokens_params.rbi +22 -2
- data/rbi/anthropic/models/message_count_tokens_tool.rbi +2 -0
- data/rbi/anthropic/models/message_create_params.rbi +22 -2
- data/rbi/anthropic/models/messages/batch_create_params.rbi +22 -2
- 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 +5 -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.rbi +12 -0
- data/rbi/anthropic/resources/beta/messages.rbi +39 -18
- data/rbi/anthropic/resources/messages.rbi +318 -3
- 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_citation_char_location.rbs +5 -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_content_block.rbs +2 -2
- data/sig/anthropic/models/beta/beta_content_block_param.rbs +9 -8
- data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +2 -2
- data/sig/anthropic/models/beta/beta_request_document_block.rbs +66 -0
- data/sig/anthropic/models/beta/beta_search_result_block_param.rbs +53 -0
- 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_tool.rbs +14 -3
- data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +1 -0
- data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +39 -0
- data/sig/anthropic/models/beta/beta_tool_union.rbs +5 -4
- data/sig/anthropic/models/beta/message_count_tokens_params.rbs +5 -4
- 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/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 +4 -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.rbs +10 -0
- data/sig/anthropic/streaming.rbs +3 -0
- metadata +44 -3
|
@@ -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::
|
|
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.
|
|
50
50
|
#
|
|
51
51
|
# @param top_k [Integer] Body param: Only sample from the top K options for each subsequent token.
|
|
52
52
|
#
|
|
@@ -62,7 +62,7 @@ module Anthropic
|
|
|
62
62
|
def create(params)
|
|
63
63
|
parsed, options = Anthropic::Beta::MessageCreateParams.dump_request(params)
|
|
64
64
|
if parsed[:stream]
|
|
65
|
-
message = "Please use `#
|
|
65
|
+
message = "Please use `#stream` for the streaming use case."
|
|
66
66
|
raise ArgumentError.new(message)
|
|
67
67
|
end
|
|
68
68
|
|
|
@@ -89,8 +89,75 @@ module Anthropic
|
|
|
89
89
|
)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
# See {Anthropic::Resources::Beta::Messages#create} for non-streaming counterpart.
|
|
93
|
+
#
|
|
94
|
+
# Some parameter documentations has been truncated, see
|
|
95
|
+
# {Anthropic::Models::Beta::MessageCreateParams} for more details.
|
|
96
|
+
#
|
|
97
|
+
# Send a structured list of input messages with text and/or image content, and the
|
|
98
|
+
# model will generate the next message in the conversation.
|
|
99
|
+
#
|
|
100
|
+
# The Messages API can be used for either single queries or stateless multi-turn
|
|
101
|
+
# conversations.
|
|
102
|
+
#
|
|
103
|
+
# Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
|
|
104
|
+
#
|
|
105
|
+
# @overload stream_raw(max_tokens:, messages:, model:, container: nil, mcp_servers: nil, 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, betas: nil, request_options: {})
|
|
106
|
+
#
|
|
107
|
+
# @param max_tokens [Integer] Body param: The maximum number of tokens to generate before stopping.
|
|
108
|
+
#
|
|
109
|
+
# @param messages [Array<Anthropic::Models::Beta::BetaMessageParam>] Body param: Input messages.
|
|
110
|
+
#
|
|
111
|
+
# @param model [Symbol, String, Anthropic::Models::Model] Body param: The model that will complete your prompt.\n\nSee [models](https://do
|
|
112
|
+
#
|
|
113
|
+
# @param container [String, nil] Body param: Container identifier for reuse across requests.
|
|
114
|
+
#
|
|
115
|
+
# @param mcp_servers [Array<Anthropic::Models::Beta::BetaRequestMCPServerURLDefinition>] Body param: MCP servers to be utilized in this request
|
|
116
|
+
#
|
|
117
|
+
# @param metadata [Anthropic::Models::Beta::BetaMetadata] Body param: An object describing metadata about the request.
|
|
118
|
+
#
|
|
119
|
+
# @param service_tier [Symbol, Anthropic::Models::Beta::MessageCreateParams::ServiceTier] Body param: Determines whether to use priority capacity (if available) or standa
|
|
120
|
+
#
|
|
121
|
+
# @param stop_sequences [Array<String>] Body param: Custom text sequences that will cause the model to stop generating.
|
|
122
|
+
#
|
|
123
|
+
# @param system_ [String, Array<Anthropic::Models::Beta::BetaTextBlockParam>] Body param: System prompt.
|
|
124
|
+
#
|
|
125
|
+
# @param temperature [Float] Body param: Amount of randomness injected into the response.
|
|
126
|
+
#
|
|
127
|
+
# @param thinking [Anthropic::Models::Beta::BetaThinkingConfigEnabled, Anthropic::Models::Beta::BetaThinkingConfigDisabled] Body param: Configuration for enabling Claude's extended thinking.
|
|
128
|
+
#
|
|
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
|
+
#
|
|
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.
|
|
132
|
+
#
|
|
133
|
+
# @param top_k [Integer] Body param: Only sample from the top K options for each subsequent token.
|
|
134
|
+
#
|
|
135
|
+
# @param top_p [Float] Body param: Use nucleus sampling.
|
|
136
|
+
#
|
|
137
|
+
# @param betas [Array<String, Symbol, Anthropic::Models::AnthropicBeta>] Header param: Optional header to specify the beta version(s) you want to use.
|
|
138
|
+
#
|
|
139
|
+
# @param request_options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil]
|
|
140
|
+
#
|
|
141
|
+
# @return [Anthropic::Internal::Stream<Anthropic::Models::Beta::BetaRawMessageStartEvent, Anthropic::Models::Beta::BetaRawMessageDeltaEvent, Anthropic::Models::Beta::BetaRawMessageStopEvent, Anthropic::Models::Beta::BetaRawContentBlockStartEvent, Anthropic::Models::Beta::BetaRawContentBlockDeltaEvent, Anthropic::Models::Beta::BetaRawContentBlockStopEvent>]
|
|
142
|
+
#
|
|
143
|
+
# @see Anthropic::Models::Beta::MessageCreateParams
|
|
144
|
+
def stream(params)
|
|
145
|
+
parsed, options = Anthropic::Models::Beta::MessageCreateParams.dump_request(params)
|
|
146
|
+
unless parsed.fetch(:stream, true)
|
|
147
|
+
message = "Please use `#create` for the non-streaming use case."
|
|
148
|
+
raise ArgumentError.new(message)
|
|
149
|
+
end
|
|
150
|
+
parsed.store(:stream, true)
|
|
151
|
+
raw_stream = @client.request(
|
|
152
|
+
method: :post,
|
|
153
|
+
path: "v1/messages?beta=true",
|
|
154
|
+
headers: {"accept" => "text/event-stream"},
|
|
155
|
+
body: parsed,
|
|
156
|
+
stream: Anthropic::Internal::Stream,
|
|
157
|
+
model: Anthropic::Beta::BetaRawMessageStreamEvent,
|
|
158
|
+
options: options
|
|
159
|
+
)
|
|
160
|
+
Anthropic::Streaming::MessageStream.new(raw_stream: raw_stream)
|
|
94
161
|
end
|
|
95
162
|
|
|
96
163
|
# See {Anthropic::Resources::Beta::Messages#create} for non-streaming counterpart.
|
|
@@ -132,7 +199,7 @@ module Anthropic
|
|
|
132
199
|
#
|
|
133
200
|
# @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
|
|
134
201
|
#
|
|
135
|
-
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::
|
|
202
|
+
# @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::BetaWebSearchTool20250305>] Body param: Definitions of tools that the model may use.
|
|
136
203
|
#
|
|
137
204
|
# @param top_k [Integer] Body param: Only sample from the top K options for each subsequent token.
|
|
138
205
|
#
|
|
@@ -192,7 +259,7 @@ module Anthropic
|
|
|
192
259
|
#
|
|
193
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
|
|
194
261
|
#
|
|
195
|
-
# @param tools [Array<Anthropic::Models::Beta::BetaTool, Anthropic::Models::Beta::
|
|
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.
|
|
196
263
|
#
|
|
197
264
|
# @param betas [Array<String, Symbol, Anthropic::Models::AnthropicBeta>] Header param: Optional header to specify the beta version(s) you want to use.
|
|
198
265
|
#
|
|
@@ -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,7 +55,7 @@ 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
|
|
|
@@ -80,8 +80,69 @@ module Anthropic
|
|
|
80
80
|
)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
# See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
|
|
84
|
+
#
|
|
85
|
+
# Some parameter documentations has been truncated, see
|
|
86
|
+
# {Anthropic::Models::MessageCreateParams} for more details.
|
|
87
|
+
#
|
|
88
|
+
# Send a structured list of input messages with text and/or image content, and the
|
|
89
|
+
# model will generate the next message in the conversation with streaming.
|
|
90
|
+
#
|
|
91
|
+
# The Messages API can be used for either single queries or stateless multi-turn
|
|
92
|
+
# conversations.
|
|
93
|
+
#
|
|
94
|
+
# Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
|
|
95
|
+
#
|
|
96
|
+
# @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: {})
|
|
97
|
+
#
|
|
98
|
+
# @param max_tokens [Integer] The maximum number of tokens to generate before stopping.
|
|
99
|
+
#
|
|
100
|
+
# @param messages [Array<Anthropic::Models::MessageParam>] Input messages.
|
|
101
|
+
#
|
|
102
|
+
# @param model [Symbol, String, Anthropic::Models::Model] The model that will complete your prompt.\n\nSee [models](https://docs.anthropic
|
|
103
|
+
#
|
|
104
|
+
# @param metadata [Anthropic::Models::Metadata] An object describing metadata about the request.
|
|
105
|
+
#
|
|
106
|
+
# @param service_tier [Symbol, Anthropic::Models::MessageCreateParams::ServiceTier] Determines whether to use priority capacity (if available) or standard capacity
|
|
107
|
+
#
|
|
108
|
+
# @param stop_sequences [Array<String>] Custom text sequences that will cause the model to stop generating.
|
|
109
|
+
#
|
|
110
|
+
# @param system_ [String, Array<Anthropic::Models::TextBlockParam>] System prompt.
|
|
111
|
+
#
|
|
112
|
+
# @param temperature [Float] Amount of randomness injected into the response.
|
|
113
|
+
#
|
|
114
|
+
# @param thinking [Anthropic::Models::ThinkingConfigEnabled, Anthropic::Models::ThinkingConfigDisabled] Configuration for enabling Claude's extended thinking.
|
|
115
|
+
#
|
|
116
|
+
# @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,
|
|
117
|
+
#
|
|
118
|
+
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
|
119
|
+
#
|
|
120
|
+
# @param top_k [Integer] Only sample from the top K options for each subsequent token.
|
|
121
|
+
#
|
|
122
|
+
# @param top_p [Float] Use nucleus sampling.
|
|
123
|
+
#
|
|
124
|
+
# @param request_options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil]
|
|
125
|
+
#
|
|
126
|
+
# @return [Anthropic::Streaming::MessageStream]
|
|
127
|
+
#
|
|
128
|
+
# @see Anthropic::Models::MessageCreateParams
|
|
129
|
+
def stream(params)
|
|
130
|
+
parsed, options = Anthropic::Models::MessageCreateParams.dump_request(params)
|
|
131
|
+
unless parsed.fetch(:stream, true)
|
|
132
|
+
message = "Please use `#create` for the non-streaming use case."
|
|
133
|
+
raise ArgumentError.new(message)
|
|
134
|
+
end
|
|
135
|
+
parsed.store(:stream, true)
|
|
136
|
+
raw_stream = @client.request(
|
|
137
|
+
method: :post,
|
|
138
|
+
path: "v1/messages",
|
|
139
|
+
headers: {"accept" => "text/event-stream"},
|
|
140
|
+
body: parsed,
|
|
141
|
+
stream: Anthropic::Internal::Stream,
|
|
142
|
+
model: Anthropic::Models::RawMessageStreamEvent,
|
|
143
|
+
options: options
|
|
144
|
+
)
|
|
145
|
+
Anthropic::Streaming::MessageStream.new(raw_stream: raw_stream)
|
|
85
146
|
end
|
|
86
147
|
|
|
87
148
|
# See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
|
|
@@ -119,7 +180,7 @@ module Anthropic
|
|
|
119
180
|
#
|
|
120
181
|
# @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
182
|
#
|
|
122
|
-
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
|
183
|
+
# @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
184
|
#
|
|
124
185
|
# @param top_k [Integer] Only sample from the top K options for each subsequent token.
|
|
125
186
|
#
|
|
@@ -171,7 +232,7 @@ module Anthropic
|
|
|
171
232
|
#
|
|
172
233
|
# @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
234
|
#
|
|
174
|
-
# @param tools [Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::WebSearchTool20250305>] Definitions of tools that the model may use.
|
|
235
|
+
# @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
236
|
#
|
|
176
237
|
# @param request_options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil]
|
|
177
238
|
#
|
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"
|
|
@@ -76,6 +77,8 @@ require_relative "anthropic/models/beta/beta_citation_page_location"
|
|
|
76
77
|
require_relative "anthropic/models/beta/beta_citation_page_location_param"
|
|
77
78
|
require_relative "anthropic/models/beta/beta_citations_config_param"
|
|
78
79
|
require_relative "anthropic/models/beta/beta_citations_delta"
|
|
80
|
+
require_relative "anthropic/models/beta/beta_citation_search_result_location"
|
|
81
|
+
require_relative "anthropic/models/beta/beta_citation_search_result_location_param"
|
|
79
82
|
require_relative "anthropic/models/beta/beta_citations_web_search_result_location"
|
|
80
83
|
require_relative "anthropic/models/beta/beta_citation_web_search_result_location_param"
|
|
81
84
|
require_relative "anthropic/models/beta/beta_code_execution_output_block"
|
|
@@ -124,6 +127,7 @@ require_relative "anthropic/models/beta/beta_redacted_thinking_block_param"
|
|
|
124
127
|
require_relative "anthropic/models/beta/beta_request_mcp_server_tool_configuration"
|
|
125
128
|
require_relative "anthropic/models/beta/beta_request_mcp_server_url_definition"
|
|
126
129
|
require_relative "anthropic/models/beta/beta_request_mcp_tool_result_block_param"
|
|
130
|
+
require_relative "anthropic/models/beta/beta_search_result_block_param"
|
|
127
131
|
require_relative "anthropic/models/beta/beta_server_tool_usage"
|
|
128
132
|
require_relative "anthropic/models/beta/beta_server_tool_use_block"
|
|
129
133
|
require_relative "anthropic/models/beta/beta_server_tool_use_block_param"
|
|
@@ -154,6 +158,7 @@ require_relative "anthropic/models/beta/beta_tool_result_block_param"
|
|
|
154
158
|
require_relative "anthropic/models/beta/beta_tool_text_editor_20241022"
|
|
155
159
|
require_relative "anthropic/models/beta/beta_tool_text_editor_20250124"
|
|
156
160
|
require_relative "anthropic/models/beta/beta_tool_text_editor_20250429"
|
|
161
|
+
require_relative "anthropic/models/beta/beta_tool_text_editor_20250728"
|
|
157
162
|
require_relative "anthropic/models/beta/beta_tool_union"
|
|
158
163
|
require_relative "anthropic/models/beta/beta_tool_use_block"
|
|
159
164
|
require_relative "anthropic/models/beta/beta_tool_use_block_param"
|
|
@@ -217,6 +222,8 @@ require_relative "anthropic/models/citation_page_location"
|
|
|
217
222
|
require_relative "anthropic/models/citation_page_location_param"
|
|
218
223
|
require_relative "anthropic/models/citations_config_param"
|
|
219
224
|
require_relative "anthropic/models/citations_delta"
|
|
225
|
+
require_relative "anthropic/models/citation_search_result_location_param"
|
|
226
|
+
require_relative "anthropic/models/citations_search_result_location"
|
|
220
227
|
require_relative "anthropic/models/citations_web_search_result_location"
|
|
221
228
|
require_relative "anthropic/models/citation_web_search_result_location_param"
|
|
222
229
|
require_relative "anthropic/models/completion"
|
|
@@ -274,6 +281,7 @@ require_relative "anthropic/models/raw_message_stop_event"
|
|
|
274
281
|
require_relative "anthropic/models/raw_message_stream_event"
|
|
275
282
|
require_relative "anthropic/models/redacted_thinking_block"
|
|
276
283
|
require_relative "anthropic/models/redacted_thinking_block_param"
|
|
284
|
+
require_relative "anthropic/models/search_result_block_param"
|
|
277
285
|
require_relative "anthropic/models/server_tool_usage"
|
|
278
286
|
require_relative "anthropic/models/server_tool_use_block"
|
|
279
287
|
require_relative "anthropic/models/server_tool_use_block_param"
|
|
@@ -299,6 +307,8 @@ require_relative "anthropic/models/tool_choice_none"
|
|
|
299
307
|
require_relative "anthropic/models/tool_choice_tool"
|
|
300
308
|
require_relative "anthropic/models/tool_result_block_param"
|
|
301
309
|
require_relative "anthropic/models/tool_text_editor_20250124"
|
|
310
|
+
require_relative "anthropic/models/tool_text_editor_20250429"
|
|
311
|
+
require_relative "anthropic/models/tool_text_editor_20250728"
|
|
302
312
|
require_relative "anthropic/models/tool_union"
|
|
303
313
|
require_relative "anthropic/models/tool_use_block"
|
|
304
314
|
require_relative "anthropic/models/tool_use_block_param"
|
|
@@ -314,6 +324,10 @@ require_relative "anthropic/models/web_search_tool_result_block_content"
|
|
|
314
324
|
require_relative "anthropic/models/web_search_tool_result_block_param"
|
|
315
325
|
require_relative "anthropic/models/web_search_tool_result_block_param_content"
|
|
316
326
|
require_relative "anthropic/models/web_search_tool_result_error"
|
|
327
|
+
require_relative "anthropic/helpers/streaming/events"
|
|
328
|
+
require_relative "anthropic/helpers/streaming/message_stream"
|
|
329
|
+
require_relative "anthropic/helpers/streaming"
|
|
330
|
+
require_relative "anthropic/streaming"
|
|
317
331
|
require_relative "anthropic/models"
|
|
318
332
|
require_relative "anthropic/resources/beta"
|
|
319
333
|
require_relative "anthropic/resources/beta/files"
|
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
|
|
@@ -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,95 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
# typed: true
|
|
4
|
+
|
|
5
|
+
module Anthropic
|
|
6
|
+
module Helpers
|
|
7
|
+
module Streaming
|
|
8
|
+
class TextEvent < Anthropic::Internal::Type::BaseModel
|
|
9
|
+
sig { returns(Symbol) }
|
|
10
|
+
attr_accessor :type
|
|
11
|
+
|
|
12
|
+
sig { returns(String) }
|
|
13
|
+
attr_accessor :text
|
|
14
|
+
|
|
15
|
+
sig { returns(String) }
|
|
16
|
+
attr_accessor :snapshot
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class CitationEvent < Anthropic::Internal::Type::BaseModel
|
|
20
|
+
sig { returns(Symbol) }
|
|
21
|
+
attr_accessor :type
|
|
22
|
+
|
|
23
|
+
sig { returns(Anthropic::CitationsDelta::Citation::Variants) }
|
|
24
|
+
attr_accessor :citation
|
|
25
|
+
|
|
26
|
+
sig { returns(T::Array[Anthropic::CitationsDelta::Citation::Variants]) }
|
|
27
|
+
attr_accessor :snapshot
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class ThinkingEvent < Anthropic::Internal::Type::BaseModel
|
|
31
|
+
sig { returns(Symbol) }
|
|
32
|
+
attr_accessor :type
|
|
33
|
+
|
|
34
|
+
sig { returns(String) }
|
|
35
|
+
attr_accessor :thinking
|
|
36
|
+
|
|
37
|
+
sig { returns(String) }
|
|
38
|
+
attr_accessor :snapshot
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class SignatureEvent < Anthropic::Internal::Type::BaseModel
|
|
42
|
+
sig { returns(Symbol) }
|
|
43
|
+
attr_accessor :type
|
|
44
|
+
|
|
45
|
+
sig { returns(String) }
|
|
46
|
+
attr_accessor :signature
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class InputJsonEvent < Anthropic::Internal::Type::BaseModel
|
|
50
|
+
sig { returns(Symbol) }
|
|
51
|
+
attr_accessor :type
|
|
52
|
+
|
|
53
|
+
sig { returns(String) }
|
|
54
|
+
attr_accessor :partial_json
|
|
55
|
+
|
|
56
|
+
sig { returns(T.untyped) }
|
|
57
|
+
attr_accessor :snapshot
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class MessageStopEvent < Anthropic::Models::RawMessageStopEvent
|
|
61
|
+
sig { returns(Anthropic::Models::Message) }
|
|
62
|
+
attr_accessor :message
|
|
63
|
+
|
|
64
|
+
sig do
|
|
65
|
+
params(message: Anthropic::Models::Message, type: Symbol).returns(
|
|
66
|
+
T.attached_class
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
def self.new(message:, type: :message_stop)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class ContentBlockStopEvent < Anthropic::Models::RawContentBlockStopEvent
|
|
74
|
+
sig { returns(Integer) }
|
|
75
|
+
attr_accessor :index
|
|
76
|
+
|
|
77
|
+
sig { returns(Symbol) }
|
|
78
|
+
attr_accessor :type
|
|
79
|
+
|
|
80
|
+
sig { returns(Anthropic::Models::ContentBlock) }
|
|
81
|
+
attr_accessor :content_block
|
|
82
|
+
|
|
83
|
+
sig do
|
|
84
|
+
params(
|
|
85
|
+
index: Integer,
|
|
86
|
+
content_block: Anthropic::Models::ContentBlock,
|
|
87
|
+
type: Symbol
|
|
88
|
+
).returns(T.attached_class)
|
|
89
|
+
end
|
|
90
|
+
def self.new(index:, content_block:, type: :content_block_stop)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Helpers
|
|
5
|
+
module Streaming
|
|
6
|
+
RawMessageEvent =
|
|
7
|
+
T.type_alias do
|
|
8
|
+
T.any(
|
|
9
|
+
Anthropic::Models::RawMessageStartEvent,
|
|
10
|
+
Anthropic::Models::RawMessageDeltaEvent,
|
|
11
|
+
Anthropic::Models::RawMessageStopEvent,
|
|
12
|
+
Anthropic::Models::RawContentBlockStartEvent,
|
|
13
|
+
Anthropic::Models::RawContentBlockDeltaEvent,
|
|
14
|
+
Anthropic::Models::RawContentBlockStopEvent
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
StreamEvent =
|
|
19
|
+
T.type_alias do
|
|
20
|
+
T.any(
|
|
21
|
+
Anthropic::Streaming::RawMessageEvent,
|
|
22
|
+
Anthropic::Streaming::TextEvent,
|
|
23
|
+
Anthropic::Streaming::CitationEvent,
|
|
24
|
+
Anthropic::Streaming::ThinkingEvent,
|
|
25
|
+
Anthropic::Streaming::SignatureEvent,
|
|
26
|
+
Anthropic::Streaming::InputJsonEvent,
|
|
27
|
+
Anthropic::Streaming::MessageStopEvent,
|
|
28
|
+
Anthropic::Streaming::ContentBlockStopEvent
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class MessageStream
|
|
33
|
+
include Anthropic::Internal::Type::BaseStream
|
|
34
|
+
|
|
35
|
+
Message =
|
|
36
|
+
type_member(:in) { { fixed: Anthropic::Streaming::RawMessageEvent } }
|
|
37
|
+
Elem =
|
|
38
|
+
type_member(:out) { { fixed: Anthropic::Streaming::StreamEvent } }
|
|
39
|
+
|
|
40
|
+
sig do
|
|
41
|
+
params(raw_stream: Anthropic::Internal::Stream[RawMessageEvent]).void
|
|
42
|
+
end
|
|
43
|
+
def initialize(raw_stream:)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
sig { void }
|
|
47
|
+
def until_done
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
sig { returns(T::Enumerator[String]) }
|
|
51
|
+
def text
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
sig { returns(Anthropic::Models::Message) }
|
|
55
|
+
def accumulated_message
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
sig { returns(String) }
|
|
59
|
+
def accumulated_text
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
sig do
|
|
63
|
+
params(
|
|
64
|
+
event: Anthropic::Streaming::RawMessageEvent,
|
|
65
|
+
current_snapshot: T.nilable(Anthropic::Models::Message)
|
|
66
|
+
).returns(Anthropic::Models::Message)
|
|
67
|
+
end
|
|
68
|
+
private def accumulate_event(event:, current_snapshot:)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -21,16 +21,26 @@ 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
|
-
params(
|
|
31
|
-
|
|
35
|
+
params(
|
|
36
|
+
request_components:
|
|
37
|
+
Anthropic::Internal::Transport::BaseClient::RequestComponents
|
|
38
|
+
).returns(
|
|
39
|
+
Anthropic::Internal::Transport::BaseClient::RequestComponents
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
private def fit_req_to_vertex_specs!(request_components)
|
|
32
43
|
end
|
|
33
|
-
private def fit_req_to_vertex_specs!(request_components) end
|
|
34
44
|
|
|
35
45
|
sig do
|
|
36
46
|
params(
|
|
@@ -51,7 +61,8 @@ module Anthropic
|
|
|
51
61
|
timeout: Anthropic::Client::DEFAULT_TIMEOUT_IN_SECONDS,
|
|
52
62
|
initial_retry_delay: Anthropic::Client::DEFAULT_INITIAL_RETRY_DELAY,
|
|
53
63
|
max_retry_delay: Anthropic::Client::DEFAULT_MAX_RETRY_DELAY
|
|
54
|
-
)
|
|
64
|
+
)
|
|
65
|
+
end
|
|
55
66
|
end
|
|
56
67
|
end
|
|
57
68
|
end
|
|
@@ -52,10 +52,17 @@ module Anthropic
|
|
|
52
52
|
url: URI::Generic,
|
|
53
53
|
status: Integer,
|
|
54
54
|
response: Net::HTTPResponse,
|
|
55
|
+
unwrap:
|
|
56
|
+
T.any(
|
|
57
|
+
Symbol,
|
|
58
|
+
Integer,
|
|
59
|
+
T::Array[T.any(Symbol, Integer)],
|
|
60
|
+
T.proc.params(arg0: T.anything).returns(T.anything)
|
|
61
|
+
),
|
|
55
62
|
stream: T::Enumerable[Message]
|
|
56
63
|
).void
|
|
57
64
|
end
|
|
58
|
-
def initialize(model:, url:, status:, response:, stream:)
|
|
65
|
+
def initialize(model:, url:, status:, response:, unwrap:, stream:)
|
|
59
66
|
end
|
|
60
67
|
|
|
61
68
|
# @api private
|