ruby-openai 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5927989b832799b3620dd5e1d93796d44fd3fe353d2edc2d64a4be2162bc6ff
4
- data.tar.gz: 3313d8fa4ce08438fda80850736c96d73397f8f9d7baf72a365dea839c0cd876
3
+ metadata.gz: 141a4b28c980797b7b04fd8434e03755341fdfbc542e7ba2425b8d467662ef34
4
+ data.tar.gz: 934ed9a6b66897c370c8d5c8787d2508a95f55e695d312bab2c4227af5f820ca
5
5
  SHA512:
6
- metadata.gz: 4604610b91ea93c5a8b08886700c656ca3651129542a6c257d5d000fc414f2a47e9ca8e8cadba622fb426a4e969fd0d058a83d857455893d172f3125852efd19
7
- data.tar.gz: d8b959447a050615b4cdffd15cb7ac782b43b4d73953e6b0aa687bacf1f5872d4e9546547d4961fd0e1f5b07f40f460ae2cb136f717034e0a9199f4e5822946c
6
+ metadata.gz: f4bccb5f8b6ac3fc05ac592af972412a284dfb2aa4015657faa8358d7e00e060b508153413c8d8416e991886724e795a5c26125485ffec3181dcb2fd3d84e298
7
+ data.tar.gz: 7a2138265ae5235d870d6ddae69acf016132c71bef8b5781d5854c6ad970396d3b466b59cd14f82891b11d81b8833483ccf757f899be71cbb9f12f6608aaffd8
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
+ ## [2.1.0] - 2022-11-13
9
+
10
+ ### Added
11
+
12
+ - Add Images#generate endpoint to generate images with DALL·E!
13
+
14
+ ## [2.0.1] - 2022-10-22
15
+
16
+ ### Removed
17
+
18
+ - Deprecate Client#answers endpoint.
19
+ - Deprecate Client#classifications endpoint.
20
+
8
21
  ## [2.0.0] - 2022-09-19
9
22
 
10
23
  ### Removed
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
 
6
6
  gem "byebug", "~> 11.1.3"
7
7
  gem "rake", "~> 13.0"
8
- gem "rspec", "~> 3.11"
9
- gem "rubocop", "~> 1.36.0"
8
+ gem "rspec", "~> 3.12"
9
+ gem "rubocop", "~> 1.38.0"
10
10
  gem "vcr", "~> 6.1.0"
11
11
  gem "webmock", "~> 3.18.1"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai (2.0.0)
4
+ ruby-openai (2.1.0)
5
5
  dotenv (>= 2.7.6, < 2.9.0)
6
6
  httparty (>= 0.18.1, < 0.21.0)
7
7
 
@@ -31,32 +31,32 @@ GEM
31
31
  public_suffix (4.0.7)
32
32
  rainbow (3.1.1)
33
33
  rake (13.0.6)
34
- regexp_parser (2.5.0)
34
+ regexp_parser (2.6.0)
35
35
  rexml (3.2.5)
36
- rspec (3.11.0)
37
- rspec-core (~> 3.11.0)
38
- rspec-expectations (~> 3.11.0)
39
- rspec-mocks (~> 3.11.0)
40
- rspec-core (3.11.0)
41
- rspec-support (~> 3.11.0)
42
- rspec-expectations (3.11.0)
36
+ rspec (3.12.0)
37
+ rspec-core (~> 3.12.0)
38
+ rspec-expectations (~> 3.12.0)
39
+ rspec-mocks (~> 3.12.0)
40
+ rspec-core (3.12.0)
41
+ rspec-support (~> 3.12.0)
42
+ rspec-expectations (3.12.0)
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.11.0)
45
- rspec-mocks (3.11.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-mocks (3.12.0)
46
46
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.11.0)
48
- rspec-support (3.11.0)
49
- rubocop (1.36.0)
47
+ rspec-support (~> 3.12.0)
48
+ rspec-support (3.12.0)
49
+ rubocop (1.38.0)
50
50
  json (~> 2.3)
51
51
  parallel (~> 1.10)
52
52
  parser (>= 3.1.2.1)
53
53
  rainbow (>= 2.2.2, < 4.0)
54
54
  regexp_parser (>= 1.8, < 3.0)
55
55
  rexml (>= 3.2.5, < 4.0)
56
- rubocop-ast (>= 1.20.1, < 2.0)
56
+ rubocop-ast (>= 1.23.0, < 2.0)
57
57
  ruby-progressbar (~> 1.7)
58
58
  unicode-display_width (>= 1.4.0, < 3.0)
59
- rubocop-ast (1.21.0)
59
+ rubocop-ast (1.23.0)
60
60
  parser (>= 3.1.1.0)
61
61
  ruby-progressbar (1.11.0)
62
62
  unicode-display_width (2.3.0)
@@ -72,8 +72,8 @@ PLATFORMS
72
72
  DEPENDENCIES
73
73
  byebug (~> 11.1.3)
74
74
  rake (~> 13.0)
75
- rspec (~> 3.11)
76
- rubocop (~> 1.36.0)
75
+ rspec (~> 3.12)
76
+ rubocop (~> 1.38.0)
77
77
  ruby-openai!
78
78
  vcr (~> 6.1.0)
79
79
  webmock (~> 3.18.1)
data/README.md CHANGED
@@ -59,6 +59,15 @@ Alternatively you can pass your key directly to a new client:
59
59
  client = OpenAI::Client.new(access_token: "access_token_goes_here")
