ruby-openai 3.2.0 → 3.4.0
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 +2 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -7
- data/README.md +25 -6
- data/bin/console +1 -1
- data/lib/{ruby/openai → openai}/client.rb +9 -5
- data/lib/openai/compatibility.rb +9 -0
- data/lib/{ruby/openai → openai}/files.rb +2 -2
- data/lib/{ruby/openai → openai}/finetunes.rb +2 -2
- data/lib/{ruby/openai → openai}/images.rb +2 -2
- data/lib/{ruby/openai → openai}/models.rb +2 -2
- data/lib/openai/version.rb +3 -0
- data/lib/openai.rb +45 -0
- data/lib/ruby/openai.rb +2 -46
- data/ruby-openai.gemspec +4 -2
- metadata +18 -13
- data/lib/ruby/openai/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3d2b8f98be44b7f33fce40f271bccc3dc1c72237df7ad64baed43f4ea79fb51
|
4
|
+
data.tar.gz: f19cc5e7155b47e6f7ccb7c5642679e5d8f7a6600e6d4f9e592ebc16313b74f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f2c05fae48718593ea7990c480f6108844a698a943c8db2e3e01f3e31e95ede1ca2a5bd0dec5364a9b1730698c3802e24eecec585d20e59b03e1a421c8a3c4e
|
7
|
+
data.tar.gz: 303d6df6cea50a4f9ac50f8cab7329e585e201aeb2532709b161b830896cc1e733e0c48dfa6ebff22d13d930c3a0ff76425b8e0294c7e175a1bc4e07b84710a2
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,19 @@ 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
|
+
## [3.4.0] - 2023-03-01
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add Client#chat endpoint - ChatGPT over the wire!
|
13
|
+
|
14
|
+
## [3.3.0] - 2023-02-15
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Replace ::Ruby::OpenAI namespace with ::OpenAI - thanks [@kmcphillips](https://github.com/kmcphillips) for this work!
|
19
|
+
- To upgrade, change `require 'ruby/openai'` to `require 'openai'` and change all references to `Ruby::OpenAI` to `OpenAI`.
|
20
|
+
|
8
21
|
## [3.2.0] - 2023-02-13
|
9
22
|
|
10
23
|
### Added
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-openai (3.
|
4
|
+
ruby-openai (3.4.0)
|
5
5
|
httparty (>= 0.18.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
mini_mime (1.1.2)
|
24
24
|
multi_xml (0.6.0)
|
25
25
|
parallel (1.22.1)
|
26
|
-
parser (3.2.
|
26
|
+
parser (3.2.1.0)
|
27
27
|
ast (~> 2.4.1)
|
28
28
|
public_suffix (5.0.1)
|
29
29
|
rainbow (3.1.1)
|
@@ -43,18 +43,18 @@ GEM
|
|
43
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
44
|
rspec-support (~> 3.12.0)
|
45
45
|
rspec-support (3.12.0)
|
46
|
-
rubocop (1.
|
46
|
+
rubocop (1.46.0)
|
47
47
|
json (~> 2.3)
|
48
48
|
parallel (~> 1.10)
|
49
49
|
parser (>= 3.2.0.0)
|
50
50
|
rainbow (>= 2.2.2, < 4.0)
|
51
51
|
regexp_parser (>= 1.8, < 3.0)
|
52
52
|
rexml (>= 3.2.5, < 4.0)
|
53
|
-
rubocop-ast (>= 1.
|
53
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
54
54
|
ruby-progressbar (~> 1.7)
|
55
55
|
unicode-display_width (>= 2.4.0, < 3.0)
|
56
|
-
rubocop-ast (1.
|
57
|
-
parser (>= 3.
|
56
|
+
rubocop-ast (1.26.0)
|
57
|
+
parser (>= 3.2.1.0)
|
58
58
|
ruby-progressbar (1.11.0)
|
59
59
|
unicode-display_width (2.4.2)
|
60
60
|
vcr (6.1.0)
|
@@ -71,7 +71,7 @@ DEPENDENCIES
|
|
71
71
|
dotenv (~> 2.8.1)
|
72
72
|
rake (~> 13.0)
|
73
73
|
rspec (~> 3.12)
|
74
|
-
rubocop (~> 1.
|
74
|
+
rubocop (~> 1.46.0)
|
75
75
|
ruby-openai!
|
76
76
|
vcr (~> 6.1.0)
|
77
77
|
webmock (~> 3.18.1)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Ruby
|
1
|
+
# Ruby OpenAI
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/ruby-openai)
|
4
4
|
[](https://github.com/alexrudall/ruby-openai/blob/main/LICENSE.txt)
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
Use the [OpenAI API](https://openai.com/blog/openai-api/) with Ruby! 🤖❤️
|
9
9
|
|
10
|
-
Generate text with
|
10
|
+
Generate text with ChatGPT, create images with DALL·E, or write code with Codex...
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -32,9 +32,13 @@ $ gem install ruby-openai
|
|
32
32
|
and require with:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
require "
|
35
|
+
require "openai"
|
36
36
|
```
|
37
37
|
|
38
|
+
## Upgrading
|
39
|
+
|
40
|
+
The `::Ruby::OpenAI` module has been removed and all classes have been moved under the top level `::OpenAI` module. To upgrade, change `require 'ruby/openai'` to `require 'openai'` and change all references to `Ruby::OpenAI` to `OpenAI`.
|
41
|
+
|
38
42
|
## Usage
|
39
43
|
|
40
44
|
- Get your API key from [https://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys)
|
@@ -53,7 +57,7 @@ For a quick test you can pass your token directly to a new client:
|
|
53
57
|
For a more robust setup, you can configure the gem with your API keys, for example in an `openai.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.
|
54
58
|
|
55
59
|
```ruby
|
56
|
-
|
60
|
+
OpenAI.configure do |config|
|
57
61
|
config.access_token = ENV.fetch('OPENAI_ACCESS_TOKEN')
|
58
62
|
config.organization_id = ENV.fetch('OPENAI_ORGANIZATION_ID') # Optional.
|
59
63
|
end
|
@@ -85,9 +89,24 @@ There are different models that can be used to generate text. For a full list an
|
|
85
89
|
- code-davinci-002
|
86
90
|
- code-cushman-001
|
87
91
|
|
92
|
+
### ChatGPT
|
93
|
+
|
94
|
+
ChatGPT is a model that can be used to generate text in a conversational style. You can use it to generate a response to a sequence of [messages](https://platform.openai.com/docs/guides/chat/introduction):
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
response = client.chat(
|
98
|
+
parameters: {
|
99
|
+
model: "gpt-3.5-turbo",
|
100
|
+
messages: [{ role: "user", content: "Hello!"}],
|
101
|
+
})
|
102
|
+
puts response.dig("choices", 0, "message", "content")
|
103
|
+
=> "Hello! How may I assist you today?"
|
104
|
+
|
105
|
+
```
|
106
|
+
|
88
107
|
### Completions
|
89
108
|
|
90
|
-
Hit the OpenAI API for a completion:
|
109
|
+
Hit the OpenAI API for a completion using other GPT-3 models:
|
91
110
|
|
92
111
|
```ruby
|
93
112
|
response = client.completions(
|
@@ -274,4 +293,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
274
293
|
|
275
294
|
## Code of Conduct
|
276
295
|
|
277
|
-
Everyone interacting in the Ruby
|
296
|
+
Everyone interacting in the Ruby OpenAI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alexrudall/ruby-openai/blob/main/CODE_OF_CONDUCT.md).
|
data/bin/console
CHANGED
@@ -3,8 +3,12 @@ module OpenAI
|
|
3
3
|
URI_BASE = "https://api.openai.com/".freeze
|
4
4
|
|
5
5
|
def initialize(access_token: nil, organization_id: nil)
|
6
|
-
|
7
|
-
|
6
|
+
OpenAI.configuration.access_token = access_token if access_token
|
7
|
+
OpenAI.configuration.organization_id = organization_id if organization_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def chat(parameters: {})
|
11
|
+
OpenAI::Client.json_post(path: "/chat/completions", parameters: parameters)
|
8
12
|
end
|
9
13
|
|
10
14
|
def completions(parameters: {})
|
@@ -70,14 +74,14 @@ module OpenAI
|
|
70
74
|
end
|
71
75
|
|
72
76
|
private_class_method def self.uri(path:)
|
73
|
-
URI_BASE +
|
77
|
+
URI_BASE + OpenAI.configuration.api_version + path
|
74
78
|
end
|
75
79
|
|
76
80
|
private_class_method def self.headers
|
77
81
|
{
|
78
82
|
"Content-Type" => "application/json",
|
79
|
-
"Authorization" => "Bearer #{
|
80
|
-
"OpenAI-Organization" =>
|
83
|
+
"Authorization" => "Bearer #{OpenAI.configuration.access_token}",
|
84
|
+
"OpenAI-Organization" => OpenAI.configuration.organization_id
|
81
85
|
}
|
82
86
|
end
|
83
87
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module OpenAI
|
2
2
|
class Files
|
3
3
|
def initialize(access_token: nil, organization_id: nil)
|
4
|
-
|
5
|
-
|
4
|
+
OpenAI.configuration.access_token = access_token if access_token
|
5
|
+
OpenAI.configuration.organization_id = organization_id if organization_id
|
6
6
|
end
|
7
7
|
|
8
8
|
def list
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module OpenAI
|
2
2
|
class Finetunes
|
3
3
|
def initialize(access_token: nil, organization_id: nil)
|
4
|
-
|
5
|
-
|
4
|
+
OpenAI.configuration.access_token = access_token if access_token
|
5
|
+
OpenAI.configuration.organization_id = organization_id if organization_id
|
6
6
|
end
|
7
7
|
|
8
8
|
def list
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module OpenAI
|
2
2
|
class Images
|
3
3
|
def initialize(access_token: nil, organization_id: nil)
|
4
|
-
|
5
|
-
|
4
|
+
OpenAI.configuration.access_token = access_token if access_token
|
5
|
+
OpenAI.configuration.organization_id = organization_id if organization_id
|
6
6
|
end
|
7
7
|
|
8
8
|
def generate(parameters: {})
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module OpenAI
|
2
2
|
class Models
|
3
3
|
def initialize(access_token: nil, organization_id: nil)
|
4
|
-
|
5
|
-
|
4
|
+
OpenAI.configuration.access_token = access_token if access_token
|
5
|
+
OpenAI.configuration.organization_id = organization_id if organization_id
|
6
6
|
end
|
7
7
|
|
8
8
|
def list
|
data/lib/openai.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
require_relative "openai/client"
|
4
|
+
require_relative "openai/files"
|
5
|
+
require_relative "openai/finetunes"
|
6
|
+
require_relative "openai/images"
|
7
|
+
require_relative "openai/models"
|
8
|
+
require_relative "openai/version"
|
9
|
+
|
10
|
+
module OpenAI
|
11
|
+
class Error < StandardError; end
|
12
|
+
class ConfigurationError < Error; end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_writer :access_token
|
16
|
+
attr_accessor :api_version, :organization_id
|
17
|
+
|
18
|
+
DEFAULT_API_VERSION = "v1".freeze
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@access_token = nil
|
22
|
+
@api_version = DEFAULT_API_VERSION
|
23
|
+
@organization_id = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def access_token
|
27
|
+
return @access_token if @access_token
|
28
|
+
|
29
|
+
error_text = "OpenAI access token missing! See https://github.com/alexrudall/ruby-openai#usage"
|
30
|
+
raise ConfigurationError, error_text
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
attr_writer :configuration
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.configuration
|
39
|
+
@configuration ||= OpenAI::Configuration.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.configure
|
43
|
+
yield(configuration)
|
44
|
+
end
|
45
|
+
end
|
data/lib/ruby/openai.rb
CHANGED
@@ -1,46 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "ruby/openai/files"
|
4
|
-
require "ruby/openai/finetunes"
|
5
|
-
require "ruby/openai/images"
|
6
|
-
require "ruby/openai/models"
|
7
|
-
require "ruby/openai/version"
|
8
|
-
|
9
|
-
module Ruby
|
10
|
-
module OpenAI
|
11
|
-
class Error < StandardError; end
|
12
|
-
class ConfigurationError < Error; end
|
13
|
-
|
14
|
-
class Configuration
|
15
|
-
attr_writer :access_token
|
16
|
-
attr_accessor :api_version, :organization_id
|
17
|
-
|
18
|
-
DEFAULT_API_VERSION = "v1".freeze
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
@access_token = nil
|
22
|
-
@api_version = DEFAULT_API_VERSION
|
23
|
-
@organization_id = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def access_token
|
27
|
-
return @access_token if @access_token
|
28
|
-
|
29
|
-
error_text = "OpenAI access token missing! See https://github.com/alexrudall/ruby-openai#usage"
|
30
|
-
raise ConfigurationError, error_text
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class << self
|
35
|
-
attr_writer :configuration
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.configuration
|
39
|
-
@configuration ||= OpenAI::Configuration.new
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.configure
|
43
|
-
yield(configuration)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
require_relative "../openai"
|
2
|
+
require_relative "../openai/compatibility"
|
data/ruby-openai.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative "lib/
|
1
|
+
require_relative "lib/openai/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "ruby-openai"
|
5
|
-
spec.version =
|
5
|
+
spec.version = OpenAI::VERSION
|
6
6
|
spec.authors = ["Alex"]
|
7
7
|
spec.email = ["alexrudall@users.noreply.github.com"]
|
8
8
|
|
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
28
|
spec.add_dependency "httparty", ">= 0.18.1"
|
29
|
+
|
30
|
+
spec.post_install_message = "Note if upgrading: The `::Ruby::OpenAI` module has been removed and all classes have been moved under the top level `::OpenAI` module. To upgrade, change `require 'ruby/openai'` to `require 'openai'` and change all references to `Ruby::OpenAI` to `OpenAI`."
|
29
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-openai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.18.1
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- alexrudall@users.noreply.github.com
|
30
30
|
executables: []
|
@@ -48,13 +48,15 @@ files:
|
|
48
48
|
- Rakefile
|
49
49
|
- bin/console
|
50
50
|
- bin/setup
|
51
|
+
- lib/openai.rb
|
52
|
+
- lib/openai/client.rb
|
53
|
+
- lib/openai/compatibility.rb
|
54
|
+
- lib/openai/files.rb
|
55
|
+
- lib/openai/finetunes.rb
|
56
|
+
- lib/openai/images.rb
|
57
|
+
- lib/openai/models.rb
|
58
|
+
- lib/openai/version.rb
|
51
59
|
- lib/ruby/openai.rb
|
52
|
-
- lib/ruby/openai/client.rb
|
53
|
-
- lib/ruby/openai/files.rb
|
54
|
-
- lib/ruby/openai/finetunes.rb
|
55
|
-
- lib/ruby/openai/images.rb
|
56
|
-
- lib/ruby/openai/models.rb
|
57
|
-
- lib/ruby/openai/version.rb
|
58
60
|
- pull_request_template.md
|
59
61
|
- ruby-openai.gemspec
|
60
62
|
homepage: https://github.com/alexrudall/ruby-openai
|
@@ -65,7 +67,10 @@ metadata:
|
|
65
67
|
source_code_uri: https://github.com/alexrudall/ruby-openai
|
66
68
|
changelog_uri: https://github.com/alexrudall/ruby-openai/blob/main/CHANGELOG.md
|
67
69
|
rubygems_mfa_required: 'true'
|
68
|
-
post_install_message:
|
70
|
+
post_install_message: 'Note if upgrading: The `::Ruby::OpenAI` module has been removed
|
71
|
+
and all classes have been moved under the top level `::OpenAI` module. To upgrade,
|
72
|
+
change `require ''ruby/openai''` to `require ''openai''` and change all references
|
73
|
+
to `Ruby::OpenAI` to `OpenAI`.'
|
69
74
|
rdoc_options: []
|
70
75
|
require_paths:
|
71
76
|
- lib
|
@@ -80,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
85
|
- !ruby/object:Gem::Version
|
81
86
|
version: '0'
|
82
87
|
requirements: []
|
83
|
-
rubygems_version: 3.4.
|
84
|
-
signing_key:
|
88
|
+
rubygems_version: 3.4.6
|
89
|
+
signing_key:
|
85
90
|
specification_version: 4
|
86
91
|
summary: A Ruby gem for the OpenAI GPT-3 API
|
87
92
|
test_files: []
|