anthropic 0.3.0 → 0.3.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/.rubocop.yml +5 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +46 -0
- data/lib/anthropic/http.rb +2 -2
- data/lib/anthropic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e97ad4ba3bb5f72993b149b48b0519c74f2ec2ec81d831635fb4f8fd58e0752
|
4
|
+
data.tar.gz: c9680b4b3dbc60dce535c7901a496f4c250db488786c8686b31044a59eddaab5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba13081aae415c8fe3f6a0d18a11b6ebf8922543d46fd4ee4124bb0bf1d7890f669f89bbb50f08522c199c15fb36a3b604d928ef99d82bf0a929d00db021752
|
7
|
+
data.tar.gz: 517a53e9dd57e9f56c71f7a13cd769975acea95cc137b79e8ee4062855ba243e0473ddfb8c81609a17da8099e5a6966bb5dfc2ceed0760ecdc6ac5e37c1ec3df
|
data/.rubocop.yml
CHANGED
@@ -4,7 +4,6 @@ AllCops:
|
|
4
4
|
SuggestExtensions: false
|
5
5
|
|
6
6
|
Style/Documentation:
|
7
|
-
# Skips checking to make sure top level modules / classes have a comment.
|
8
7
|
Enabled: false
|
9
8
|
|
10
9
|
Layout/LineLength:
|
@@ -24,3 +23,8 @@ Style/StringLiterals:
|
|
24
23
|
|
25
24
|
Style/FrozenStringLiteralComment:
|
26
25
|
Enabled: false
|
26
|
+
|
27
|
+
# Disable Security/MarshalLoad rule only for spec files
|
28
|
+
Security/MarshalLoad:
|
29
|
+
Exclude:
|
30
|
+
- "spec/**/*"
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ 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.3.1] - 2024-10-09
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Fix for Tool streaming.
|
13
|
+
|
8
14
|
## [0.3.0] - 2024-06-10
|
9
15
|
|
10
16
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -133,6 +133,52 @@ response = client.messages(
|
|
133
133
|
# => }
|
134
134
|
```
|
135
135
|
|
136
|
+
#### Vision
|
137
|
+
|
138
|
+
Claude 3 family of models comes with vision capabilities that allow Claude to understand and analyze images.
|
139
|
+
|
140
|
+
Transform an image to base64 and send to the API.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
require 'base64'
|
144
|
+
|
145
|
+
image = File.open(FILE_PATH, 'rb') { |file| file.read }
|
146
|
+
|
147
|
+
imgbase64 = Base64.strict_encode64(image)
|
148
|
+
|
149
|
+
response = client.messages(
|
150
|
+
parameters: {
|
151
|
+
model: "claude-3-haiku-20240307", # claude-3-opus-20240229, claude-3-sonnet-20240229
|
152
|
+
system: "Respond only in Spanish.",
|
153
|
+
messages: [
|
154
|
+
{"role": "user", "content": [
|
155
|
+
{
|
156
|
+
"type":"image","source":
|
157
|
+
{"type":"base64","media_type":"image/png", imgbase64 }
|
158
|
+
},
|
159
|
+
{"type":"text","text":"What is this"}
|
160
|
+
]
|
161
|
+
}
|
162
|
+
],
|
163
|
+
max_tokens: 1000
|
164
|
+
}
|
165
|
+
)
|
166
|
+
|
167
|
+
# => {
|
168
|
+
# => "id" => "msg_0123MiRVCgSG2PaQZwCGbgmV",
|
169
|
+
# => "type" => "message",
|
170
|
+
# => "role" => "assistant",
|
171
|
+
# => "content" => [{"type"=>"text", "text"=>"This
|
172
|
+
# => image depicts a person, presumably a student or young adult, holding a tablet
|
173
|
+
# => device. "}],
|
174
|
+
# => "model" => "claude-3-haiku-20240307",
|
175
|
+
# => "stop_reason" => "end_turn",
|
176
|
+
# => "stop_sequence" => nil,
|
177
|
+
# => "usage" => {"input_tokens"=>17, "output_tokens"=>32}
|
178
|
+
# => }
|
179
|
+
```
|
180
|
+
|
181
|
+
|
136
182
|
#### Additional parameters
|
137
183
|
|
138
184
|
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
|
data/lib/anthropic/http.rb
CHANGED
@@ -99,7 +99,7 @@ module Anthropic
|
|
99
99
|
response.merge!(parsed_data["delta"])
|
100
100
|
when "content_block_delta"
|
101
101
|
delta = parsed_data["delta"]["text"]
|
102
|
-
response["content"][0]["text"].concat(delta)
|
102
|
+
response["content"][0]["text"].concat(delta) if delta
|
103
103
|
block.yield delta
|
104
104
|
end
|
105
105
|
end
|
@@ -107,7 +107,7 @@ module Anthropic
|
|
107
107
|
|
108
108
|
# Decides whether to preprocess JSON or text and calls the appropriate method.
|
109
109
|
def preprocess(directive, stack, delta, user_proc)
|
110
|
-
stack.concat(delta)
|
110
|
+
stack.concat(delta) if delta # Alters the stack.
|
111
111
|
case directive
|
112
112
|
when :json
|
113
113
|
preprocess_json(stack, delta, user_proc)
|
data/lib/anthropic/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|