anthropic 0.1.0 โ†’ 0.2.0

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: 7bf4e9a547533edb57fcaee7dd07c8c1a5c7d3f5291b539541b9b9b8c3b5e614
4
- data.tar.gz: e62081a581aa15d9b8dbd335fb6b989671eb733629b64992c847584e83100c4e
3
+ metadata.gz: 5591b52e376e9a5915a3011d9919d188aaa441fa65f6a8d665b160c5529b0564
4
+ data.tar.gz: e251bf3dd61569807e722f6fe116498fd6801e07fc2333c2f2f40c03e61b5b9f
5
5
  SHA512:
6
- metadata.gz: dc148818d355a80050ae35c9b7a60d48dfa713826b9607d9add0ceb70b88da4b19f7b650dae1b5714ea41003fcec94cd4bc2fd226f999c3e4c3562d681a8100a
7
- data.tar.gz: 683dedfd00584546691bde56a569f2a043a0ba8b9806450e5baabcdbc0c0ff28960778c9cda600bea5b13a8024b01337e1f271f363508dd657424ad6da3b3fbd
6
+ metadata.gz: 6beac221f3595b6599e37175190a59fc20681aa679d7746f060447850aab0b4ca7362ef5ce99a458a9ce1a5f6acfc5a6491ca5bdb7147efadf14cca068576d08
7
+ data.tar.gz: 39189b30389c23c56956b32135587513f3ae7f2927e323262333c82392b5c24239c3a94486a68b2bd569856fe34334a19eb8a3ad7a0f0d99ef9bd5ec16283580
data/CHANGELOG.md CHANGED
@@ -5,14 +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.0.0] - 2023-07-12
8
+ ## [0.2.0] - 2024-04-25
9
9
 
10
10
  ### Added
11
11
 
