quick_openai 0.1.0 → 0.1.2

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: c100b819268f04a4bf818f9b011a35d0fce11652398bdab7d837594eefa09ecb
4
- data.tar.gz: 2b8d7e92373f869306c6c02e4194635b7676422a8362239df619f47ea9c8a7d5
3
+ metadata.gz: 29998848a279d5254494c77b0381b039d2e9dc0171f4740953cbeab517a9e9f6
4
+ data.tar.gz: 9d44c2630df9557fc3c26cfb9058ec4d4082c74d12df674187a7e4701fd9740a
5
5
  SHA512:
6
- metadata.gz: 63970fcd91f0802d14ce0fcdd62ae515f6d73d2076f0450c67131ea19b689466b06901d0b7e0473f9579aedc8da0fa8f0a03e0fdab01718e030ecd1701220ab4
7
- data.tar.gz: e268e1471966d8adad75b3ea609df8faa562f5aadb5948ffa80ebec1c89ce6420b2c63c6e2911449e2dc0bc85560172c4e4a1df151c5690d56341de9a270011b
6
+ metadata.gz: f05ad7ba4632fafb68cf8e2e156e18d5bd5af12e7e2fb4c96cc7e5430cce5ee46d7f34939e3503653fd9d25bfe8e125bbbfd6e93bea9d9d53e3eab16503f6186
7
+ data.tar.gz: 7b40b2825d4e0b5e4563f8dbeb91aa44e44e6f1952197899a190625789fda06e5079e6cb49d0c09925619e987bc25833ecccf32b4091d7f5727458f30fe8b197
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: 2.6
3
+ TargetRubyVersion: 2.7
4
4
 
5
5
  Style/StringLiterals:
6
6
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quick_openai (0.1.0)
4
+ quick_openai (0.1.2)
5
5
  down (~> 5)
6
- ruby-openai (~> 2)
6
+ ruby-openai (~> 3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -13,15 +13,13 @@ GEM
13
13
  ast (2.4.2)
14
14
  diff-lcs (1.5.0)
15
15
  dotenv (2.8.1)
16
- down (5.3.1)
16
+ down (5.4.0)
17
17
  addressable (~> 2.8)
18
- httparty (0.20.0)
19
- mime-types (~> 3.0)
18
+ httparty (0.21.0)
19
+ mini_mime (>= 1.0.0)
20
20
  multi_xml (>= 0.5.2)
21
21
  json (2.6.3)
22
- mime-types (3.4.1)
23
- mime-types-data (~> 3.2015)
24
- mime-types-data (3.2022.0105)
22
+ mini_mime (1.1.2)
25
23
  multi_xml (0.6.0)
26
24
  parallel (1.22.1)
27
25
  parser (3.1.3.0)
@@ -56,9 +54,8 @@ GEM
56
54
  unicode-display_width (>= 1.4.0, < 3.0)
57
55
  rubocop-ast (1.24.0)
58
56
  parser (>= 3.1.1.0)
59
- ruby-openai (2.1.0)
60
- dotenv (>= 2.7.6, < 2.9.0)
61
- httparty (>= 0.18.1, < 0.21.0)
57
+ ruby-openai (3.0.3)
58
+ httparty (>= 0.18.1, < 0.22.0)
62
59
  ruby-progressbar (1.11.0)
63
60
  unicode-display_width (2.3.0)
64
61
  vcr (6.1.0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QuickOpenAI
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/quick_openai.rb CHANGED
@@ -8,22 +8,38 @@ require_relative "quick_openai/extensions/string"
8
8
  module QuickOpenAI
9
9
  class Error < StandardError; end
10
10
 
11
- def self.client
12
- OpenAI::Client.new
13
- end
11
+ class << self
12
+ def client
13
+ OpenAI::Client.new(access_token: ENV["OPENAI_ACCESS_TOKEN"])
14
+ end
15
+
16
+ def fetch_response_from_client
17
+ ensure_access_token!
14
18
 
15
- def self.fetch_response_from_client
16
- begin
17
- response = yield client
18
- rescue StandardError
19
- raise QuickOpenAI::Error, "Unable to fetch response."
19
+ begin
20
+ response = yield client
21
+ rescue StandardError
22
+ raise QuickOpenAI::Error, "Unable to fetch response."
23
+ end
24
+
25
+ ensure_no_error!(response)
26
+
27
+ response
20
28
  end
21
29
 
22
- if (error = response.dig("error", "message"))
23
- raise QuickOpenAI::Error, "Unable to fetch response: #{error}"
30
+ private
31
+
32
+ def ensure_access_token!
33
+ return if ENV.key?("OPENAI_ACCESS_TOKEN")
34
+
35
+ raise QuickOpenAI::Error, "Make sure OPENAI_ACCESS_TOKEN is present in ENV."
24
36
  end
25
37
 
26
- response
38
+ def ensure_no_error!(response)
39
+ return unless (error = response.dig("error", "message"))
40
+
41
+ raise QuickOpenAI::Error, "Unable to fetch response: #{error}"
42
+ end
27
43
  end
28
44
  end
29
45
 
@@ -0,0 +1,37 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick_openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John DeSilva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-23 00:00:00.000000000 Z
11
+ date: 2023-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2'
33
+ version: '3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2'
40
+ version: '3'
41
41
  description: Provides monkey patches for quick usage of GPT3 and DALLE2
42
42
  email:
43
43
  - desilvjo@umich.edu
@@ -59,6 +59,7 @@ files:
59
59
  - lib/quick_openai/extensions/string.rb
60
60
  - lib/quick_openai/gpt3.rb
61
61
  - lib/quick_openai/version.rb
62
+ - quick_openai.gemspec
62
63
  - sig/quick_openai.rbs
63
64
  homepage: https://github.com/Aesthetikx/quick_openai
64
65
  licenses: