anthropic 0.3.2 → 0.4.1
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 +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +92 -6
- data/lib/anthropic/client.rb +49 -15
- data/lib/anthropic/compatibility.rb +1 -0
- data/lib/anthropic/http.rb +13 -12
- data/lib/anthropic/http_headers.rb +1 -1
- data/lib/anthropic/messages/batches.rb +112 -0
- data/lib/anthropic/messages/client.rb +13 -0
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +9 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9def8893a5bf773385f2acf8cab126f65fcaf8c14c0aa30809ce20150221da8
|
4
|
+
data.tar.gz: eb2fd9b075ff306205857c4ecd926c9a1d0e82d20a5c91c1d03711c7947090f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a4c4015f3b2416adbe94b7a2170eb61dcecc7e87f71e6f26f7006006bd15801c9a28197af6892cf0f0393f8e6c9901a625419ebf9d5bee425c2de4ef514bc9d
|
7
|
+
data.tar.gz: 2e2ab2e3e71affe935a42e54e8e38eea23ec31a37495d8c1e9004aff96fd24163e802efe64de7b32e3e4304743525788a0a0337c9a90d0f79e478471c330f2c4
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.4.1] - 2025-04-10
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Add deprecation warning - this gem will be renamed to ruby-anthropic in the next release, to make way for the new official Anthropic SDK (currently at https://github.com/anthropics/anthropic-sdk-ruby).
|
13
|
+
- The gem name 'anthropic' will soon refer to the official Anthropic SDK. You'll need to update your Gemfile to 'ruby-anthropic' if you want to keep using this gem.
|
14
|
+
|
15
|
+
## [0.4.0] - 2025-03-25
|
16
|
+
|
17
|
+
### Added
|
18
|
+
|
19
|
+
- Add Batches API! Thanks to [@ignacio-chiazzo](https://github.com/ignacio-chiazzo) for previous work on this.
|
20
|
+
- Thanks to [@seuros](https://github.com/seuros) for helpful README notes on Batch usage.
|
21
|
+
|
8
22
|
## [0.3.2] - 2024-10-09
|
9
23
|
|
10
24
|
### Fixed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
[](https://github.com/alexrudall/anthropic/blob/main/LICENSE.txt)
|
5
5
|
[](https://circleci.com/gh/alexrudall/anthropic)
|
6
6
|
|
7
|
+
> [!IMPORTANT]
|
8
|
+
> This gem has been renamed from `anthropic` to `ruby-anthropic`, to make way for the new [official Anthropic Ruby SDK](https://github.com/anthropics/anthropic-sdk-ruby) 🎉
|
9
|
+
> If you wish to keep using this gem, you just need to update your Gemfile from `anthropic` to `ruby-anthropic` and version `0.4.2` or greater. No other changes are needed and it will continue to work as normal.
|
10
|
+
|
7
11
|
Use the [Anthropic API](https://docs.anthropic.com/claude/reference/getting-started-with-the-api) with Ruby! 🤖🌌
|
8
12
|
|
9
13
|
You can get access to the API [here](https://docs.anthropic.com/claude/docs/getting-access-to-claude).
|
@@ -43,7 +47,10 @@ require "anthropic"
|
|
43
47
|
For a quick test you can pass your token directly to a new client:
|
44
48
|
|
45
49
|
```ruby
|
46
|
-
client = Anthropic::Client.new(
|
50
|
+
client = Anthropic::Client.new(
|
51
|
+
access_token: "access_token_goes_here",
|
52
|
+
log_errors: true # Highly recommended in development, so you can see what errors Anthropic is returning. Not recommended in production because it could leak private data to your logs.
|
53
|
+
)
|
47
54
|
```
|
48
55
|
|
49
56
|
### With Config
|
@@ -53,10 +60,11 @@ For a more robust setup, you can configure the gem with your API keys, for examp
|
|
53
60
|
```ruby
|
54
61
|
Anthropic.configure do |config|
|
55
62
|
# With dotenv
|
56
|
-
config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
|
63
|
+
config.access_token = ENV.fetch("ANTHROPIC_API_KEY"),
|
57
64
|
# OR
|
58
65
|
# With Rails credentials
|
59
|
-
config.access_token = Rails.application.credentials.dig(:anthropic, :api_key)
|
66
|
+
config.access_token = Rails.application.credentials.dig(:anthropic, :api_key),
|
67
|
+
config.log_errors = true # Highly recommended in development, so you can see what errors Anthropic is returning. Not recommended in production because it could leak private data to your logs.
|
60
68
|
end
|
61
69
|
```
|
62
70
|
|
@@ -75,6 +83,7 @@ The default timeout for any request using this library is 120 seconds. You can c
|
|
75
83
|
```ruby
|
76
84
|
client = Anthropic::Client.new(
|
77
85
|
access_token: "access_token_goes_here",
|
86
|
+
log_errors: true, # Optional
|
78
87
|
anthropic_version: "2023-01-01", # Optional
|
79
88
|
request_timeout: 240 # Optional
|
80
89
|
)
|
@@ -90,6 +99,16 @@ Anthropic.configure do |config|
|
|
90
99
|
end
|
91
100
|
```
|
92
101
|
|
102
|
+
#### Logging
|
103
|
+
|
104
|
+
##### Errors
|
105
|
+
By default, the `anthropic` gem does not log any `Faraday::Error`s encountered while executing a network request to avoid leaking data (e.g. 400s, 500s, SSL errors and more - see [here](https://www.rubydoc.info/github/lostisland/faraday/Faraday/Error) for a complete list of subclasses of `Faraday::Error` and what can cause them).
|
106
|
+
|
107
|
+
If you would like to enable this functionality, you can set `log_errors` to `true` when configuring the client:
|
108
|
+
```ruby
|
109
|
+
client = Anthropic::Client.new(log_errors: true)
|
110
|
+
```
|
111
|
+
|
93
112
|
### Models
|
94
113
|
|
95
114
|
Available Models:
|
@@ -133,7 +152,74 @@ response = client.messages(
|
|
133
152
|
# => }
|
134
153
|
```
|
135
154
|
|
136
|
-
|
155
|
+
### Batches
|
156
|
+
The Batches API can be used to process multiple Messages API requests at once. Once a Message Batch is created, it begins processing a soon as possible.
|
157
|
+
|
158
|
+
Batches can contain up to 100,000 requests or 256 MB in total size, whichever limit is reached first.
|
159
|
+
|
160
|
+
Create a batch of message requests:
|
161
|
+
```ruby
|
162
|
+
response = client.messages.batches.create(
|
163
|
+
parameters: {
|
164
|
+
requests: [
|
165
|
+
{
|
166
|
+
custom_id: "my-first-request",
|
167
|
+
params: {
|
168
|
+
model: "claude-3-haiku-20240307",
|
169
|
+
max_tokens: 1024,
|
170
|
+
messages: [
|
171
|
+
{ role: "user", content: "Hello, world" }
|
172
|
+
]
|
173
|
+
}
|
174
|
+
},
|
175
|
+
{
|
176
|
+
custom_id: "my-second-request",
|
177
|
+
params: {
|
178
|
+
model: "claude-3-haiku-20240307",
|
179
|
+
max_tokens: 1024,
|
180
|
+
messages: [
|
181
|
+
{ role: "user", content: "Hi again, friend" }
|
182
|
+
]
|
183
|
+
}
|
184
|
+
}
|
185
|
+
]
|
186
|
+
}
|
187
|
+
)
|
188
|
+
batch_id = response["id"]
|
189
|
+
```
|
190
|
+
|
191
|
+
You can retrieve information about a specific batch:
|
192
|
+
```ruby
|
193
|
+
batch = client.messages.batches.get(id: batch_id)
|
194
|
+
```
|
195
|
+
|
196
|
+
To cancel a batch that is in progress:
|
197
|
+
```ruby
|
198
|
+
client.messages.batches.cancel(id: batch_id)
|
199
|
+
```
|
200
|
+
|
201
|
+
List all batches:
|
202
|
+
```ruby
|
203
|
+
client.messages.batches.list
|
204
|
+
```
|
205
|
+
|
206
|
+
#### Notes (as of 31 March 2025)
|
207
|
+
|
208
|
+
- If individual batch items have errors, you will not be billed for those specific items.
|
209
|
+
- Batches will be listed in the account indefinitely.
|
210
|
+
- Results are fetchable only within 29 days after batch creation.
|
211
|
+
- When you cancel a batch, any unprocessed items will not be billed.
|
212
|
+
- Batches in other workspaces are not accessible with API keys from a different workspace.
|
213
|
+
- If a batch item takes more than 24 hours to process, it will expire and not be billed.
|
214
|
+
|
215
|
+
Once processing ends, you can fetch the results:
|
216
|
+
```ruby
|
217
|
+
results = client.messages.batches.results(id: batch_id)
|
218
|
+
```
|
219
|
+
|
220
|
+
Results are returned as a .jsonl file, with each line containing the result of a single request. Results may be in any order - use the custom_id field to match results to requests.
|
221
|
+
|
222
|
+
### Vision
|
137
223
|
|
138
224
|
Claude 3 family of models comes with vision capabilities that allow Claude to understand and analyze images.
|
139
225
|
|
@@ -179,14 +265,14 @@ response = client.messages(
|
|
179
265
|
```
|
180
266
|
|
181
267
|
|
182
|
-
|
268
|
+
### Additional parameters
|
183
269
|
|
184
270
|
You can add other parameters to the parameters hash, like `temperature` and even `top_k` or `top_p`. They will just be passed to the Anthropic server. You
|
185
271
|
can read more about the supported parameters [here](https://docs.anthropic.com/claude/reference/messages_post).
|
186
272
|
|
187
273
|
There are two special parameters, though, to do with... streaming. Keep reading to find out more.
|
188
274
|
|
189
|
-
|
275
|
+
### JSON
|
190
276
|
|
191
277
|
If you want your output to be json, it is recommended to provide an additional message like this:
|
192
278
|
|
data/lib/anthropic/client.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative "messages/batches"
|
2
|
+
require_relative "messages/client"
|
3
|
+
|
1
4
|
module Anthropic
|
2
5
|
class Client
|
3
6
|
include Anthropic::HTTP
|
@@ -6,10 +9,12 @@ module Anthropic
|
|
6
9
|
access_token
|
7
10
|
anthropic_version
|
8
11
|
api_version
|
12
|
+
log_errors
|
9
13
|
uri_base
|
10
14
|
request_timeout
|
11
15
|
extra_headers
|
12
16
|
].freeze
|
17
|
+
attr_reader(*CONFIG_KEYS)
|
13
18
|
|
14
19
|
def initialize(config = {}, &faraday_middleware)
|
15
20
|
CONFIG_KEYS.each do |key|
|
@@ -21,6 +26,8 @@ module Anthropic
|
|
21
26
|
)
|
22
27
|
end
|
23
28
|
@faraday_middleware = faraday_middleware
|
29
|
+
log "[WARNING] Gem `anthropic` was renamed to `ruby-anthropic`.
|
30
|
+
Please update your Gemfile to use `ruby-anthropic` version 0.4.2 or later."
|
24
31
|
end
|
25
32
|
|
26
33
|
# @deprecated (but still works while Anthropic API responds to it)
|
@@ -30,7 +37,10 @@ module Anthropic
|
|
30
37
|
end
|
31
38
|
|
32
39
|
# Anthropic API Parameters as of 2024-05-07:
|
33
|
-
#
|
40
|
+
# @see https://docs.anthropic.com/claude/reference/messages_post
|
41
|
+
#
|
42
|
+
# When called without parameters, returns a Messages::Batches instance for batch operations.
|
43
|
+
# When called with parameters, creates a single message.
|
34
44
|
#
|
35
45
|
# @param [Hash] parameters
|
36
46
|
# @option parameters [Array] :messages - Required. An array of messages to send to the API. Each
|
@@ -51,20 +61,44 @@ module Anthropic
|
|
51
61
|
# arguments: the first will be the text accrued so far, and the second will be the delta
|
52
62
|
# just received in the current chunk.
|
53
63
|
#
|
54
|
-
# @returns [Hash]
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
# }
|
66
|
-
|
67
|
-
|
64
|
+
# @returns [Hash, Messages::Client] Returns a Hash response from the API when creating a message
|
65
|
+
# with parameters, or a Messages::Client instance when called without parameters
|
66
|
+
# @example Creating a message:
|
67
|
+
# {
|
68
|
+
# "id" => "msg_013xVudG9xjSvLGwPKMeVXzG",
|
69
|
+
# "type" => "message",
|
70
|
+
# "role" => "assistant",
|
71
|
+
# "content" => [{"type" => "text", "text" => "The sky has no distinct"}],
|
72
|
+
# "model" => "claude-2.1",
|
73
|
+
# "stop_reason" => "max_tokens",
|
74
|
+
# "stop_sequence" => nil,
|
75
|
+
# "usage" => {"input_tokens" => 15, "output_tokens" => 5}
|
76
|
+
# }
|
77
|
+
# @example Accessing batches:
|
78
|
+
# client.messages.batches.create(requests: [...])
|
79
|
+
# client.messages.batches.get(id: "batch_123")
|
80
|
+
def messages(**args)
|
81
|
+
return @messages ||= Messages::Client.new(self) unless args && args[:parameters]
|
82
|
+
|
83
|
+
json_post(path: "/messages", parameters: args[:parameters])
|
84
|
+
end
|
85
|
+
|
86
|
+
# Adds Anthropic beta features to API requests. Can be used in two ways:
|
87
|
+
#
|
88
|
+
# 1. Multiple betas in one call with comma-separated string:
|
89
|
+
# client.beta("feature1,feature2").messages
|
90
|
+
#
|
91
|
+
# 2. Chaining multiple beta calls:
|
92
|
+
# client.beta("feature1").beta("feature2").messages
|
93
|
+
#
|
94
|
+
# @param version [String] The beta version(s) to enable
|
95
|
+
# @return [Client] A new client instance with the beta header(s)
|
96
|
+
def beta(version)
|
97
|
+
dup.tap do |client|
|
98
|
+
existing_beta = client.extra_headers["anthropic-beta"]
|
99
|
+
combined_beta = [existing_beta, version].compact.join(",")
|
100
|
+
client.add_headers("anthropic-beta" => combined_beta)
|
101
|
+
end
|
68
102
|
end
|
69
103
|
|
70
104
|
private
|
data/lib/anthropic/http.rb
CHANGED
@@ -7,19 +7,19 @@ module Anthropic
|
|
7
7
|
module HTTP
|
8
8
|
include HTTPHeaders
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
to_json(conn.get(uri(path: path)) do |req|
|
10
|
+
def get(path:, parameters: nil)
|
11
|
+
response = conn.get(uri(path: path), parameters) do |req|
|
13
12
|
req.headers = headers
|
14
|
-
end
|
13
|
+
end
|
14
|
+
response&.body
|
15
15
|
end
|
16
16
|
|
17
|
-
# This is currently the workhorse for all API calls.
|
18
17
|
# rubocop:disable Metrics/MethodLength
|
19
|
-
|
18
|
+
# rubocop:disable Metrics/AbcSize
|
19
|
+
def json_post(path:, parameters: {})
|
20
20
|
str_resp = {}
|
21
21
|
response = conn.post(uri(path: path)) do |req|
|
22
|
-
if parameters[:stream].is_a?(Proc)
|
22
|
+
if parameters.respond_to?(:key?) && parameters[:stream].is_a?(Proc)
|
23
23
|
req.options.on_data = to_json_stream(user_proc: parameters[:stream], response: str_resp,
|
24
24
|
preprocess: parameters[:preprocess_stream])
|
25
25
|
parameters[:stream] = true # Necessary to tell Anthropic to stream.
|
@@ -33,8 +33,9 @@ module Anthropic
|
|
33
33
|
str_resp.empty? ? response.body : str_resp
|
34
34
|
end
|
35
35
|
# rubocop:enable Metrics/MethodLength
|
36
|
+
# rubocop:enable Metrics/AbcSize
|
36
37
|
|
37
|
-
# Unused
|
38
|
+
# Unused - leave in until v1 since someone might be using it.
|
38
39
|
def multipart_post(path:, parameters: nil)
|
39
40
|
to_json(conn(multipart: true).post(uri(path: path)) do |req|
|
40
41
|
req.headers = headers.merge({ "Content-Type" => "multipart/form-data" })
|
@@ -42,7 +43,7 @@ module Anthropic
|
|
42
43
|
end&.body)
|
43
44
|
end
|
44
45
|
|
45
|
-
# Unused
|
46
|
+
# Unused - leave in until v1 since someone might be using it.
|
46
47
|
def delete(path:)
|
47
48
|
to_json(conn.delete(uri(path: path)) do |req|
|
48
49
|
req.headers = headers
|
@@ -51,7 +52,7 @@ module Anthropic
|
|
51
52
|
|
52
53
|
private
|
53
54
|
|
54
|
-
# Used only
|
55
|
+
# Used only in unused methods - leave in until v1 since someone might be using it.
|
55
56
|
def to_json(string)
|
56
57
|
return unless string
|
57
58
|
|
@@ -63,7 +64,7 @@ module Anthropic
|
|
63
64
|
|
64
65
|
# Given a proc, returns an outer proc that can be used to iterate over a JSON stream of chunks.
|
65
66
|
# For each chunk, the inner user_proc is called giving it the JSON object. The JSON object could
|
66
|
-
# be a data object or an error object as described in the
|
67
|
+
# be a data object or an error object as described in the Anthropic API documentation.
|
67
68
|
#
|
68
69
|
# @param user_proc [Proc] The inner proc to call for each JSON object in the chunk.
|
69
70
|
# @return [Proc] An outer proc that iterates over a raw stream, converting it to JSON.
|
@@ -147,7 +148,7 @@ module Anthropic
|
|
147
148
|
def log(error)
|
148
149
|
logger = Logger.new($stdout)
|
149
150
|
logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
150
|
-
"\033[31mAnthropic
|
151
|
+
"\033[31mAnthropic Error (spotted in anthropic #{VERSION}): #{msg}\n\033[0m"
|
151
152
|
end
|
152
153
|
logger.error(error)
|
153
154
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Anthropic
|
2
|
+
module Messages
|
3
|
+
class Batches
|
4
|
+
BETA_VERSION = "message-batches-2024-09-24".freeze
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client.beta(BETA_VERSION)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Anthropic API Parameters as of 2024-10-09:
|
11
|
+
# @see https://docs.anthropic.com/en/api/creating-message-batches
|
12
|
+
#
|
13
|
+
# @param [Array] :parameters - List of requests for prompt completion.
|
14
|
+
# Each is an individual request to create a Message.
|
15
|
+
# Parameters are an array of hashes, each with the following keys:
|
16
|
+
# - :custom_id (required): Developer-provided ID created for each request in a Message Batch.
|
17
|
+
# Useful for matching results to requests, as results may be given out of request order.
|
18
|
+
# Must be unique for each request within the Message Batch.
|
19
|
+
# - :params (required): Messages API creation parameters for the individual request.
|
20
|
+
# See the Messages API reference for full documentation on available parameters.
|
21
|
+
#
|
22
|
+
# @returns [Hash] the response from the API (after the streaming is done, if streaming)
|
23
|
+
# @example:
|
24
|
+
#
|
25
|
+
# > messages.batches.create(parameters: [message1, message2])
|
26
|
+
# {
|
27
|
+
# "id"=>"msgbatch_01668jySCZeCpMLsxFcroNnN",
|
28
|
+
# "type"=>"message_batch",
|
29
|
+
# "processing_status"=>"in_progress",
|
30
|
+
# "request_counts"=>{
|
31
|
+
# "processing"=>2,
|
32
|
+
# "succeeded"=>0,
|
33
|
+
# "errored"=>0,
|
34
|
+
# "canceled"=>0,
|
35
|
+
# "expired"=>0
|
36
|
+
# },
|
37
|
+
# "ended_at"=>nil,
|
38
|
+
# "created_at"=>"2024-10-09T20:18:11.480471+00:00",
|
39
|
+
# "expires_at"=>"2024-10-10T20:18:11.480471+00:00",
|
40
|
+
# "cancel_initiated_at"=>nil,
|
41
|
+
# "results_url"=>nil
|
42
|
+
# }
|
43
|
+
def create(parameters: {})
|
44
|
+
@client.json_post(
|
45
|
+
path: "/messages/batches",
|
46
|
+
parameters: parameters
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Anthropic API Parameters as of 2024-10-09:
|
51
|
+
# @see https://docs.anthropic.com/en/api/creating-message-batches
|
52
|
+
#
|
53
|
+
# @param [String] :id - ID of the Message Batch.
|
54
|
+
#
|
55
|
+
# @returns [Hash] the same response shape as #create method.
|
56
|
+
def get(id:)
|
57
|
+
@client.get(path: "/messages/batches/#{id}")
|
58
|
+
end
|
59
|
+
|
60
|
+
# Anthropic API Parameters as of 2024-10-09:
|
61
|
+
# @see https://docs.anthropic.com/en/api/creating-message-batches
|
62
|
+
#
|
63
|
+
# @param [String] :id - ID of the Message Batch.
|
64
|
+
#
|
65
|
+
# Returns the results of a Message Batch as a .jsonl file.
|
66
|
+
# Each line in the file is a JSON object containing the result of a
|
67
|
+
# single request in the Message Batch.
|
68
|
+
# Results are not guaranteed to be in the same order as requests.
|
69
|
+
# Use the custom_id field to match results to requests.
|
70
|
+
def results(id:)
|
71
|
+
@client.get(path: "/messages/batches/#{id}/results")
|
72
|
+
end
|
73
|
+
|
74
|
+
# Anthropic API Parameters as of 2024-10-09:
|
75
|
+
# @see https://docs.anthropic.com/en/api/listing-message-batches
|
76
|
+
#
|
77
|
+
# List all Message Batches within a Workspace. Most recently created batches returned first.
|
78
|
+
# @param [String] :before_id - ID of the object to use as a cursor for pagination.
|
79
|
+
# When provided, returns the page of results immediately before this object.
|
80
|
+
#
|
81
|
+
# @param [String] :after_id - ID of the object to use as a cursor for pagination.
|
82
|
+
# When provided, returns the page of results immediately after this object.
|
83
|
+
#
|
84
|
+
# @param [Integer] :limit - Number of items to return per page.
|
85
|
+
# Defaults to 20. Ranges from 1 to 100.
|
86
|
+
#
|
87
|
+
# @returns [Hash] the response from the API
|
88
|
+
def list(parameters: {})
|
89
|
+
@client.get(path: "/messages/batches", parameters: parameters)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Anthropic API Parameters as of 2024-10-09:
|
93
|
+
# @see https://docs.anthropic.com/en/api/creating-message-batches
|
94
|
+
#
|
95
|
+
# @param [String] :id - ID of the Message Batch.
|
96
|
+
#
|
97
|
+
# @returns [Hash] the response from the API
|
98
|
+
#
|
99
|
+
# Cancel a Message Batch.
|
100
|
+
# Batches may be canceled any time before processing ends. Once cancellation is initiated,
|
101
|
+
# the batch enters a canceling state, at which time the system may complete any in-progress,
|
102
|
+
# non-interruptible requests before finalizing cancellation.
|
103
|
+
#
|
104
|
+
# The number of canceled requests is specified in request_counts.
|
105
|
+
# To determine which requests were canceled, check the individual results within the batch.
|
106
|
+
# Note that cancellation may not cancel any requests if they were non-interruptible.
|
107
|
+
def cancel(id:)
|
108
|
+
@client.json_post(path: "/messages/batches/#{id}/cancel")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/lib/anthropic/version.rb
CHANGED
data/lib/anthropic.rb
CHANGED
@@ -17,7 +17,7 @@ module Anthropic
|
|
17
17
|
|
18
18
|
logger = Logger.new($stdout)
|
19
19
|
logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
20
|
-
"\033[31mAnthropic HTTP Error (spotted in
|
20
|
+
"\033[31mAnthropic HTTP Error (spotted in anthropic #{VERSION}): #{msg}\n\033[0m"
|
21
21
|
end
|
22
22
|
logger.error(e.response[:body])
|
23
23
|
|
@@ -27,11 +27,16 @@ module Anthropic
|
|
27
27
|
|
28
28
|
class Configuration
|
29
29
|
attr_writer :access_token
|
30
|
-
attr_accessor :anthropic_version,
|
31
|
-
:
|
30
|
+
attr_accessor :anthropic_version,
|
31
|
+
:api_version,
|
32
|
+
:extra_headers,
|
33
|
+
:log_errors,
|
34
|
+
:request_timeout,
|
35
|
+
:uri_base
|
32
36
|
|
33
37
|
DEFAULT_API_VERSION = "v1".freeze
|
34
38
|
DEFAULT_ANTHROPIC_VERSION = "2023-06-01".freeze
|
39
|
+
DEFAULT_LOG_ERRORS = false
|
35
40
|
DEFAULT_URI_BASE = "https://api.anthropic.com/".freeze
|
36
41
|
DEFAULT_REQUEST_TIMEOUT = 120
|
37
42
|
|
@@ -39,6 +44,7 @@ module Anthropic
|
|
39
44
|
@access_token = nil
|
40
45
|
@api_version = DEFAULT_API_VERSION
|
41
46
|
@anthropic_version = DEFAULT_ANTHROPIC_VERSION
|
47
|
+
@log_errors = DEFAULT_LOG_ERRORS
|
42
48
|
@uri_base = DEFAULT_URI_BASE
|
43
49
|
@request_timeout = DEFAULT_REQUEST_TIMEOUT
|
44
50
|
@extra_headers = {}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anthropic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|
@@ -88,6 +88,8 @@ files:
|
|
88
88
|
- lib/anthropic/compatibility.rb
|
89
89
|
- lib/anthropic/http.rb
|
90
90
|
- lib/anthropic/http_headers.rb
|
91
|
+
- lib/anthropic/messages/batches.rb
|
92
|
+
- lib/anthropic/messages/client.rb
|
91
93
|
- lib/anthropic/version.rb
|
92
94
|
- lib/ruby/anthropic.rb
|
93
95
|
- pull_request_template.md
|