anthropic 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef2ed78af9f188f394fce182554887c8a38c68864f05796f23ccd3e57cf38d40
4
- data.tar.gz: 65495af068a5f373e6d77dbc0085846c75e1a77dab2139fe0a06bbc62678e3ea
3
+ metadata.gz: 9e97ad4ba3bb5f72993b149b48b0519c74f2ec2ec81d831635fb4f8fd58e0752
4
+ data.tar.gz: c9680b4b3dbc60dce535c7901a496f4c250db488786c8686b31044a59eddaab5
5
5
  SHA512:
6
- metadata.gz: e508affc831d8136633d74ca73026fb5936d52bf1ffbb82541a8ead24c5e4dec640faef5d3747986d242bde4296efc6e5ceac6688c091641da13b74a27371819
7
- data.tar.gz: 4fd4fd39c63c902c1a54d71fe884329eaca8d7d5a385beb6fdf3c2e3fabeb8cbf4f67a41014d2df43eef15707ef474ee892c7f954f46ca34f33c625577038b6f
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- anthropic (0.3.0)
4
+ anthropic (0.3.1)
5
5
  event_stream_parser (>= 0.3.0, < 2.0.0)
6
6
  faraday (>= 1)
7
7
  faraday-multipart (>= 1)
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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Anthropic
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.3.1".freeze
3
3
  end
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.0
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-06-10 00:00:00.000000000 Z
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