openai-client 0.7.0 → 0.8.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: fa13b10a22961929472de3fc7cb1ebedc43c5d46d2e1b221d3e7ac39293af99e
4
- data.tar.gz: d848b51aa150fe3b33f755cd774f8e959550bfeef82daf475976756fe0b3a12a
3
+ metadata.gz: a80665d3e20f6c56644b2dd0b03b5f7a4231b3e0ef1d947af3094917944c885c
4
+ data.tar.gz: fd1bb8de6a7d955be8b2265e637a3bad4b09823e538a1c5b49ae8e3b4c8f067a
5
5
  SHA512:
6
- metadata.gz: 30b8d9843d40343ba72e06450c7262238a2d2d67bfffe6d59c55c61e4d20535985c513bc8b692bab193b5df3e2427b82ede2f441e50834d3fb15bf5f61d2d272
7
- data.tar.gz: '0817ca7dce3899b5e43a5a87fad228c370051475ccd41c475d5c5e32560cfa3cfca318006f59a8fb611be722cf08c76a82cb8184407c53d2e92999e6d38bed47'
6
+ metadata.gz: 5e6414ba8bf6453fb683870b8a90a7ffaea0101461d73baded7c0572a47bddabca443b1854b42f31db9a1ce95f957111a93bde585692d1f69a15a942d6b42ddd
7
+ data.tar.gz: '043982ac4ac832a6d8c8078996469bbddc794d56f113a35e2d3869338a34d49f2db58888d15cdd6713cb0e36a254d69e5eb9d26ab301bd9442de44e75298fba6'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openai-client (0.7.0)
4
+ openai-client (0.8.0)
5
5
  faraday (~> 1.8)
6
6
  faraday_middleware (~> 1.2)
7
7
 