60
60
  ```
61
61
 
62
+ ### Models
63
+
64
+ There are different models that can be used to generate text. For a full list and to retrieve information about a single models:
65
+
66
+ ```ruby
67
+ client.models.list
68
+ client.models.retrieve(id: "text-ada-001")
69
+ ```
70
+
62
71
  #### Examples
63
72
 
64
73
  - [GPT-3](https://beta.openai.com/docs/models/gpt-3)
@@ -70,15 +79,6 @@ Alternatively you can pass your key directly to a new client:
70
79
  - code-davinci-002
71
80
  - code-cushman-001
72
81
 
73
- ### Models
74
-
75
- There are different models that can be used to generate text. For a full list and to retrieve information about a single models:
76
-
77
- ```ruby
78
- client.models.list
79
- client.models.retrieve(id: "text-ada-001")
80
- ```
81
-
82
82
  ### Completions
83
83
 
84
84
  Hit the OpenAI API for a completion:
@@ -194,6 +194,18 @@ This fine-tuned model name can then be used in classifications:
194
194
  JSON.parse(response.body)["choices"].map { |c| c["text"] }
195
195
  ```
196
196
 
197
+ ### Images
198
+
199
+ Generate an image using DALL·E!
200
+
201
+ ```ruby
202
+ response = client.images.generate(parameters: { prompt: "A baby sea otter cooking pasta wearing a hat of some sort" })
203
+ puts response.dig("data", 0, "url") }
204
+ => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
205
+ ```
206
+
207
+ ![Otter Chef](https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhhQPMiIQ0Es8OwrH/user-jxM65ijkZc1qRfHC0IJ8mOIc/img-UrDvFC4tDnuhTieF7TrTJ2gq.png?st=2022-11-13T15%3A55%3A34Z&se=2022-11-13T17%3A55%3A34Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2022-11-13T01%3A32%3A30Z&ske=2022-11-14T01%3A32%3A30Z&sks=b&skv=2021-08-06&sig=tLdggckHl20CnnpCleoeiAEQjy4zMjuZJiUdovmkoF0%3D)
208
+
197
209
  ### Moderations
198
210
 
199
211
  Pass a string to check if it violates OpenAI's Content Policy:
@@ -260,7 +272,7 @@ Or use the ID of a file you've uploaded:
260
272
 
261
273
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
262
274
 
263
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, update `CHANGELOG.md`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
275
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, update `CHANGELOG.md`, run `bundle install` to update Gemfile.lock, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
264
276
 
265
277
  ## Contributing
266
278
 
@@ -8,10 +8,18 @@ module OpenAI
8
8
  end
9
9
 
10
10
  def answers(version: default_version, parameters: {})
11
+ warn "[DEPRECATION WARNING] [ruby-openai] `Client#answers` is deprecated and will
12
+ be removed from the OpenAI API on 3 December 2022 and from ruby-openai v3.0.
13
+ More information: https://help.openai.com/en/articles/6233728-answers-transition-guide"
14
+
11
15
  post(url: "/#{version}/answers", parameters: parameters)
12
16
  end
13
17
 
14
18
  def classifications(version: default_version, parameters: {})
19
+ warn "[DEPRECATION WARNING] [ruby-openai] `Client#classifications` is deprecated and will
20
+ be removed from the OpenAI API on 3 December 2022 and from ruby-openai v3.0.
21
+ More information: https://help.openai.com/en/articles/6272941-classifications-transition-guide"
22
+
15
23
  post(url: "/#{version}/classifications", parameters: parameters)
16
24
  end
17
25
 
@@ -46,6 +54,10 @@ module OpenAI
46
54
  @finetunes ||= OpenAI::Finetunes.new(access_token: @access_token)
47
55
  end
48
56
 
57
+ def images
58
+ @images ||= OpenAI::Images.new(access_token: @access_token)
59
+ end
60
+
49
61
  def models
50
62
  @models ||= OpenAI::Models.new(access_token: @access_token)
51
63
  end
@@ -0,0 +1,27 @@
1
+ module OpenAI
2
+ class Images
3
+ include HTTParty
4
+ base_uri "https://api.openai.com"
5
+
6
+ def initialize(access_token: nil)
7
+ @access_token = access_token || ENV.fetch("OPENAI_ACCESS_TOKEN")
8
+ end
9
+
10
+ def generate(version: default_version, parameters: {})
11
+ self.class.post(
12
+ "/#{version}/images/generations",
13
+ headers: {
14
+ "Content-Type" => "application/json",
15
+ "Authorization" => "Bearer #{@access_token}"
16
+ },
17
+ body: parameters.to_json
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ def default_version
24
+ "v1".freeze
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module OpenAI
3
- VERSION = "2.0.0".freeze
3
+ VERSION = "2.1.0".freeze
4
4
  end
5
5
  end
data/lib/ruby/openai.rb CHANGED
@@ -2,6 +2,7 @@ require "httparty"
2
2
  require "ruby/openai/engines"
3
3
  require "ruby/openai/files"
4
4
  require "ruby/openai/finetunes"
5
+ require "ruby/openai/images"
5
6
  require "ruby/openai/models"
6
7
  require "ruby/openai/client"
7
8
  require "ruby/openai/version"
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: 2.0.0
4
+ version: 2.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: 2022-09-19 00:00:00.000000000 Z
11
+ date: 2022-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -80,6 +80,7 @@ files:
80
80
  - lib/ruby/openai/engines.rb
81
81
  - lib/ruby/openai/files.rb
82
82
  - lib/ruby/openai/finetunes.rb
83
+ - lib/ruby/openai/images.rb
83
84
  - lib/ruby/openai/models.rb
84
85
  - lib/ruby/openai/version.rb
85
86
  - pull_request_template.md