12
- - Initialise repository.
12
+ - Add new Messages endpoint - thanks [@deepakmahakale](https://github.com/deepakmahakale) for the PR, [@obie](https://github.com/obie) for the first pass, and many others for requesting and contributions!
13
13
 
14
14
  ## [0.1.0] - 2023-07-18
15
15
 
16
16
  ### Changed
17
17
 
18
18
  - Got the gem working with the API. MVP
19
+
20
+ ## [0.0.0] - 2023-07-12
21
+
22
+ ### Added
23
+
24
+ - Initialise repository.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- anthropic (0.1.0)
4
+ anthropic (0.2.0)
5
5
  faraday (>= 1)
6
6
  faraday-multipart (>= 1)
7
7
 
data/README.md CHANGED
@@ -1,18 +1,16 @@
1
- # Anthropic (WIP)
1
+ # Anthropic
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/anthropic.svg)](https://badge.fury.io/rb/anthropic)
4
4
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexrudall/anthropic/blob/main/LICENSE.txt)
5
5
  [![CircleCI Build Status](https://circleci.com/gh/alexrudall/anthropic.svg?style=shield)](https://circleci.com/gh/alexrudall/anthropic)
6
6
 
7
- Use the [Anthropic API](https://docs.anthropic.com/claude/reference/getting-started-with-the-api) with Ruby! ๐ŸŒŒโค๏ธ
7
+ Use the [Anthropic API](https://docs.anthropic.com/claude/reference/getting-started-with-the-api) with Ruby! ๐Ÿค–๐ŸŒŒ
8
8
 
9
9
  You can apply for access to the API [here](https://docs.anthropic.com/claude/docs/getting-access-to-claude).
10
10
 
11
- [Ruby AI Builders Discord](https://discord.gg/k4Uc224xVD)
11
+ ๐Ÿšข Need someone to ship critical Rails features for you, fast? I'm taking on a few new clients at an experimental crazy low price, check it out: [railsai.com](https://railsai.com?utm_source=anthropic&utm_medium=readme&utm_id=26072023)
12
12
 
13
- [Rails AI Guides](https://railsai.com)
14
-
15
- Follow me on [Twitter](https://twitter.com/alexrudall) for more Ruby / AI content!
13
+ [๐ŸŽฎ Ruby AI Builders Discord](https://discord.gg/k4Uc224xVD) | [๐Ÿฆ Twitter](https://twitter.com/alexrudall) | [๐Ÿค– OpenAI Gem](https://github.com/alexrudall/ruby-openai) | [๐Ÿš‚ Midjourney Gem](https://github.com/alexrudall/midjourney)
16
14
 
17
15
  ### Bundler
18
16
 
@@ -52,11 +50,15 @@ client = Anthropic::Client.new(access_token: "access_token_goes_here")
52
50
 
53
51
  ### With Config
54
52
 
55
- For a more robust setup, you can configure the gem with your API keys, for example in an `anthropic.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.
53
+ For a more robust setup, you can configure the gem with your API keys, for example in an `anthropic.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments or rails credentials if you are using this in a rails project.
56
54
 
57
55
  ```ruby
58
56
  Anthropic.configure do |config|
59
- config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
57
+ # With dotenv
58
+ config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
59
+ # OR
60
+ # With Rails credentials
61
+ config.access_token = Rails.application.credentials.dig(:anthropic, :api_key)
60
62
  end
61
63
  ```
62
64
 
@@ -74,9 +76,9 @@ The default timeout for any request using this library is 120 seconds. You can c
74
76
 
75
77
  ```ruby
76
78
  client = Anthropic::Client.new(
77
- access_token: "access_token_goes_here",
78
- anthropic_version: "2023-01-01", # Optional
79
- request_timeout: 240 # Optional
79
+ access_token: "access_token_goes_here",
80
+ anthropic_version: "2023-01-01", # Optional
81
+ request_timeout: 240 # Optional
80
82
  )
81
83
  ```
82
84
 
@@ -84,40 +86,54 @@ You can also set these keys when configuring the gem:
84
86
 
85
87
  ```ruby
86
88
  Anthropic.configure do |config|
87
- config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
88
- config.anthropic_version = "2023-01-01" # Optional
89
- config.request_timeout = 240 # Optional
89
+ config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
90
+ config.anthropic_version = "2023-01-01" # Optional
91
+ config.request_timeout = 240 # Optional
90
92
  end
91
93
  ```
92
94
 
93
- ### Completions
94
-
95
- Hit the Anthropic API for a completion:
96
-
97
- ```ruby
98
- response = client.complete(
99
- parameters: {
100
- model: "claude-2",
101
- prompt: "How high is the sky?",
102
- max_tokens_to_sample: 5
103
- })
104
- puts response["completion"]
105
- # => " The sky has no definitive"
106
- ```
95
+ ### Models
107
96
 
108
- Note that all requests are prepended by this library with
97
+ Available Models:
109
98
 
110
- `\n\nHuman: `
99
+ | Name | API Name |
100
+ | --------------- | ------------------------ |
101
+ | Claude 3 Opus | claude-3-opus-20240229 |
102
+ | Claude 3 Sonnet | claude-3-sonnet-20240229 |
103
+ | Claude 3 Haiku | claude-3-haiku-20240307 |
111
104
 
112
- and appended with
105
+ You can find the latest model names in the [Anthropic API documentation](https://docs.anthropic.com/claude/docs/models-overview#model-recommendations).
113
106
 
114
- `\n\nAssistant:`
107
+ ### Messages
115
108
 
116
- so whatever prompt you pass will be sent to the API as
109
+ ```
110
+ POST https://api.anthropic.com/v1/messages
111
+ ```
117
112
 
118
- `\n\nHuman: How high is the sky?\n\nAssistant:`
113
+ Send a sequence of messages (user or assistant) to the API and receive a message in response.
119
114
 
120
- This is a requirement of [the API](https://docs.anthropic.com/claude/reference/complete_post).
115
+ ```ruby
116
+ response = client.messages(
117
+ parameters: {
118
+ model: "claude-3-haiku-20240307", # claude-3-opus-20240229, claude-3-sonnet-20240229
119
+ system: "Respond only in Spanish.",
120
+ messages: [
121
+ {"role": "user", "content": "Hello, Claude!"}
122
+ ],
123
+ max_tokens: 1000
124
+ }
125
+ )
126
+ # => {
127
+ # => "id" => "msg_0123MiRVCgSG2PaQZwCGbgmV",
128
+ # => "type" => "message",
129
+ # => "role" => "assistant",
130
+ # => "content" => [{"type"=>"text", "text"=>"ยกHola! Es un gusto saludarte. ยฟEn quรฉ puedo ayudarte hoy?"}],
131
+ # => "model" => "claude-3-haiku-20240307",
132
+ # => "stop_reason" => "end_turn",
133
+ # => "stop_sequence" => nil,
134
+ # => "usage" => {"input_tokens"=>17, "output_tokens"=>32}
135
+ # => }
136
+ ```
121
137
 
122
138
  ## Development
123
139
 
@@ -125,6 +141,11 @@ After checking out the repo, run `bin/setup` to install dependencies. You can ru
125
141
 
126
142
  To install this gem onto your local machine, run `bundle exec rake install`.
127
143
 
144
+ To run all tests, execute the command `bundle exec rake`, which will also run the linter (Rubocop). This repository uses [VCR](https://github.com/vcr/vcr) to log API requests.
145
+
146
+ > [!WARNING]
147
+ > If you have an `ANTHROPIC_API_KEY` in your `ENV`, running the specs will use this to run the specs against the actual API, which will be slow and cost you money - 2 cents or more! Remove it from your environment with `unset` or similar if you just want to run the specs against the stored VCR responses.
148
+
128
149
  ### Warning
129
150
 
130
151
  If you have an `ANTHROPIC_API_KEY` in your `ENV`, running the specs will use this to run the specs against the actual API, which will be slow and cost you money - 2 cents or more! Remove it from your environment with `unset` or similar if you just want to run the specs against the stored VCR responses.
data/Rakefile CHANGED
@@ -1,6 +1,19 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task default: :spec
7
+ task :default do
8
+ Rake::Task["test"].invoke
9
+ Rake::Task["lint"].invoke
10
+ end
11
+
12
+ task :test do
13
+ Rake::Task["spec"].invoke
14
+ end
15
+
16
+ task :lint do
17
+ RuboCop::RakeTask.new(:rubocop)
18
+ Rake::Task["rubocop"].invoke
19
+ end
data/anthropic.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Alex"]
7
7
  spec.email = ["alexrudall@users.noreply.github.com"]
8
8
 
9
- spec.summary = "Anthropic API + Ruby! ๐ŸŒŒโค๏ธ"
9
+ spec.summary = "Anthropic API + Ruby! ๐Ÿค–๐ŸŒŒ"
10
10
  spec.homepage = "https://github.com/alexrudall/anthropic"
11
11
  spec.license = "MIT"
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
@@ -16,6 +16,10 @@ module Anthropic
16
16
  Anthropic::Client.json_post(path: "/complete", parameters: parameters)
17
17
  end
18
18
 
19
+ def messages(parameters: {})
20
+ Anthropic::Client.json_post(path: "/messages", parameters: parameters)
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def wrap_prompt(prompt:, prefix: "\n\nHuman: ", suffix: "\n\nAssistant:")
@@ -1,3 +1,3 @@
1
1
  module Anthropic
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-18 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -93,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.4.12
96
+ rubygems_version: 3.4.22
97
97
  signing_key:
98
98
  specification_version: 4
99
- summary: "Anthropic API + Ruby! \U0001F30Cโค๏ธ"
99
+ summary: "Anthropic API + Ruby! \U0001F916\U0001F30C"
100
100
  test_files: []