data/README.md CHANGED
@@ -19,6 +19,13 @@ This gem is a wrapper for calling the OpenAI and GPT-3 APIs.
19
19
  * [Find File Content](#find-file-content)
20
20
  * [Upload File](#upload-file)
21
21
  * [Delete File](#delete-file)
22
+ * [OpenAI Fine-Tunes API](#openai-fine-tunes-api)
23
+ * [Create Fine-Tune](#create-fine-tune)
24
+ * [List Fine-Tunes](#list-fine-tunes)
25
+ * [Find Fine-Tune](#find-fine-tune)
26
+ * [List Fine-Tune Events](#list-fine-tune-events)
27
+ * [Cancel Fine-Tune](#cancel-fine-tune)
28
+ * [Delete Fine-Tune Model](#delete-fine-tune-model)
22
29
 
23
30
  ## Installation
24
31
 
@@ -81,7 +88,7 @@ request_body = {
81
88
  Openai::Client.completions.create(request_body)
82
89
  ```
83
90
 
84
- [API documentation](https://platform.openai.com/docs/api-reference/completions/create)
91
+ [API Documentation](https://platform.openai.com/docs/api-reference/completions/create)
85
92
 
86
93
  ## OpenAI Edits API
87
94
 
@@ -94,7 +101,7 @@ request_body = {
94
101
  Openai::Client.edits.create(request_body)
95
102
  ```
96
103
 
97
- [API documentation](https://platform.openai.com/docs/api-reference/edits/create)
104
+ [API Documentation](https://platform.openai.com/docs/api-reference/edits/create)
98
105
 
99
106
  ## OpenAI Image API
100
107
 
@@ -110,7 +117,7 @@ request_body = {
110
117
  response = Openai::Client.images.create(request_body)
111
118
  ```
112
119
 
113
- [API documentation](https://platform.openai.com/docs/api-reference/images/create)
120
+ [API Documentation](https://platform.openai.com/docs/api-reference/images/create)
114
121
 
115
122
  ### Create an Image Edit
116
123
 
@@ -129,7 +136,7 @@ response = Openai::Client.images.edit(request_body)
129
136
  - `image` - must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.
130
137
  - `mask` - an additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.
131
138
 
132
- [API documentation](https://platform.openai.com/docs/api-reference/images/create-edit)
139
+ [API Documentation](https://platform.openai.com/docs/api-reference/images/create-edit)
133
140
 
134
141
  ### Create an Image Variation
135
142
 
@@ -145,7 +152,7 @@ response = Openai::Client.images.variations(request_body)
145
152
 
146
153
  - `image` - must be a valid PNG file, less than 4MB, and square.
147
154
 
148
- [API documentation](https://platform.openai.com/docs/api-reference/images/create-variation)
155
+ [API Documentation](https://platform.openai.com/docs/api-reference/images/create-variation)
149
156
 
150
157
  ## OpenAI Embeddings API
151
158
 
@@ -157,7 +164,7 @@ request_body = {
157
164
  Openai::Client.embeddings.create(request_body)
158
165
  ```
159
166
 
160
- [API documentation](https://platform.openai.com/docs/api-reference/embeddings/create)
167
+ [API Documentation](https://platform.openai.com/docs/api-reference/embeddings/create)
161
168
 
162
169
  ## OpenAI Moderations API
163
170
 
@@ -169,7 +176,7 @@ request_body = {
169
176
  Openai::Client.moderations.create(request_body)
170
177
  ```
171
178
 
172
- [API documentation](https://platform.openai.com/docs/api-reference/moderations/create)
179
+ [API Documentation](https://platform.openai.com/docs/api-reference/moderations/create)
173
180
 
174
181
  ## OpenAI Files API
175
182
 
@@ -179,7 +186,7 @@ Openai::Client.moderations.create(request_body)
179
186
  Openai::Client.files.list
180
187
  ```
181
188
 
182
- [API documentation](https://platform.openai.com/docs/api-reference/files/list)
189
+ [API Documentation](https://platform.openai.com/docs/api-reference/files/list)
183
190
 
184
191
  ### Find File
185
192
 
@@ -187,7 +194,7 @@ Openai::Client.files.list
187
194
  Openai::Client.files.find(file_id)
188
195
  ```
189
196
 
190
- [API documentation](https://platform.openai.com/docs/api-reference/files/retrieve)
197
+ [API Documentation](https://platform.openai.com/docs/api-reference/files/retrieve)
191
198
 
192
199
  ### Find File Content
193
200
 
@@ -195,7 +202,7 @@ Openai::Client.files.find(file_id)
195
202
  Openai::Client.files.find_content(file_id)
196
203
  ```
197
204
 
198
- [API documentation](https://platform.openai.com/docs/api-reference/files/retrieve-content)
205
+ [API Documentation](https://platform.openai.com/docs/api-reference/files/retrieve-content)
199
206
 
200
207
  ### Upload File
201
208
 
@@ -216,7 +223,7 @@ Example (file.jsonl):
216
223
  ...
217
224
  ```
218
225
 
219
- [API documentation](https://platform.openai.com/docs/api-reference/files/upload)
226
+ [API Documentation](https://platform.openai.com/docs/api-reference/files/upload)
220
227
 
221
228
  ### Delete File
222
229
 
@@ -224,7 +231,64 @@ Example (file.jsonl):
224
231
  Openai::Client.files.delete(file_id)
225
232
  ```
226
233
 
227
- [API documentation](https://platform.openai.com/docs/api-reference/files/delete)
234
+ [API Documentation](https://platform.openai.com/docs/api-reference/files/delete)
235
+
236
+ ## OpenAI Fine-Tunes API
237
+
238
+ ### Create Fine-Tune
239
+
240
+ ```ruby
241
+ request_body = {
242
+ training_file: "file-XGinujblHPwGLSztz8cPS8XY"
243
+ }
244
+
245
+ Openai::Client.fine_tunes.create(request_body)
246
+ ```
247
+
248
+ [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/create)
249
+
250
+ ### List Fine-Tunes
251
+
252
+ ```ruby
253
+ Openai::Client.fine_tunes.list
254
+ ```
255
+
256
+ [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/list)
257
+
258
+ ### Find Fine-Tune
259
+
260
+ ```ruby
261
+ Openai::Client.fine_tunes.find(fine_tune_id)
262
+ ```
263
+
264
+ [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/retrieve)
265
+
266
+ ### List Fine-Tune Events
267
+
268
+ ```ruby
269
+ Openai::Client.fine_tunes.find_events(fine_tune_id)
270
+ ```
271
+
272
+ [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/events)
273
+
274
+ ### Cancel Fine-Tune
275
+
276
+ ```ruby
277
+ Openai::Client.fine_tunes.cancel(fine_tune_id)
278
+ ```
279
+
280
+ [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/cancel)
281
+
282
+ ### Delete Fine-Tune Model
283
+
284
+ ```ruby
285
+ Openai::Client.models.delete(model_id)
286
+ ```
287
+
288
+ [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/delete-model)
289
+
290
+ > - You must have the Owner role in your organization.
291
+ > - Make sure you provide the Model ID and not the Fine-Tune ID.
228
292
 
229
293
  ## Contributing
230
294
 
@@ -46,7 +46,7 @@ module Openai
46
46
  #
47
47
  # @param [String] id file ID
48
48
  #
49
- # @return [Hash] found file or nil
49
+ # @return [Hash] found file
50
50
  def find(id)
51
51
  Http.new.get("#{PATH}/#{id}").body
52
52
  rescue Faraday::Error
@@ -58,7 +58,7 @@ module Openai
58
58
  #
59
59
  # @param [String] id file ID
60
60
  #
61
- # @return [Hash] the contents of the specified file or nil
61
+ # @return [Hash] the contents of the specified file
62
62
  def find_content(id)
63
63
  Http.new.get("#{PATH}/#{id}/content").body
64
64
  rescue Faraday::Error
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openai
4
+ module Client
5
+ class FineTunes
6
+ PATH = 'fine-tunes'
7
+
8
+ # @api public
9
+ # Public: Makes an API call to return list the organization's fine-tuning jobs.
10
+ #
11
+ # @return [Hash] a list of fine-tuning jobs
12
+ def list
13
+ Http.new.get(PATH).body
14
+ rescue Faraday::Error
15
+ nil
16
+ end
17
+
18
+ # @api public
19
+ # Public: Makes an API call to find info about the fine-tune job.
20
+ #
21
+ # @param [String] id the ID of the fine-tune job
22
+ #
23
+ # @return [Hash] found fine-tune info
24
+ def find(id)
25
+ Http.new.get("#{PATH}/#{id}").body
26
+ rescue Faraday::Error
27
+ nil
28
+ end
29
+
30
+ # @api public
31
+ # Public: Makes an API call to find fine-grained status updates for a fine-tune job.
32
+ #
33
+ # @param [String] id the ID of the fine-tune job
34
+ #
35
+ # @return [Hash] found fine-grained status updates
36
+ def find_events(id)
37
+ Http.new.get("#{PATH}/#{id}/events").body
38
+ rescue Faraday::Error
39
+ nil
40
+ end
41
+
42
+ # @api public
43
+ # Public: Makes an API call to cancel a fine-tune job.
44
+ #
45
+ # @param [String] id the ID of the fine-tune job
46
+ #
47
+ # @return [Hash] the fine-tune related info
48
+ def cancel(id)
49
+ Http.new.post("#{PATH}/#{id}/cancel").body
50
+ rescue Faraday::Error
51
+ nil
52
+ end
53
+
54
+ # @api public
55
+ # Public: Makes an API call to create a job that fine-tunes a specified model from a given dataset.
56
+ #
57
+ # @param [Hash] body request body
58
+ #
59
+ # @return [Hash] details of the enqueued job including job status and the name of the fine-tuned models
60
+ def create(body)
61
+ Http.new.post(PATH, body).body
62
+ rescue Faraday::Error
63
+ nil
64
+ end
65
+ end
66
+ end
67
+ end
@@ -20,12 +20,24 @@ module Openai
20
20
  #
21
21
  # @param [String] id model id
22
22
  #
23
- # @return [Hash] found model or nil
23
+ # @return [Hash] found model
24
24
  def find(id)
25
25
  Http.new.get("#{PATH}/#{id}").body
26
26
  rescue Faraday::Error
27
27
  nil
28
28
  end
29
+
30
+ # @api public
31
+ # Public: Makes an API call to delete a model.
32
+ #
33
+ # @param [String] id model id
34
+ #
35
+ # @return [Hash] the model
36
+ def delete(id)
37
+ Http.new.delete("#{PATH}/#{id}").body
38
+ rescue Faraday::Error
39
+ nil
40
+ end
29
41
  end
30
42
  end
31
43
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Openai
4
4
  module Client
5
- VERSION = '0.7.0'
5
+ VERSION = '0.8.0'
6
6
  end
7
7
  end
data/lib/openai/client.rb CHANGED
@@ -15,18 +15,28 @@ require 'openai/client/images'
15
15
  require 'openai/client/embeddings'
16
16
  require 'openai/client/moderations'
17
17
  require 'openai/client/files'
18
+ require 'openai/client/fine_tunes'
18
19
 
19
20
  module Openai
20
21
  module Client
21
22
  extend Configurable
22
23
 
23
- ATTRS = ['models', 'edits', 'completions', 'images', 'embeddings', 'moderations', 'files'].freeze
24
+ ATTRS = [
25
+ 'models',
26
+ 'edits',
27
+ 'completions',
28
+ 'images',
29
+ 'embeddings',
30
+ 'moderations',
31
+ 'files',
32
+ 'fine_tunes'
33
+ ].freeze
24
34
 
25
35
  class << self
26
36
  ATTRS.each do |attr|
27
37
  define_method(attr) do
28
- instance_variable_get("@#{attr}") || instance_variable_set("@#{attr}",
29
- const_get(attr.capitalize, self).new)
38
+ klass = const_get(attr.split('_').map(&:capitalize).join, self)
39
+ instance_variable_get("@#{attr}") || instance_variable_set("@#{attr}", klass.new)
30
40
  end
31
41
  end
32
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openai-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ihor Tykhonenko
@@ -60,6 +60,7 @@ files:
60
60
  - lib/openai/client/edits.rb
61
61
  - lib/openai/client/embeddings.rb
62
62
  - lib/openai/client/files.rb
63
+ - lib/openai/client/fine_tunes.rb
63
64
  - lib/openai/client/http.rb
64
65
  - lib/openai/client/images.rb
65
66
  - lib/openai/client/models.rb