openai-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +202 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +120 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +12 -0
- data/lib/openai/client/configurable.rb +31 -0
- data/lib/openai/client/configuration.rb +17 -0
- data/lib/openai/client/http.rb +65 -0
- data/lib/openai/client/models.rb +31 -0
- data/lib/openai/client/version.rb +7 -0
- data/lib/openai/client.rb +28 -0
- data/openai-client.gemspec +32 -0
- data/sig/openai/client.rbs +6 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 89cfd9978fd03cfbd1580f34402a26cf624e5f5b46267ad7983e86e9bbaa78bc
|
4
|
+
data.tar.gz: 5886fa8d3e043516ec07616c1559c2b5859914a374c438dd32cf92a714f81cf0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fca94f728f9a718ee9d68e979be51c2f845879ba9b07d6fe049f9de378c0462ab883f223dd3a11b63f430379d9200cba53273b94bb20b669ccd73041484370f6
|
7
|
+
data.tar.gz: bc9c9298f3734d40239eab52a33ed8642f1759dd0f5152f7ef6ac8490b055f4e8b2752e202cc075650a9d458e67c8eae34329e32df0fb6d6fb5bd8061d094896
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.6
|
7
|
+
NewCops: enable
|
8
|
+
Layout/EmptyLinesAroundClassBody:
|
9
|
+
Enabled: false
|
10
|
+
Layout/EmptyLinesAroundMethodBody:
|
11
|
+
Enabled: false
|
12
|
+
Layout/EmptyLinesAroundModuleBody:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
# Checks that the indentation of method names for calls that span lines is relative to what the call is made on.
|
16
|
+
Layout/MultilineMethodCallIndentation:
|
17
|
+
EnforcedStyle: indented_relative_to_receiver
|
18
|
+
|
19
|
+
# Checks that there is exactly one space between a method and it's first argument when parentheses are not used.
|
20
|
+
# Not enforced.
|
21
|
+
Layout/SpaceBeforeFirstArg:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
# Use spaces inside hash literal braces. Not enforced.
|
25
|
+
Layout/SpaceInsideHashLiteralBraces:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
# Maximum line length of 120 chars
|
29
|
+
Layout/LineLength:
|
30
|
+
Max: 120
|
31
|
+
|
32
|
+
# Disabled since MFA is not supported for internal rubygems
|
33
|
+
Gemspec/RequireMFA:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# -------------------------------------------------------- Lint --------------------------------------------------------
|
37
|
+
|
38
|
+
# Don't use assignment in conditions. Not enforced, since this is occasionally useful.
|
39
|
+
Lint/AssignmentInCondition:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Naming/MethodParameterName:
|
43
|
+
MinNameLength: 1
|
44
|
+
|
45
|
+
Lint/ScriptPermission:
|
46
|
+
Exclude:
|
47
|
+
- "Rakefile"
|
48
|
+
|
49
|
+
# ------------------------------------------------------- Naming -------------------------------------------------------
|
50
|
+
|
51
|
+
# Ensure numbered variables use snake_case, i.e. variable_1.
|
52
|
+
Naming/VariableNumber:
|
53
|
+
EnforcedStyle: snake_case
|
54
|
+
Naming/MemoizedInstanceVariableName:
|
55
|
+
EnforcedStyleForLeadingUnderscores: optional
|
56
|
+
|
57
|
+
# ------------------------------------------------------- Metrics ------------------------------------------------------
|
58
|
+
|
59
|
+
# Counts the number of assignments, branches (including method calls), and conditions, keeps it below a maximum.
|
60
|
+
# Not enforced.
|
61
|
+
Metrics/AbcSize:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
# Avoid blocks longer than 25 lines of code, except for RSpec's DSL
|
65
|
+
Metrics/BlockLength:
|
66
|
+
Max: 25
|
67
|
+
Exclude:
|
68
|
+
- "**/spec_helper.rb"
|
69
|
+
IgnoredMethods:
|
70
|
+
- after
|
71
|
+
- before
|
72
|
+
- context
|
73
|
+
- describe
|
74
|
+
- feature
|
75
|
+
- it
|
76
|
+
- let
|
77
|
+
- scenario
|
78
|
+
- shared_examples
|
79
|
+
- shared_examples_for
|
80
|
+
|
81
|
+
# Restrict the number of lines in a class (not counting comments) to a maximum
|
82
|
+
Metrics/ClassLength:
|
83
|
+
Max: 150
|
84
|
+
|
85
|
+
# Avoid deep nesting
|
86
|
+
Metrics/CyclomaticComplexity:
|
87
|
+
Max: 10
|
88
|
+
|
89
|
+
# Avoid methods longer than 30 lines of code
|
90
|
+
Metrics/MethodLength:
|
91
|
+
Exclude:
|
92
|
+
- "spec/**/*"
|
93
|
+
Max: 30
|
94
|
+
|
95
|
+
# Do not apply the module length check to spec files.
|
96
|
+
Metrics/ModuleLength:
|
97
|
+
Exclude:
|
98
|
+
- "spec/**/*"
|
99
|
+
|
100
|
+
# Avoid parameter lists longer than three or four parameters. Not enforced.
|
101
|
+
Metrics/ParameterLists:
|
102
|
+
Enabled: false
|
103
|
+
|
104
|
+
# Tries to score methods for complexity, with some special cases around case..when statements.
|
105
|
+
# Not enforced (we use Metrics/CyclomaticComplexity instead).
|
106
|
+
Metrics/PerceivedComplexity:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# ------------------------------------------------------- Style --------------------------------------------------------
|
110
|
+
|
111
|
+
# Forces the use of the shortcut %() for single-line strings with interpolation and double quotes.
|
112
|
+
# Not enforced.
|
113
|
+
Style/BarePercentLiterals:
|
114
|
+
Enabled: false
|
115
|
+
|
116
|
+
# Always use {} for single line blocks and do..end for multi-line blocks
|
117
|
+
Style/BlockDelimiters:
|
118
|
+
EnforcedStyle: line_count_based
|
119
|
+
|
120
|
+
# There are two styles for defining class/module hierarchies
|
121
|
+
# class Alpha
|
122
|
+
# class Beta
|
123
|
+
# end
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# class Alpha::Beta
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# Allow both (not enforced).
|
130
|
+
Style/ClassAndModuleChildren:
|
131
|
+
Enabled: false
|
132
|
+
|
133
|
+
# Forces consistent use of is_a? vs kind_of?
|
134
|
+
# Not enforced.
|
135
|
+
Style/ClassCheck:
|
136
|
+
Enabled: false
|
137
|
+
|
138
|
+
# Document classes and non-namespace modules. Not enforced.
|
139
|
+
Style/Documentation:
|
140
|
+
Enabled: false
|
141
|
+
|
142
|
+
# Disallows !!variable to convert variable to a boolean
|
143
|
+
# Not enforced.
|
144
|
+
Style/DoubleNegation:
|
145
|
+
Enabled: false
|
146
|
+
|
147
|
+
# Checks that empty method definitions have 'end' on a separate line.
|
148
|
+
Style/EmptyMethod:
|
149
|
+
EnforcedStyle: expanded
|
150
|
+
|
151
|
+
# Disallows guard clauses.
|
152
|
+
# Not enforced because it conflicts with removing Style/MultilineIfModifier.
|
153
|
+
Style/GuardClause:
|
154
|
+
Enabled: false
|
155
|
+
|
156
|
+
# Disallows trailing comments on any line with code in it.
|
157
|
+
# Not enforced.
|
158
|
+
Style/InlineComment:
|
159
|
+
Enabled: false
|
160
|
+
|
161
|
+
# Favor unless over if for negative conditions (or control flow or). Not enforced.
|
162
|
+
Style/NegatedIf:
|
163
|
+
Enabled: false
|
164
|
+
|
165
|
+
# Checks that the next keyword is used rather than a condition to skip the body of a loop
|
166
|
+
# Not enforced.
|
167
|
+
Style/Next:
|
168
|
+
Enabled: false
|
169
|
+
|
170
|
+
# Uses slashes for single-line regexes, and %r for multiline regexes or regexes with inner slashes.
|
171
|
+
Style/RegexpLiteral:
|
172
|
+
EnforcedStyle: mixed
|
173
|
+
|
174
|
+
# Always use 'raise' command, never 'fail'
|
175
|
+
Style/SignalException:
|
176
|
+
EnforcedStyle: only_raise
|
177
|
+
|
178
|
+
# Use symbols as procs whenever possible. Instead of
|
179
|
+
# arr.map { |x| x.id }
|
180
|
+
# use
|
181
|
+
# arr.map(&:id)
|
182
|
+
# Not enforced.
|
183
|
+
Style/SymbolProc:
|
184
|
+
Enabled: false
|
185
|
+
|
186
|
+
# Use %w or %W for arrays of words. Not enforced.
|
187
|
+
Style/WordArray:
|
188
|
+
Enabled: false
|
189
|
+
EnforcedStyle: percent
|
190
|
+
|
191
|
+
# Call super to initialize state of the parent class.
|
192
|
+
Lint/MissingSuper:
|
193
|
+
Enabled: false
|
194
|
+
|
195
|
+
# ------------------------------------------------------- RSpec --------------------------------------------------------
|
196
|
+
RSpec/MultipleMemoizedHelpers:
|
197
|
+
Max: 15
|
198
|
+
|
199
|
+
# Disable "Maximum example group nesting exceeded"
|
200
|
+
# Disabling this will allow us to have more verbose specs, and easier to understand and structure
|
201
|
+
RSpec/NestedGroups:
|
202
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in openai-client.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'byebug'
|
10
|
+
gem 'faker', '~> 2.0'
|
11
|
+
gem 'rake', '~> 13.0'
|
12
|
+
gem 'rspec', '~> 3.0'
|
13
|
+
gem 'rubocop', '~> 1.21'
|
14
|
+
gem 'rubocop-performance', '~> 1.12'
|
15
|
+
gem 'rubocop-rspec', '~> 2.6'
|
16
|
+
gem 'webmock', '~> 3.12'
|
17
|
+
gem 'yard', '~> 0.9'
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
openai-client (0.1.0)
|
5
|
+
faraday (~> 1.8)
|
6
|
+
faraday_middleware (~> 1.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.1)
|
12
|
+
public_suffix (>= 2.0.2, < 6.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
byebug (11.1.3)
|
15
|
+
concurrent-ruby (1.2.0)
|
16
|
+
crack (0.4.5)
|
17
|
+
rexml
|
18
|
+
diff-lcs (1.5.0)
|
19
|
+
faker (2.23.0)
|
20
|
+
i18n (>= 1.8.11, < 2)
|
21
|
+
faraday (1.10.3)
|
22
|
+
faraday-em_http (~> 1.0)
|
23
|
+
faraday-em_synchrony (~> 1.0)
|
24
|
+
faraday-excon (~> 1.1)
|
25
|
+
faraday-httpclient (~> 1.0)
|
26
|
+
faraday-multipart (~> 1.0)
|
27
|
+
faraday-net_http (~> 1.0)
|
28
|
+
faraday-net_http_persistent (~> 1.0)
|
29
|
+
faraday-patron (~> 1.0)
|
30
|
+
faraday-rack (~> 1.0)
|
31
|
+
faraday-retry (~> 1.0)
|
32
|
+
ruby2_keywords (>= 0.0.4)
|
33
|
+
faraday-em_http (1.0.0)
|
34
|
+
faraday-em_synchrony (1.0.0)
|
35
|
+
faraday-excon (1.1.0)
|
36
|
+
faraday-httpclient (1.0.1)
|
37
|
+
faraday-multipart (1.0.4)
|
38
|
+
multipart-post (~> 2)
|
39
|
+
faraday-net_http (1.0.1)
|
40
|
+
faraday-net_http_persistent (1.2.0)
|
41
|
+
faraday-patron (1.0.0)
|
42
|
+
faraday-rack (1.0.0)
|
43
|
+
faraday-retry (1.0.3)
|
44
|
+
faraday_middleware (1.2.0)
|
45
|
+
faraday (~> 1.0)
|
46
|
+
hashdiff (1.0.1)
|
47
|
+
i18n (1.12.0)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
json (2.6.3)
|
50
|
+
multipart-post (2.3.0)
|
51
|
+
parallel (1.22.1)
|
52
|
+
parser (3.2.0.0)
|
53
|
+
ast (~> 2.4.1)
|
54
|
+
public_suffix (5.0.1)
|
55
|
+
rainbow (3.1.1)
|
56
|
+
rake (13.0.6)
|
57
|
+
regexp_parser (2.6.2)
|
58
|
+
rexml (3.2.5)
|
59
|
+
rspec (3.12.0)
|
60
|
+
rspec-core (~> 3.12.0)
|
61
|
+
rspec-expectations (~> 3.12.0)
|
62
|
+
rspec-mocks (~> 3.12.0)
|
63
|
+
rspec-core (3.12.1)
|
64
|
+
rspec-support (~> 3.12.0)
|
65
|
+
rspec-expectations (3.12.2)
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
+
rspec-support (~> 3.12.0)
|
68
|
+
rspec-mocks (3.12.3)
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
+
rspec-support (~> 3.12.0)
|
71
|
+
rspec-support (3.12.0)
|
72
|
+
rubocop (1.44.1)
|
73
|
+
json (~> 2.3)
|
74
|
+
parallel (~> 1.10)
|
75
|
+
parser (>= 3.2.0.0)
|
76
|
+
rainbow (>= 2.2.2, < 4.0)
|
77
|
+
regexp_parser (>= 1.8, < 3.0)
|
78
|
+
rexml (>= 3.2.5, < 4.0)
|
79
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
80
|
+
ruby-progressbar (~> 1.7)
|
81
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
82
|
+
rubocop-ast (1.24.1)
|
83
|
+
parser (>= 3.1.1.0)
|
84
|
+
rubocop-capybara (2.17.0)
|
85
|
+
rubocop (~> 1.41)
|
86
|
+
rubocop-performance (1.15.2)
|
87
|
+
rubocop (>= 1.7.0, < 2.0)
|
88
|
+
rubocop-ast (>= 0.4.0)
|
89
|
+
rubocop-rspec (2.18.1)
|
90
|
+
rubocop (~> 1.33)
|
91
|
+
rubocop-capybara (~> 2.17)
|
92
|
+
ruby-progressbar (1.11.0)
|
93
|
+
ruby2_keywords (0.0.5)
|
94
|
+
unicode-display_width (2.4.2)
|
95
|
+
webmock (3.18.1)
|
96
|
+
addressable (>= 2.8.0)
|
97
|
+
crack (>= 0.3.2)
|
98
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
99
|
+
webrick (1.7.0)
|
100
|
+
yard (0.9.28)
|
101
|
+
webrick (~> 1.7.0)
|
102
|
+
|
103
|
+
PLATFORMS
|
104
|
+
ruby
|
105
|
+
x86_64-darwin-22
|
106
|
+
|
107
|
+
DEPENDENCIES
|
108
|
+
byebug
|
109
|
+
faker (~> 2.0)
|
110
|
+
openai-client!
|
111
|
+
rake (~> 13.0)
|
112
|
+
rspec (~> 3.0)
|
113
|
+
rubocop (~> 1.21)
|
114
|
+
rubocop-performance (~> 1.12)
|
115
|
+
rubocop-rspec (~> 2.6)
|
116
|
+
webmock (~> 3.12)
|
117
|
+
yard (~> 0.9)
|
118
|
+
|
119
|
+
BUNDLED WITH
|
120
|
+
2.4.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Ihor Tykhonenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Openai::Client
|
2
|
+
This gem is a wrapper for calling the OpenAI and GPT-3 APIs.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
```ruby
|
7
|
+
gem 'openai-client'
|
8
|
+
```
|
9
|
+
And then execute:
|
10
|
+
```bash
|
11
|
+
bundle
|
12
|
+
```
|
13
|
+
Or install it yourself as:
|
14
|
+
```bash
|
15
|
+
gem install openai-client
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
- API key (`access_token`) https://beta.openai.com/account/api-keys.
|
20
|
+
- Organization ID (if needed) https://beta.openai.com/account/org-settings.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'openai-client'
|
24
|
+
|
25
|
+
Openai::Client.configure do |c|
|
26
|
+
c.access_token = 'access_token'
|
27
|
+
c.organization_id = 'organization_id' # optional
|
28
|
+
end
|
29
|
+
|
30
|
+
# Models
|
31
|
+
Openai::Client.models.list
|
32
|
+
|
33
|
+
# Find a Model
|
34
|
+
Openai::Client.models.find(model_id)
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/itikhonenko/openai-client.
|
39
|
+
|
40
|
+
## License
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Client
|
5
|
+
module Configurable
|
6
|
+
# @api public
|
7
|
+
# Public: Returns the instance of Configuration class
|
8
|
+
#
|
9
|
+
# @return [Openai::Client::Configuration] instance of Configuration class
|
10
|
+
def configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# @api public
|
15
|
+
# Public: Allows to provide configuration values
|
16
|
+
#
|
17
|
+
# @return [Openai::Client::Configuration] instance of Configuration class
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
# Openai::Client.configure do |c|
|
21
|
+
# c.logger = Rails.logger
|
22
|
+
# c.access_token = 'access_token_goes_here'
|
23
|
+
# c.organization_id = 'organization_id_goes_here'
|
24
|
+
# c.openai_url = 'https://api.openai.com/v1'
|
25
|
+
# end
|
26
|
+
def configure
|
27
|
+
yield(configuration)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Client
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :logger, :access_token, :organization_id, :openai_url
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@openai_url = 'https://api.openai.com/v1'
|
10
|
+
@access_token = nil
|
11
|
+
@organization_id = nil
|
12
|
+
@organization_id = nil
|
13
|
+
@logger = Logger.new($stdout)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Client
|
5
|
+
class Http
|
6
|
+
def initialize
|
7
|
+
@connection = Faraday.new(url: Openai::Client.configuration.openai_url, headers: headers) do |conn|
|
8
|
+
conn.response :json
|
9
|
+
conn.response :raise_error
|
10
|
+
conn.request :json
|
11
|
+
end
|
12
|
+
@logger = Openai::Client.configuration.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
# @api public
|
16
|
+
# Public: Makes a GET request using the Faraday HTTP Client.
|
17
|
+
#
|
18
|
+
# @param [String] path API path
|
19
|
+
# @param [String] query_params query params
|
20
|
+
#
|
21
|
+
# @raise [Faraday::Error] on failure API call
|
22
|
+
#
|
23
|
+
# @return [Faraday::Response] instance of Faraday::Response class
|
24
|
+
def get(path, query_params = {})
|
25
|
+
connection.get(path, query_params)
|
26
|
+
rescue Faraday::Error => e
|
27
|
+
log_error(e) && raise
|
28
|
+
end
|
29
|
+
|
30
|
+
# @api public
|
31
|
+
# Public: Makes a POST request using the Faraday HTTP Client.
|
32
|
+
#
|
33
|
+
# @param [String] path API path
|
34
|
+
# @param [Hash] body request body
|
35
|
+
#
|
36
|
+
# @raise [Faraday::Error] on failure API call
|
37
|
+
#
|
38
|
+
# @return [Faraday::Response] instance of Faraday::Response class
|
39
|
+
def post(path, body = {})
|
40
|
+
connection.post(path, body)
|
41
|
+
rescue Faraday::Error => e
|
42
|
+
log_error(e) && raise
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
attr_reader :connection, :logger
|
48
|
+
|
49
|
+
# @api private
|
50
|
+
# Internal: Logs failure API calls.
|
51
|
+
#
|
52
|
+
# @param [Faraday::Error] e the error to log
|
53
|
+
def log_error(e)
|
54
|
+
logger.error("Error response, status: #{e.response[:status]}, body: #{e.response[:body]}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def headers
|
58
|
+
{
|
59
|
+
'Authorization' => "Bearer #{Openai::Client.configuration.access_token}",
|
60
|
+
'OpenAI-Organization' => Openai::Client.configuration.organization_id
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Client
|
5
|
+
class Models
|
6
|
+
PATH = 'models'
|
7
|
+
|
8
|
+
# @api public
|
9
|
+
# Public: Makes an API call to return all models.
|
10
|
+
#
|
11
|
+
# @return [Hash] a hash with models
|
12
|
+
def list
|
13
|
+
Http.new.get(PATH).body
|
14
|
+
rescue StandardError
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
# @api public
|
19
|
+
# Public: Makes an API call to find the model by the ID.
|
20
|
+
#
|
21
|
+
# @param [String] id model id
|
22
|
+
#
|
23
|
+
# @return [Hash] found model or nil
|
24
|
+
def find(id)
|
25
|
+
Http.new.get("#{PATH}/#{id}").body
|
26
|
+
rescue StandardError
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
require 'openai/client/version'
|
8
|
+
require 'openai/client/configuration'
|
9
|
+
require 'openai/client/configurable'
|
10
|
+
require 'openai/client/http'
|
11
|
+
require 'openai/client/models'
|
12
|
+
|
13
|
+
module Openai
|
14
|
+
module Client
|
15
|
+
extend Configurable
|
16
|
+
|
17
|
+
ATTRS = ['models'].freeze
|
18
|
+
|
19
|
+
class << self
|
20
|
+
ATTRS.each do |attr|
|
21
|
+
define_method(attr) do
|
22
|
+
instance_variable_get("@#{attr}") || instance_variable_set("@#{attr}",
|
23
|
+
const_get(attr.capitalize, self).new)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/openai/client/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'openai-client'
|
7
|
+
spec.version = Openai::Client::VERSION
|
8
|
+
spec.authors = ['itikhonenko']
|
9
|
+
spec.email = ['tikhonenkoigor@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A Ruby gem for the OpenAI GPT-3 API'
|
12
|
+
spec.homepage = 'https://github.com/itikhonenko/openai-client'
|
13
|
+
spec.required_ruby_version = '>= 2.6.0'
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
17
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/README.md"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency('faraday', '~> 1.8')
|
31
|
+
spec.add_dependency('faraday_middleware', '~> 1.2')
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openai-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- itikhonenko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- tikhonenkoigor@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- CHANGELOG.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/openai/client.rb
|
57
|
+
- lib/openai/client/configurable.rb
|
58
|
+
- lib/openai/client/configuration.rb
|
59
|
+
- lib/openai/client/http.rb
|
60
|
+
- lib/openai/client/models.rb
|
61
|
+
- lib/openai/client/version.rb
|
62
|
+
- openai-client.gemspec
|
63
|
+
- sig/openai/client.rbs
|
64
|
+
homepage: https://github.com/itikhonenko/openai-client
|
65
|
+
licenses: []
|
66
|
+
metadata:
|
67
|
+
homepage_uri: https://github.com/itikhonenko/openai-client
|
68
|
+
source_code_uri: https://github.com/itikhonenko/openai-client
|
69
|
+
changelog_uri: https://github.com/itikhonenko/openai-client/blob/main/README.md
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.6.0
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.1.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: A Ruby gem for the OpenAI GPT-3 API
|
89
|
+
test_files: []
|