ruby-openai 3.2.0 → 3.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: 9e8ff1d30efd244fc448e8f473834796b8b02b627a5a4fc4edfdb79062119cfd
4
- data.tar.gz: dfd511d71c4a8d351e298cb6759bc876467840c70d073b0835259d18a4e4aa6e
3
+ metadata.gz: f31dd3158125262e5c187ee9503b21a9e9c0f423440c8da7a54e6abfaa932da3
4
+ data.tar.gz: 1c80b95c3d6587c3ddf95145f970690bf83572ef24902b455d126e2205f42c0d
5
5
  SHA512:
6
- metadata.gz: 6df6919af3e66c044d7309f6f7272078a12a2532702ced4175365b9ca618b7f6cac88e8aa7d84ed9884fea053d032505b9b1a3be8f7a39cb47c056e2e7a87849
7
- data.tar.gz: 529f048e9a35a7169f688cc49bb78a68b5787919c716dcb8c4017357db3124ed637314c931578b05aeedc76c72045c8f3144682c32f2a3879188270cbe7eae8d
6
+ metadata.gz: 9c8e2185a4c2822a54aaeaaa6eca5034e01c2796010df65d4ac7688e70e19da7546e120a64eed8bd3bb30417be54492570a5713d2ba3b684778e508b053cc0d3
7
+ data.tar.gz: d0d9a8aade92949b509882fe699809b659bc82ddf79ba54485f7d6e304abcfecf50e20dae18fa3df4bda5b41d364a6519f24d27e7177a64d773f7e408b644d23
data/.rubocop.yml CHANGED
@@ -9,6 +9,8 @@ Style/Documentation:
9
9
 
10
10
  Layout/LineLength:
11
11
  Max: 100
12
+ Exclude:
13
+ - "**/*.gemspec"
12
14
 
13
15
  Metrics/BlockLength:
14
16
  Exclude:
data/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ 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.3.0] - 2023-02-15
9
+
10
+ ### Changed
11
+
12
+ - Replace ::Ruby::OpenAI namespace with ::OpenAI - thanks [@kmcphillips](https://github.com/kmcphillips) for this work!
13
+ - To upgrade, change `require 'ruby/openai'` to `require 'openai'` and change all references to `Ruby::OpenAI` to `OpenAI`.
14
+
8
15
  ## [3.2.0] - 2023-02-13
9
16
 
10
17
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai (3.2.0)
4
+ ruby-openai (3.3.0)
5
5
  httparty (>= 0.18.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ruby::OpenAI
1
+ # Ruby OpenAI
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ruby-openai.svg)](https://badge.fury.io/rb/ruby-openai)
4
4
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexrudall/ruby-openai/blob/main/LICENSE.txt)
@@ -32,9 +32,13 @@ $ gem install ruby-openai
32
32
  and require with:
33
33
 
34
34
  ```ruby
35
- require "ruby/openai"
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
- Ruby::OpenAI.configure do |config|
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
@@ -274,4 +278,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
274
278
 
275
279
  ## Code of Conduct
276
280
 
277
- 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).
281
+ 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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "ruby/openai"
4
+ require "openai"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -3,8 +3,8 @@ module OpenAI
3
3
  URI_BASE = "https://api.openai.com/".freeze
4
4
 
5
5
  def initialize(access_token: nil, organization_id: nil)
6
- Ruby::OpenAI.configuration.access_token = access_token if access_token
7
- Ruby::OpenAI.configuration.organization_id = organization_id if organization_id
6
+ OpenAI.configuration.access_token = access_token if access_token
7
+ OpenAI.configuration.organization_id = organization_id if organization_id
8
8
  end
9
9
 
10
10
  def completions(parameters: {})
@@ -70,14 +70,14 @@ module OpenAI
70
70
  end
71
71
 
72
72
  private_class_method def self.uri(path:)
73
- URI_BASE + Ruby::OpenAI.configuration.api_version + path
73
+ URI_BASE + OpenAI.configuration.api_version + path
74
74
  end
75
75
 
76
76
  private_class_method def self.headers
77
77
  {
78
78
  "Content-Type" => "application/json",
79
- "Authorization" => "Bearer #{Ruby::OpenAI.configuration.access_token}",
80
- "OpenAI-Organization" => Ruby::OpenAI.configuration.organization_id
79
+ "Authorization" => "Bearer #{OpenAI.configuration.access_token}",
80
+ "OpenAI-Organization" => OpenAI.configuration.organization_id
81
81
  }
82
82
  end
83
83
  end
@@ -0,0 +1,9 @@
1
+ module Ruby
2
+ module OpenAI
3
+ VERSION = ::OpenAI::VERSION
4
+
5
+ Error = ::OpenAI::Error
6
+ ConfigurationError = ::OpenAI::ConfigurationError
7
+ Configuration = ::OpenAI::Configuration
8
+ end
9
+ end
@@ -1,8 +1,8 @@
1
1
  module OpenAI
2
2
  class Files
3
3
  def initialize(access_token: nil, organization_id: nil)
4
- Ruby::OpenAI.configuration.access_token = access_token if access_token
5
- Ruby::OpenAI.configuration.organization_id = organization_id if organization_id
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
- Ruby::OpenAI.configuration.access_token = access_token if access_token
5
- Ruby::OpenAI.configuration.organization_id = organization_id if organization_id
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
- Ruby::OpenAI.configuration.access_token = access_token if access_token
5
- Ruby::OpenAI.configuration.organization_id = organization_id if organization_id
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
- Ruby::OpenAI.configuration.access_token = access_token if access_token
5
- Ruby::OpenAI.configuration.organization_id = organization_id if organization_id
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
@@ -0,0 +1,3 @@
1
+ module OpenAI
2
+ VERSION = "3.3.0".freeze
3
+ end
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
- require "httparty"
2
- require "ruby/openai/client"
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/ruby/openai/version"
1
+ require_relative "lib/openai/version"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "ruby-openai"
5
- spec.version = Ruby::OpenAI::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.2.0
4
+ version: 3.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: 2023-02-13 00:00:00.000000000 Z
11
+ date: 2023-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -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
@@ -1,5 +0,0 @@
1
- module Ruby
2
- module OpenAI
3
- VERSION = "3.2.0".freeze
4
- end
5
- end