anthropic 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +2 -2
- data/README.md +29 -15
- data/anthropic.gemspec +1 -1
- data/lib/anthropic/client.rb +13 -2
- data/lib/anthropic/http.rb +3 -3
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +4 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bf4e9a547533edb57fcaee7dd07c8c1a5c7d3f5291b539541b9b9b8c3b5e614
|
4
|
+
data.tar.gz: e62081a581aa15d9b8dbd335fb6b989671eb733629b64992c847584e83100c4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc148818d355a80050ae35c9b7a60d48dfa713826b9607d9add0ceb70b88da4b19f7b650dae1b5714ea41003fcec94cd4bc2fd226f999c3e4c3562d681a8100a
|
7
|
+
data.tar.gz: 683dedfd00584546691bde56a569f2a043a0ba8b9806450e5baabcdbc0c0ff28960778c9cda600bea5b13a8024b01337e1f271f363508dd657424ad6da3b3fbd
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
anthropic (0.
|
4
|
+
anthropic (0.1.0)
|
5
5
|
faraday (>= 1)
|
6
6
|
faraday-multipart (>= 1)
|
7
7
|
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
rexml
|
17
17
|
diff-lcs (1.5.0)
|
18
18
|
dotenv (2.8.1)
|
19
|
-
faraday (2.7.
|
19
|
+
faraday (2.7.10)
|
20
20
|
faraday-net_http (>= 2.0, < 3.1)
|
21
21
|
ruby2_keywords (>= 0.0.4)
|
22
22
|
faraday-multipart (1.0.4)
|
data/README.md
CHANGED
@@ -4,9 +4,9 @@
|
|
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://anthropic.com/
|
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
11
|
[Ruby AI Builders Discord](https://discord.gg/k4Uc224xVD)
|
12
12
|
|
@@ -40,8 +40,7 @@ require "anthropic"
|
|
40
40
|
|
41
41
|
## Usage
|
42
42
|
|
43
|
-
- Get your API key from [https://
|
44
|
-
- If you belong to multiple organizations, you can get your Organization ID from [https://platform.anthropic.com/account/org-settings](https://platform.anthropic.com/account/org-settings)
|
43
|
+
- Get your API key from [https://console.anthropic.com/account/keys](https://console.anthropic.com/account/keys)
|
45
44
|
|
46
45
|
### Quickstart
|
47
46
|
|
@@ -67,26 +66,27 @@ Then you can create a client like this:
|
|
67
66
|
client = Anthropic::Client.new
|
68
67
|
```
|
69
68
|
|
70
|
-
####
|
69
|
+
#### Change version or timeout
|
70
|
+
|
71
|
+
You can change to a different dated version (different from the URL version which is just `v1`) of Anthropic's API by passing `anthropic_version` when initializing the client. If you don't the default latest will be used, which is "2023-06-01". [More info](https://docs.anthropic.com/claude/reference/versioning)
|
71
72
|
|
72
73
|
The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the `request_timeout` when initializing the client.
|
73
74
|
|
74
75
|
```ruby
|
75
76
|
client = Anthropic::Client.new(
|
76
77
|
access_token: "access_token_goes_here",
|
77
|
-
|
78
|
+
anthropic_version: "2023-01-01", # Optional
|
79
|
+
request_timeout: 240 # Optional
|
78
80
|
)
|
79
81
|
```
|
80
82
|
|
81
|
-
|
83
|
+
You can also set these keys when configuring the gem:
|
82
84
|
|
83
85
|
```ruby
|
84
86
|
Anthropic.configure do |config|
|
85
87
|
config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
|
88
|
+
config.anthropic_version = "2023-01-01" # Optional
|
86
89
|
config.request_timeout = 240 # Optional
|
87
|
-
config.extra_headers = {
|
88
|
-
"X-Proxy-Refresh": "true"
|
89
|
-
} # Optional
|
90
90
|
end
|
91
91
|
```
|
92
92
|
|
@@ -95,16 +95,30 @@ end
|
|
95
95
|
Hit the Anthropic API for a completion:
|
96
96
|
|
97
97
|
```ruby
|
98
|
-
response = client.
|
98
|
+
response = client.complete(
|
99
99
|
parameters: {
|
100
100
|
model: "claude-2",
|
101
|
-
prompt: "
|
102
|
-
|
101
|
+
prompt: "How high is the sky?",
|
102
|
+
max_tokens_to_sample: 5
|
103
103
|
})
|
104
|
-
puts response["
|
105
|
-
# =>
|
104
|
+
puts response["completion"]
|
105
|
+
# => " The sky has no definitive"
|
106
106
|
```
|
107
107
|
|
108
|
+
Note that all requests are prepended by this library with
|
109
|
+
|
110
|
+
`\n\nHuman: `
|
111
|
+
|
112
|
+
and appended with
|
113
|
+
|
114
|
+
`\n\nAssistant:`
|
115
|
+
|
116
|
+
so whatever prompt you pass will be sent to the API as
|
117
|
+
|
118
|
+
`\n\nHuman: How high is the sky?\n\nAssistant:`
|
119
|
+
|
120
|
+
This is a requirement of [the API](https://docs.anthropic.com/claude/reference/complete_post).
|
121
|
+
|
108
122
|
## Development
|
109
123
|
|
110
124
|
After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
|
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")
|
data/lib/anthropic/client.rb
CHANGED
@@ -11,8 +11,19 @@ module Anthropic
|
|
11
11
|
Anthropic.configuration.extra_headers = extra_headers
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def complete(parameters: {})
|
15
|
+
parameters[:prompt] = wrap_prompt(prompt: parameters[:prompt])
|
16
|
+
Anthropic::Client.json_post(path: "/complete", parameters: parameters)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def wrap_prompt(prompt:, prefix: "\n\nHuman: ", suffix: "\n\nAssistant:")
|
22
|
+
return if prompt.nil?
|
23
|
+
|
24
|
+
prompt.prepend(prefix) unless prompt.start_with?(prefix)
|
25
|
+
prompt.concat(suffix) unless prompt.end_with?(suffix)
|
26
|
+
prompt
|
16
27
|
end
|
17
28
|
end
|
18
29
|
end
|
data/lib/anthropic/http.rb
CHANGED
@@ -74,8 +74,8 @@ module Anthropic
|
|
74
74
|
def headers
|
75
75
|
{
|
76
76
|
"Content-Type" => "application/json",
|
77
|
-
"
|
78
|
-
"Anthropic-
|
77
|
+
"x-api-key" => Anthropic.configuration.access_token,
|
78
|
+
"Anthropic-Version" => Anthropic.configuration.anthropic_version
|
79
79
|
}.merge(Anthropic.configuration.extra_headers)
|
80
80
|
end
|
81
81
|
|
@@ -83,7 +83,7 @@ module Anthropic
|
|
83
83
|
parameters&.transform_values do |value|
|
84
84
|
next value unless value.is_a?(File)
|
85
85
|
|
86
|
-
# Doesn't seem like Anthropic
|
86
|
+
# Doesn't seem like Anthropic needs mime_type yet, so not worth
|
87
87
|
# the library to figure this out. Hence the empty string
|
88
88
|
# as the second argument.
|
89
89
|
Faraday::UploadIO.new(value, "", value.path)
|
data/lib/anthropic/version.rb
CHANGED
data/lib/anthropic.rb
CHANGED
@@ -3,10 +3,6 @@ require "faraday/multipart"
|
|
3
3
|
|
4
4
|
require_relative "anthropic/http"
|
5
5
|
require_relative "anthropic/client"
|
6
|
-
require_relative "anthropic/files"
|
7
|
-
require_relative "anthropic/finetunes"
|
8
|
-
require_relative "anthropic/images"
|
9
|
-
require_relative "anthropic/models"
|
10
6
|
require_relative "anthropic/version"
|
11
7
|
|
12
8
|
module Anthropic
|
@@ -15,15 +11,18 @@ module Anthropic
|
|
15
11
|
|
16
12
|
class Configuration
|
17
13
|
attr_writer :access_token
|
18
|
-
attr_accessor :
|
14
|
+
attr_accessor :anthropic_version, :api_version, :extra_headers, :organization_id,
|
15
|
+
:request_timeout, :uri_base
|
19
16
|
|
20
17
|
DEFAULT_API_VERSION = "v1".freeze
|
18
|
+
DEFAULT_ANTHROPIC_VERSION = "2023-06-01".freeze
|
21
19
|
DEFAULT_URI_BASE = "https://api.anthropic.com/".freeze
|
22
20
|
DEFAULT_REQUEST_TIMEOUT = 120
|
23
21
|
|
24
22
|
def initialize
|
25
23
|
@access_token = nil
|
26
24
|
@api_version = DEFAULT_API_VERSION
|
25
|
+
@anthropic_version = DEFAULT_ANTHROPIC_VERSION
|
27
26
|
@organization_id = nil
|
28
27
|
@uri_base = DEFAULT_URI_BASE
|
29
28
|
@request_timeout = DEFAULT_REQUEST_TIMEOUT
|
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.1.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-
|
11
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -96,5 +96,5 @@ requirements: []
|
|
96
96
|
rubygems_version: 3.4.12
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
|
-
summary: "Anthropic API + Ruby! \
|
99
|
+
summary: "Anthropic API + Ruby! \U0001F30C❤️"
|
100
100
|
test_files: []
|