quick_openai 0.1.2 → 0.3.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: 29998848a279d5254494c77b0381b039d2e9dc0171f4740953cbeab517a9e9f6
4
- data.tar.gz: 9d44c2630df9557fc3c26cfb9058ec4d4082c74d12df674187a7e4701fd9740a
3
+ metadata.gz: d0c8f01b890c1bac117c4ec75c84cc42cedec5f392ffb53427902da947f38dae
4
+ data.tar.gz: 7c099581a01de52fbebba1c57c3900f819d78ee38c93277dd8e370327bba3fcc
5
5
  SHA512:
6
- metadata.gz: f05ad7ba4632fafb68cf8e2e156e18d5bd5af12e7e2fb4c96cc7e5430cce5ee46d7f34939e3503653fd9d25bfe8e125bbbfd6e93bea9d9d53e3eab16503f6186
7
- data.tar.gz: 7b40b2825d4e0b5e4563f8dbeb91aa44e44e6f1952197899a190625789fda06e5079e6cb49d0c09925619e987bc25833ecccf32b4091d7f5727458f30fe8b197
6
+ metadata.gz: 2911d2d5aa90500dbb47d5b9abcbf82baec63d9698beb5f631d29692ec5adb1988c480dfaae8f64da4fb455b3b2d8151b2b6fd99acf2fe7d99fc52784c01d712
7
+ data.tar.gz: 2d6c7a326874c9ede4e62f39c1055f701b2fc53b1daf1ed8cce57bb5f710279c00ca2de147e50ab114b0537d10125fcaf24e7abd2a32ed924f996748e76ebca2
data/.env.test CHANGED
@@ -1 +1 @@
1
- OPENAI_ACCESS_TOKEN=fakeopenaiaccesstoken
1
+ OPENAI_ACCESS_TOKEN=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
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: 2.7
3
+ TargetRubyVersion: 3.2
4
4
 
5
5
  Style/StringLiterals:
6
6
  Enabled: true
data/Gemfile CHANGED
@@ -14,3 +14,5 @@ gem "rspec", "~> 3.0"
14
14
  gem "rubocop", "~> 1.21"
15
15
 
16
16
  gem "vcr", "~> 6"
17
+
18
+ gem "webmock", "~> 3"
data/Gemfile.lock CHANGED
@@ -1,66 +1,98 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quick_openai (0.1.2)
4
+ quick_openai (0.3.0)
5
5
  down (~> 5)
6
- ruby-openai (~> 3)
6
+ ruby-openai (~> 8)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.8.1)
12
- public_suffix (>= 2.0.2, < 6.0)
13
- ast (2.4.2)
14
- diff-lcs (1.5.0)
15
- dotenv (2.8.1)
16
- down (5.4.0)
11
+ addressable (2.8.7)
12
+ public_suffix (>= 2.0.2, < 7.0)
13
+ ast (2.4.3)
14
+ base64 (0.2.0)
15
+ bigdecimal (3.1.9)
16
+ crack (1.0.0)
17
+ bigdecimal
18
+ rexml
19
+ diff-lcs (1.6.1)
20
+ dotenv (3.1.8)
21
+ down (5.4.2)
17
22
  addressable (~> 2.8)
18
- httparty (0.21.0)
19
- mini_mime (>= 1.0.0)
20
- multi_xml (>= 0.5.2)
21
- json (2.6.3)
22
- mini_mime (1.1.2)
23
- multi_xml (0.6.0)
24
- parallel (1.22.1)
25
- parser (3.1.3.0)
23
+ event_stream_parser (1.0.0)
24
+ faraday (2.13.0)
25
+ faraday-net_http (>= 2.0, < 3.5)
26
+ json
27
+ logger
28
+ faraday-multipart (1.1.0)
29
+ multipart-post (~> 2.0)
30
+ faraday-net_http (3.4.0)
31
+ net-http (>= 0.5.0)
32
+ hashdiff (1.1.2)
33
+ json (2.10.2)
34
+ language_server-protocol (3.17.0.4)
35
+ lint_roller (1.1.0)
36
+ logger (1.7.0)
37
+ multipart-post (2.4.1)
38
+ net-http (0.6.0)
39
+ uri
40
+ parallel (1.27.0)
41
+ parser (3.3.8.0)
26
42
  ast (~> 2.4.1)
27
- public_suffix (5.0.1)
43
+ racc
44
+ prism (1.4.0)
45
+ public_suffix (6.0.1)
46
+ racc (1.8.1)
28
47
  rainbow (3.1.1)
29
- rake (13.0.6)
30
- regexp_parser (2.6.1)
31
- rexml (3.2.5)
32
- rspec (3.12.0)
33
- rspec-core (~> 3.12.0)
34
- rspec-expectations (~> 3.12.0)
35
- rspec-mocks (~> 3.12.0)
36
- rspec-core (3.12.0)
37
- rspec-support (~> 3.12.0)
38
- rspec-expectations (3.12.0)
48
+ rake (13.2.1)
49
+ regexp_parser (2.10.0)
50
+ rexml (3.4.1)
51
+ rspec (3.13.0)
52
+ rspec-core (~> 3.13.0)
53
+ rspec-expectations (~> 3.13.0)
54
+ rspec-mocks (~> 3.13.0)
55
+ rspec-core (3.13.3)
56
+ rspec-support (~> 3.13.0)
57
+ rspec-expectations (3.13.3)
39
58
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.12.0)
41
- rspec-mocks (3.12.1)
59
+ rspec-support (~> 3.13.0)
60
+ rspec-mocks (3.13.2)
42
61
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.12.0)
44
- rspec-support (3.12.0)
45
- rubocop (1.40.0)
62
+ rspec-support (~> 3.13.0)
63
+ rspec-support (3.13.2)
64
+ rubocop (1.75.2)
46
65
  json (~> 2.3)
66
+ language_server-protocol (~> 3.17.0.2)
67
+ lint_roller (~> 1.1.0)
47
68
  parallel (~> 1.10)
48
- parser (>= 3.1.2.1)
69
+ parser (>= 3.3.0.2)
49
70
  rainbow (>= 2.2.2, < 4.0)
50
- regexp_parser (>= 1.8, < 3.0)
51
- rexml (>= 3.2.5, < 4.0)
52
- rubocop-ast (>= 1.23.0, < 2.0)
71
+ regexp_parser (>= 2.9.3, < 3.0)
72
+ rubocop-ast (>= 1.44.0, < 2.0)
53
73
  ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 1.4.0, < 3.0)
55
- rubocop-ast (1.24.0)
56
- parser (>= 3.1.1.0)
57
- ruby-openai (3.0.3)
58
- httparty (>= 0.18.1, < 0.22.0)
59
- ruby-progressbar (1.11.0)
60
- unicode-display_width (2.3.0)
61
- vcr (6.1.0)
74
+ unicode-display_width (>= 2.4.0, < 4.0)
75
+ rubocop-ast (1.44.1)
76
+ parser (>= 3.3.7.2)
77
+ prism (~> 1.4)
78
+ ruby-openai (8.1.0)
79
+ event_stream_parser (>= 0.3.0, < 2.0.0)
80
+ faraday (>= 1)
81
+ faraday-multipart (>= 1)
82
+ ruby-progressbar (1.13.0)
83
+ unicode-display_width (3.1.4)
84
+ unicode-emoji (~> 4.0, >= 4.0.4)
85
+ unicode-emoji (4.0.4)
86
+ uri (1.0.3)
87
+ vcr (6.3.1)
88
+ base64
89
+ webmock (3.25.1)
90
+ addressable (>= 2.8.0)
91
+ crack (>= 0.3.2)
92
+ hashdiff (>= 0.4.0, < 2.0.0)
62
93
 
63
94
  PLATFORMS
95
+ x86_64-freebsd-13
64
96
  x86_64-linux
65
97
 
66
98
  DEPENDENCIES
@@ -70,6 +102,7 @@ DEPENDENCIES
70
102
  rspec (~> 3.0)
71
103
  rubocop (~> 1.21)
72
104
  vcr (~> 6)
105
+ webmock (~> 3)
73
106
 
74
107
  BUNDLED WITH
75
108
  2.3.12
data/README.md CHANGED
@@ -4,17 +4,17 @@ This gem is a wrapper of [ruby-openai](https://github.com/alexrudall/ruby-openai
4
4
 
5
5
  ## Usage
6
6
 
7
- Quickly get results from GPT3:
7
+ Quickly get results from GPT:
8
8
 
9
9
  ```ruby
10
- puts "Hello, what is your name?".gpt3
10
+ puts "Hello, what is your name?".gpt
11
11
  # => My name is Aileen.
12
12
  ```
13
13
 
14
- Quickly get images from DALLE2:
14
+ Quickly get images from DALLE:
15
15
 
16
16
  ```ruby
17
- "a drawing of a cat in a hat".dalle2.then { |tempfile|
17
+ "a drawing of a cat in a hat".dalle.then { |tempfile|
18
18
  File.write('./cat.png', tempfile.read)
19
19
  }
20
20
  ```
@@ -44,14 +44,14 @@ require 'quick_openai'
44
44
  You can pass options supported by `ruby-openai` to the convenience methods:
45
45
 
46
46
  ```ruby
47
- "a drawing of a cat in a hat".dalle2(n: 2) # => An array of two tempfiles
47
+ "a drawing of a cat in a hat".dalle(n: 2) # => An array of two tempfiles
48
48
 
49
- "count to ten in italian".gpt3(model: 'text-ada-001') # Use a different model
49
+ "count to ten in italian".gpt(model: 'gpt-4.5-preview') # Use a different model
50
50
 
51
- "write me an essay on napoleon".gpt3(max_tokens: 2048) # Produce more or less output. The default is 2048.
51
+ "write me an essay on napoleon".gpt(max_tokens: 2048) # Produce more or less output. The default is 2048.
52
52
  ```
53
53
 
54
- Read more about GPT3 models [here](https://beta.openai.com/docs/models/gpt-3).
54
+ Read more about GPT models [here](https://beta.openai.com/docs/models/gpt-3).
55
55
 
56
56
  ## Development
57
57
 
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QuickOpenAI
4
+ module Dalle
5
+ class << self
6
+ def dalle2(prompt, **)
7
+ generic_dalle(prompt, **)
8
+ end
9
+
10
+ def dalle3(prompt, **)
11
+ default_size = "1024x1024"
12
+
13
+ generic_dalle(prompt, size: default_size, **)
14
+ end
15
+
16
+ alias dalle dalle3
17
+
18
+ private
19
+
20
+ def generic_dalle(prompt, **options)
21
+ parameters = {
22
+ prompt:,
23
+ **options
24
+ }
25
+
26
+ response = QuickOpenAI.fetch_response_from_client do |client|
27
+ client.images.generate(parameters:)
28
+ end
29
+
30
+ results = response.fetch("data")
31
+
32
+ tempfiles = results.map do |result|
33
+ url = result["url"]
34
+
35
+ Down.download(url)
36
+ end
37
+
38
+ if tempfiles.size == 1
39
+ tempfiles.first
40
+ else
41
+ tempfiles
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -3,13 +3,17 @@
3
3
  module QuickOpenAI
4
4
  module Extensions
5
5
  module String
6
- def gpt3(**options)
7
- QuickOpenAI::Gpt3.gpt3(self, **options)
8
- end
6
+ def gpt(**) = QuickOpenAI::Gpt.gpt(self, **)
9
7
 
10
- def dalle2(**options)
11
- QuickOpenAI::Dalle2.dalle2(self, **options)
12
- end
8
+ def gpt3(**) = QuickOpenAI::Gpt.gpt3(self, **)
9
+
10
+ def gpt4(**) = QuickOpenAI::Gpt.gpt4(self, **)
11
+
12
+ def dalle(**) = QuickOpenAI::Dalle.dalle(self, **)
13
+
14
+ def dalle2(**) = QuickOpenAI::Dalle.dalle2(self, **)
15
+
16
+ def dalle3(**) = QuickOpenAI::Dalle.dalle3(self, **)
13
17
  end
14
18
  end
15
19
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QuickOpenAI
4
+ module Gpt
5
+ class << self
6
+ def gpt3(prompt, **)
7
+ model = "gpt-3.5-turbo"
8
+
9
+ generic_gpt(prompt, model:, **)
10
+ end
11
+
12
+ def gpt4(prompt, **)
13
+ model = "gpt-4.1"
14
+
15
+ generic_gpt(prompt, model:, **)
16
+ end
17
+
18
+ alias gpt gpt4
19
+
20
+ private
21
+
22
+ def generic_gpt(prompt, **options)
23
+ parameters = {
24
+ max_tokens: 2048,
25
+ messages: [{ role: "user", content: prompt }],
26
+ **options
27
+ }
28
+
29
+ response = QuickOpenAI.fetch_response_from_client do |client|
30
+ client.chat(parameters:)
31
+ end
32
+
33
+ text = response.dig("choices", 0, "message", "content")
34
+
35
+ raise QuickOpenAI::Error, "Unable to parse response." if text.nil? || text.empty?
36
+
37
+ text.chomp.strip
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QuickOpenAI
4
- VERSION = "0.1.2"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/quick_openai.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "quick_openai/version"
4
- require_relative "quick_openai/dalle2"
5
- require_relative "quick_openai/gpt3"
4
+ require_relative "quick_openai/dalle"
5
+ require_relative "quick_openai/gpt"
6
6
  require_relative "quick_openai/extensions/string"
7
7
 
8
8
  module QuickOpenAI
@@ -10,7 +10,7 @@ module QuickOpenAI
10
10
 
11
11
  class << self
12
12
  def client
13
- OpenAI::Client.new(access_token: ENV["OPENAI_ACCESS_TOKEN"])
13
+ OpenAI::Client.new(access_token:)
14
14
  end
15
15
 
16
16
  def fetch_response_from_client
@@ -40,6 +40,10 @@ module QuickOpenAI
40
40
 
41
41
  raise QuickOpenAI::Error, "Unable to fetch response: #{error}"
42
42
  end
43
+
44
+ def access_token
45
+ ENV.fetch("OPENAI_ACCESS_TOKEN")
46
+ end
43
47
  end
44
48
  end
45
49
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick_openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John DeSilva
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-01-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: down
@@ -30,14 +29,14 @@ dependencies:
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '3'
32
+ version: '8'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '3'
39
+ version: '8'
41
40
  description: Provides monkey patches for quick usage of GPT3 and DALLE2
42
41
  email:
43
42
  - desilvjo@umich.edu
@@ -55,19 +54,18 @@ files:
55
54
  - README.md
56
55
  - Rakefile
57
56
  - lib/quick_openai.rb
58
- - lib/quick_openai/dalle2.rb
57
+ - lib/quick_openai/dalle.rb
59
58
  - lib/quick_openai/extensions/string.rb
60
- - lib/quick_openai/gpt3.rb
59
+ - lib/quick_openai/gpt.rb
61
60
  - lib/quick_openai/version.rb
62
- - quick_openai.gemspec
63
61
  - sig/quick_openai.rbs
64
62
  homepage: https://github.com/Aesthetikx/quick_openai
65
63
  licenses:
66
64
  - MIT
67
65
  metadata:
66
+ rubygems_mfa_required: 'true'
68
67
  homepage_uri: https://github.com/Aesthetikx/quick_openai
69
68
  source_code_uri: https://github.com/Aesthetikx/quick_openai
70
- post_install_message:
71
69
  rdoc_options: []
72
70
  require_paths:
73
71
  - lib
@@ -75,15 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
73
  requirements:
76
74
  - - ">="
77
75
  - !ruby/object:Gem::Version
78
- version: 2.7.0
76
+ version: '3.2'
79
77
  required_rubygems_version: !ruby/object:Gem::Requirement
80
78
  requirements:
81
79
  - - ">="
82
80
  - !ruby/object:Gem::Version
83
81
  version: '0'
84
82
  requirements: []
85
- rubygems_version: 3.3.7
86
- signing_key:
83
+ rubygems_version: 3.6.7
87
84
  specification_version: 4
88
85
  summary: Convenience extensions for using OpenAI with Ruby
89
86
  test_files: []
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module QuickOpenAI
4
- module Dalle2
5
- def self.dalle2(prompt, **options)
6
- parameters = {
7
- prompt: prompt,
8
- **options
9
- }
10
-
11
- response = QuickOpenAI.fetch_response_from_client do |client|
12
- client.images.generate(parameters: parameters)
13
- end
14
-
15
- results = response.fetch("data")
16
-
17
- tempfiles = results.map do |result|
18
- url = result["url"]
19
-
20
- Down.download(url)
21
- end
22
-
23
- if tempfiles.size == 1
24
- tempfiles.first
25
- else
26
- tempfiles
27
- end
28
- end
29
- end
30
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module QuickOpenAI
4
- module Gpt3
5
- def self.gpt3(prompt, **options)
6
- parameters = {
7
- model: "text-davinci-003",
8
- max_tokens: 2048,
9
- prompt: prompt,
10
- **options
11
- }
12
-
13
- response = QuickOpenAI.fetch_response_from_client do |client|
14
- client.completions(parameters: parameters)
15
- end
16
-
17
- text = response.dig("choices", 0, "text")
18
-
19
- raise QuickOpenAI::Error, "Unable to parse response." if text.nil? || text.empty?
20
-
21
- text.chomp.strip
22
- end
23
- end
24
- end
data/quick_openai.gemspec DELETED
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/quick_openai/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "quick_openai"
7
- spec.version = QuickOpenAI::VERSION
8
- spec.authors = ["John DeSilva"]
9
- spec.email = ["desilvjo@umich.edu"]
10
-
11
- spec.summary = "Convenience extensions for using OpenAI with Ruby"
12
- spec.description = "Provides monkey patches for quick usage of GPT3 and DALLE2"
13
- spec.homepage = "https://github.com/Aesthetikx/quick_openai"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.0"
16
-
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/Aesthetikx/quick_openai"
19
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(__dir__) do
24
- `git ls-files -z`.split("\x0").reject do |f|
25
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci|github)|appveyor)})
26
- end
27
- end
28
- spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
31
-
32
- spec.add_dependency "down", "~> 5"
33
- spec.add_dependency "ruby-openai", "~> 3"
34
-
35
- # For more information and examples about making a new gem, check out our
36
- # guide at: https://bundler.io/guides/creating_gem.html
37
- end