ruby-openai 2.2.0 → 2.3.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: 6b9c4dc42598004908a840d7f014259502f876df499c2bcfc93170e4fc44f729
4
- data.tar.gz: 4149a872b11219223412e9a1c8ce0e8f4c25706b75e30acb8c41ae80144cfd83
3
+ metadata.gz: e9f91687f2b4e37ef74018f8454392416afbe43ad08f5f8d671a1a9dc8feba82
4
+ data.tar.gz: 902a8bbd495d8ee56800f695aa3a264a8ded26475c11874040871b4765c8dacf
5
5
  SHA512:
6
- metadata.gz: b2dbfdb269b5cee46758307b32ad149ed198a994aa79274d1790e12c13c5505e6b7a126647725d8169204bea69b16b82f37e42a69903e20af9d3f5f5b07f5b51
7
- data.tar.gz: 5c75f720b3f329f4ef4d37ed7b768c7edc46b97de843687543e382b49db98fc0df730c3dbab068f05862e765be59a75c7efadc405f9864554db84246efe61ece
6
+ metadata.gz: 5b631c7f78b6de8d7c20acc61e4fc22eca4f372e488ba55e10267cedfd91c9b340334c69403fd28a26c71cfaa52678e7ea9c8410121139e9069abdadf5f37cf8
7
+ data.tar.gz: 40cb9e2f2848a954e5f786979d207a08b698ef6c5fb787afd564cd7945e5e758555ec2d99967a507bd2ae05b63ee8a7b518a197d8b2b6d39b19839c4398caf48
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
+ ## [2.3.0] - 2022-12-23
9
+
10
+ ### Added
11
+
12
+ - Add Images#edit and Images#variations endpoint to modify images with DALL·E.
13
+
8
14
  ## [2.2.0] - 2022-12-15
9
15
 
10
16
  ### Added
data/Gemfile CHANGED
@@ -6,6 +6,6 @@ gemspec
6
6
  gem "byebug", "~> 11.1.3"
7
7
  gem "rake", "~> 13.0"
8
8
  gem "rspec", "~> 3.12"
9
- gem "rubocop", "~> 1.40.0"
9
+ gem "rubocop", "~> 1.41.1"
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.2.0)
4
+ ruby-openai (2.3.0)
5
5
  dotenv (>= 2.7.6, < 2.9.0)
6
6
  httparty (>= 0.18.1, < 0.21.0)
7
7
 
@@ -46,7 +46,7 @@ GEM
46
46
  diff-lcs (>= 1.2.0, < 2.0)
47
47
  rspec-support (~> 3.12.0)
48
48
  rspec-support (3.12.0)
49
- rubocop (1.40.0)
49
+ rubocop (1.41.1)
50
50
  json (~> 2.3)
51
51
  parallel (~> 1.10)
52
52
  parser (>= 3.1.2.1)
@@ -73,7 +73,7 @@ DEPENDENCIES
73
73
  byebug (~> 11.1.3)
74
74
  rake (~> 13.0)
75
75
  rspec (~> 3.12)
76
- rubocop (~> 1.40.0)
76
+ rubocop (~> 1.41.1)
77
77
  ruby-openai!
78
78
  vcr (~> 6.1.0)
79
79
  webmock (~> 3.18.1)
data/README.md CHANGED
@@ -5,7 +5,9 @@
5
5
  [![CircleCI Build Status](https://circleci.com/gh/alexrudall/ruby-openai.svg?style=shield)](https://circleci.com/gh/alexrudall/ruby-openai)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
7
7
 
8
- Use the [OpenAI GPT-3 API](https://openai.com/blog/openai-api/) with Ruby! 🤖❤️
8
+ Use the [OpenAI API](https://openai.com/blog/openai-api/) with Ruby! 🤖❤️
9
+
10
+ Generate text with GPT-3, create images with DALL·E, or write code with Codex...
9
11
 
10
12
  ## Installation
11
13
 
@@ -199,7 +201,7 @@ This fine-tuned model name can then be used in classifications:
199
201
  JSON.parse(response.body)["choices"].map { |c| c["text"] }
200
202
  ```
201
203
 
202
- ### Images
204
+ ### Image Generation
203
205
 
204
206
  Generate an image using DALL·E!
205
207
 
@@ -209,7 +211,32 @@ Generate an image using DALL·E!
209
211
  => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
210
212
  ```
211
213
 
212
- ![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)
214
+ ![Ruby](https://i.ibb.co/6y4HJFx/img-d-Tx-Rf-RHj-SO5-Gho-Cbd8o-LJvw3.png)
215
+
216
+ ### Image Edit
217
+
218
+ Fill in the transparent part of an image, or upload a mask with transparent sections to indicate the parts of an image that can be changed according to your prompt...
219
+
220
+ ```ruby
221
+ response = client.images.edit(parameters: { prompt: "A solid red Ruby on a blue background", image: "image.png", mask: "mask.png" })
222
+ puts response.dig("data", 0, "url")
223
+ => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
224
+ ```
225
+
226
+ ![Ruby](https://i.ibb.co/sWVh3BX/dalle-ruby.png)
227
+
228
+ ### Image Variations
229
+
230
+ Create n variations of an image.
231
+
232
+ ```ruby
233
+ response = client.images.variations(parameters: { image: "image.png", n: 2 })
234
+ puts response.dig("data", 0, "url")
235
+ => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
236
+ ```
237
+
238
+ ![Ruby](https://i.ibb.co/TWJLP2y/img-miu-Wk-Nl0-QNy-Xtj-Lerc3c0l-NW.png)
239
+ ![Ruby](https://i.ibb.co/ScBhDGB/img-a9-Be-Rz-Au-Xwd-AV0-ERLUTSTGdi.png)
213
240
 
214
241
  ### Moderations
215
242
 
@@ -20,10 +20,44 @@ module OpenAI
20
20
  )
21
21
  end
22
22
 
23
+ def edit(version: default_version, parameters: {})
24
+ parameters = open_files(parameters)
25
+
26
+ self.class.post(
27
+ "/#{version}/images/edits",
28
+ headers: {
29
+ "Content-Type" => "application/json",
30
+ "Authorization" => "Bearer #{@access_token}",
31
+ "OpenAI-Organization" => @organization_id
32
+ },
33
+ body: parameters
34
+ )
35
+ end
36
+
37
+ def variations(version: default_version, parameters: {})
38
+ parameters = open_files(parameters)
39
+
40
+ self.class.post(
41
+ "/#{version}/images/variations",
42
+ headers: {
43
+ "Content-Type" => "application/json",
44
+ "Authorization" => "Bearer #{@access_token}",
45
+ "OpenAI-Organization" => @organization_id
46
+ },
47
+ body: parameters
48
+ )
49
+ end
50
+
23
51
  private
24
52
 
25
53
  def default_version
26
54
  "v1".freeze
27
55
  end
56
+
57
+ def open_files(parameters)
58
+ parameters = parameters.merge(image: File.open(parameters[:image]))
59
+ parameters = parameters.merge(mask: File.open(parameters[:mask])) if parameters[:mask]
60
+ parameters
61
+ end
28
62
  end
29
63
  end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module OpenAI
3
- VERSION = "2.2.0".freeze
3
+ VERSION = "2.3.0".freeze
4
4
  end
5
5
  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: 2.2.0
4
+ version: 2.3.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-12-15 00:00:00.000000000 Z
11
+ date: 2022-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv