openai-client 0.7.0 → 0.8.1
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 +4 -4
 - data/Gemfile.lock +1 -1
 - data/README.md +102 -12
 - data/Rakefile +7 -0
 - data/lib/openai/client/files.rb +2 -2
 - data/lib/openai/client/fine_tunes.rb +67 -0
 - data/lib/openai/client/models.rb +13 -1
 - data/lib/openai/client/version.rb +1 -1
 - data/lib/openai/client.rb +13 -3
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3cbf3dd44125f32b91842962afe23cd6c9598d1860134d9bbdf00f7aee8a0324
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5082017517a67520e653376ee73bc267c7775d2e85979b7fb38ef8a19267fc20
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 24b0f29f7e4c58a3f881fcd06a68d833e8c3185990d572983f43e68d86a97ec4911d2ffa9f906c5408b0aac142e7a8fca6029f406325f3082dcf695a83e8c605
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f82ba652ebcaea9407f6b4667a5b98351af1352c48e112a0a90773a909bd1f043979a1cd2fc261be9bd714c1fe85298b3a95eec32bd2878168307e1336724de9
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -5,20 +5,33 @@ This gem is a wrapper for calling the OpenAI and GPT-3 APIs. 
     | 
|
| 
       5 
5 
     | 
    
         
             
            * [Installation](#installation)
         
     | 
| 
       6 
6 
     | 
    
         
             
            * [Usage](#usage)
         
     | 
| 
       7 
7 
     | 
    
         
             
            * [OpenAI Models API](#openai-models-api)
         
     | 
| 
      
 8 
     | 
    
         
            +
              * [List Models](#list-models)
         
     | 
| 
      
 9 
     | 
    
         
            +
              * [Find Model](#find-model)
         
     | 
| 
       8 
10 
     | 
    
         
             
            * [OpenAI Completions API](#openai-completions-api)
         
     | 
| 
      
 11 
     | 
    
         
            +
              * [Create Completion](#create-completion)
         
     | 
| 
       9 
12 
     | 
    
         
             
            * [OpenAI Edits API](#openai-edits-api)
         
     | 
| 
      
 13 
     | 
    
         
            +
              * [Create Edit](#create-edit)
         
     | 
| 
       10 
14 
     | 
    
         
             
            * [OpenAI Image API](#openai-image-api)
         
     | 
| 
       11 
15 
     | 
    
         
             
              * [Create an Image](#create-an-image)
         
     | 
| 
       12 
16 
     | 
    
         
             
              * [Create an Image Edit](#create-an-image-edit)
         
     | 
| 
       13 
17 
     | 
    
         
             
              * [Create an Image Variation](#create-an-image-variation)
         
     | 
| 
       14 
18 
     | 
    
         
             
            * [OpenAI Embeddings API](#openai-embeddings-api)
         
     | 
| 
      
 19 
     | 
    
         
            +
              * [Create Embeddings](#create-embeddings)
         
     | 
| 
       15 
20 
     | 
    
         
             
            * [OpenAI Moderations API](#openai-moderations-api)
         
     | 
| 
      
 21 
     | 
    
         
            +
              * [Create Moderation](#create-moderation)
         
     | 
| 
       16 
22 
     | 
    
         
             
            * [OpenAI Files API](#openai-files-api)
         
     | 
| 
       17 
23 
     | 
    
         
             
              * [List Files](#list-files)
         
     | 
| 
       18 
24 
     | 
    
         
             
              * [Find File](#find-file)
         
     | 
| 
       19 
25 
     | 
    
         
             
              * [Find File Content](#find-file-content)
         
     | 
| 
       20 
26 
     | 
    
         
             
              * [Upload File](#upload-file)
         
     | 
| 
       21 
27 
     | 
    
         
             
              * [Delete File](#delete-file)
         
     | 
| 
      
 28 
     | 
    
         
            +
            * [OpenAI Fine-Tunes API](#openai-fine-tunes-api)
         
     | 
| 
      
 29 
     | 
    
         
            +
              * [Create Fine-Tune](#create-fine-tune)
         
     | 
| 
      
 30 
     | 
    
         
            +
              * [List Fine-Tunes](#list-fine-tunes)
         
     | 
| 
      
 31 
     | 
    
         
            +
              * [Find Fine-Tune](#find-fine-tune)
         
     | 
| 
      
 32 
     | 
    
         
            +
              * [List Fine-Tune Events](#list-fine-tune-events)
         
     | 
| 
      
 33 
     | 
    
         
            +
              * [Cancel Fine-Tune](#cancel-fine-tune)
         
     | 
| 
      
 34 
     | 
    
         
            +
              * [Delete Fine-Tune Model](#delete-fine-tune-model)
         
     | 
| 
       22 
35 
     | 
    
         | 
| 
       23 
36 
     | 
    
         
             
            ## Installation
         
     | 
| 
       24 
37 
     | 
    
         | 
| 
         @@ -56,6 +69,18 @@ end 
     | 
|
| 
       56 
69 
     | 
    
         | 
| 
       57 
70 
     | 
    
         
             
            ## OpenAI Models API
         
     | 
| 
       58 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
            ### List Models
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 75 
     | 
    
         
            +
            Openai::Client.models.list
         
     | 
| 
      
 76 
     | 
    
         
            +
            ```
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            ### Find Model
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 81 
     | 
    
         
            +
            Openai::Client.models.find(model_id)
         
     | 
| 
      
 82 
     | 
    
         
            +
            ```
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
       59 
84 
     | 
    
         
             
            ```ruby
         
     | 
| 
       60 
85 
     | 
    
         
             
            # Models
         
     | 
| 
       61 
86 
     | 
    
         
             
            Openai::Client.models.list
         
     | 
| 
         @@ -66,6 +91,8 @@ Openai::Client.models.find(model_id) 
     | 
|
| 
       66 
91 
     | 
    
         | 
| 
       67 
92 
     | 
    
         
             
            ## OpenAI Completions API
         
     | 
| 
       68 
93 
     | 
    
         | 
| 
      
 94 
     | 
    
         
            +
            ### Create Completion
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
       69 
96 
     | 
    
         
             
            ```ruby
         
     | 
| 
       70 
97 
     | 
    
         
             
            request_body = {
         
     | 
| 
       71 
98 
     | 
    
         
             
              model: 'text-davinci-003',
         
     | 
| 
         @@ -81,10 +108,12 @@ request_body = { 
     | 
|
| 
       81 
108 
     | 
    
         
             
            Openai::Client.completions.create(request_body)
         
     | 
| 
       82 
109 
     | 
    
         
             
            ```
         
     | 
| 
       83 
110 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
            [API  
     | 
| 
      
 111 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/completions/create)
         
     | 
| 
       85 
112 
     | 
    
         | 
| 
       86 
113 
     | 
    
         
             
            ## OpenAI Edits API
         
     | 
| 
       87 
114 
     | 
    
         | 
| 
      
 115 
     | 
    
         
            +
            ### Create Edit
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
       88 
117 
     | 
    
         
             
            ```ruby
         
     | 
| 
       89 
118 
     | 
    
         
             
            request_body = {
         
     | 
| 
       90 
119 
     | 
    
         
             
              model: 'text-davinci-edit-001',
         
     | 
| 
         @@ -94,7 +123,7 @@ request_body = { 
     | 
|
| 
       94 
123 
     | 
    
         
             
            Openai::Client.edits.create(request_body)
         
     | 
| 
       95 
124 
     | 
    
         
             
            ```
         
     | 
| 
       96 
125 
     | 
    
         | 
| 
       97 
     | 
    
         
            -
            [API  
     | 
| 
      
 126 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/edits/create)
         
     | 
| 
       98 
127 
     | 
    
         | 
| 
       99 
128 
     | 
    
         
             
            ## OpenAI Image API
         
     | 
| 
       100 
129 
     | 
    
         | 
| 
         @@ -110,7 +139,7 @@ request_body = { 
     | 
|
| 
       110 
139 
     | 
    
         
             
            response = Openai::Client.images.create(request_body)
         
     | 
| 
       111 
140 
     | 
    
         
             
            ```
         
     | 
| 
       112 
141 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
            [API  
     | 
| 
      
 142 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/images/create)
         
     | 
| 
       114 
143 
     | 
    
         | 
| 
       115 
144 
     | 
    
         
             
            ### Create an Image Edit
         
     | 
| 
       116 
145 
     | 
    
         | 
| 
         @@ -129,7 +158,7 @@ response = Openai::Client.images.edit(request_body) 
     | 
|
| 
       129 
158 
     | 
    
         
             
            - `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 
159 
     | 
    
         
             
            - `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 
160 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
            [API  
     | 
| 
      
 161 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/images/create-edit)
         
     | 
| 
       133 
162 
     | 
    
         | 
| 
       134 
163 
     | 
    
         
             
            ### Create an Image Variation
         
     | 
| 
       135 
164 
     | 
    
         | 
| 
         @@ -145,10 +174,12 @@ response = Openai::Client.images.variations(request_body) 
     | 
|
| 
       145 
174 
     | 
    
         | 
| 
       146 
175 
     | 
    
         
             
            - `image` - must be a valid PNG file, less than 4MB, and square.
         
     | 
| 
       147 
176 
     | 
    
         | 
| 
       148 
     | 
    
         
            -
            [API  
     | 
| 
      
 177 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/images/create-variation)
         
     | 
| 
       149 
178 
     | 
    
         | 
| 
       150 
179 
     | 
    
         
             
            ## OpenAI Embeddings API
         
     | 
| 
       151 
180 
     | 
    
         | 
| 
      
 181 
     | 
    
         
            +
            ### Create Embeddings
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
       152 
183 
     | 
    
         
             
            ```ruby
         
     | 
| 
       153 
184 
     | 
    
         
             
            request_body = {
         
     | 
| 
       154 
185 
     | 
    
         
             
              model: 'text-embedding-ada-002',
         
     | 
| 
         @@ -157,10 +188,12 @@ request_body = { 
     | 
|
| 
       157 
188 
     | 
    
         
             
            Openai::Client.embeddings.create(request_body)
         
     | 
| 
       158 
189 
     | 
    
         
             
            ```
         
     | 
| 
       159 
190 
     | 
    
         | 
| 
       160 
     | 
    
         
            -
            [API  
     | 
| 
      
 191 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/embeddings/create)
         
     | 
| 
       161 
192 
     | 
    
         | 
| 
       162 
193 
     | 
    
         
             
            ## OpenAI Moderations API
         
     | 
| 
       163 
194 
     | 
    
         | 
| 
      
 195 
     | 
    
         
            +
            ### Create Moderation
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
       164 
197 
     | 
    
         
             
            ```ruby
         
     | 
| 
       165 
198 
     | 
    
         
             
            request_body = {
         
     | 
| 
       166 
199 
     | 
    
         
             
              model: 'text-moderation-latest', # text-moderation-stable or text-moderation-latest
         
     | 
| 
         @@ -169,7 +202,7 @@ request_body = { 
     | 
|
| 
       169 
202 
     | 
    
         
             
            Openai::Client.moderations.create(request_body)
         
     | 
| 
       170 
203 
     | 
    
         
             
            ```
         
     | 
| 
       171 
204 
     | 
    
         | 
| 
       172 
     | 
    
         
            -
            [API  
     | 
| 
      
 205 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/moderations/create)
         
     | 
| 
       173 
206 
     | 
    
         | 
| 
       174 
207 
     | 
    
         
             
            ## OpenAI Files API
         
     | 
| 
       175 
208 
     | 
    
         | 
| 
         @@ -179,7 +212,7 @@ Openai::Client.moderations.create(request_body) 
     | 
|
| 
       179 
212 
     | 
    
         
             
            Openai::Client.files.list
         
     | 
| 
       180 
213 
     | 
    
         
             
            ```
         
     | 
| 
       181 
214 
     | 
    
         | 
| 
       182 
     | 
    
         
            -
            [API  
     | 
| 
      
 215 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/files/list)
         
     | 
| 
       183 
216 
     | 
    
         | 
| 
       184 
217 
     | 
    
         
             
            ### Find File
         
     | 
| 
       185 
218 
     | 
    
         | 
| 
         @@ -187,7 +220,7 @@ Openai::Client.files.list 
     | 
|
| 
       187 
220 
     | 
    
         
             
            Openai::Client.files.find(file_id)
         
     | 
| 
       188 
221 
     | 
    
         
             
            ```
         
     | 
| 
       189 
222 
     | 
    
         | 
| 
       190 
     | 
    
         
            -
            [API  
     | 
| 
      
 223 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/files/retrieve)
         
     | 
| 
       191 
224 
     | 
    
         | 
| 
       192 
225 
     | 
    
         
             
            ### Find File Content
         
     | 
| 
       193 
226 
     | 
    
         | 
| 
         @@ -195,7 +228,7 @@ Openai::Client.files.find(file_id) 
     | 
|
| 
       195 
228 
     | 
    
         
             
            Openai::Client.files.find_content(file_id)
         
     | 
| 
       196 
229 
     | 
    
         
             
            ```
         
     | 
| 
       197 
230 
     | 
    
         | 
| 
       198 
     | 
    
         
            -
            [API  
     | 
| 
      
 231 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/files/retrieve-content)
         
     | 
| 
       199 
232 
     | 
    
         | 
| 
       200 
233 
     | 
    
         
             
            ### Upload File
         
     | 
| 
       201 
234 
     | 
    
         | 
| 
         @@ -216,7 +249,7 @@ Example (file.jsonl): 
     | 
|
| 
       216 
249 
     | 
    
         
             
            ...
         
     | 
| 
       217 
250 
     | 
    
         
             
            ```
         
     | 
| 
       218 
251 
     | 
    
         | 
| 
       219 
     | 
    
         
            -
            [API  
     | 
| 
      
 252 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/files/upload)
         
     | 
| 
       220 
253 
     | 
    
         | 
| 
       221 
254 
     | 
    
         
             
            ### Delete File
         
     | 
| 
       222 
255 
     | 
    
         | 
| 
         @@ -224,7 +257,64 @@ Example (file.jsonl): 
     | 
|
| 
       224 
257 
     | 
    
         
             
            Openai::Client.files.delete(file_id)
         
     | 
| 
       225 
258 
     | 
    
         
             
            ```
         
     | 
| 
       226 
259 
     | 
    
         | 
| 
       227 
     | 
    
         
            -
            [API  
     | 
| 
      
 260 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/files/delete)
         
     | 
| 
      
 261 
     | 
    
         
            +
             
     | 
| 
      
 262 
     | 
    
         
            +
            ## OpenAI Fine-Tunes API
         
     | 
| 
      
 263 
     | 
    
         
            +
             
     | 
| 
      
 264 
     | 
    
         
            +
            ### Create Fine-Tune
         
     | 
| 
      
 265 
     | 
    
         
            +
             
     | 
| 
      
 266 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 267 
     | 
    
         
            +
            request_body = {
         
     | 
| 
      
 268 
     | 
    
         
            +
              training_file: "file-XGinujblHPwGLSztz8cPS8XY"
         
     | 
| 
      
 269 
     | 
    
         
            +
            }
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
            Openai::Client.fine_tunes.create(request_body)
         
     | 
| 
      
 272 
     | 
    
         
            +
            ```
         
     | 
| 
      
 273 
     | 
    
         
            +
             
     | 
| 
      
 274 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/create)
         
     | 
| 
      
 275 
     | 
    
         
            +
             
     | 
| 
      
 276 
     | 
    
         
            +
            ### List Fine-Tunes
         
     | 
| 
      
 277 
     | 
    
         
            +
             
     | 
| 
      
 278 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 279 
     | 
    
         
            +
            Openai::Client.fine_tunes.list
         
     | 
| 
      
 280 
     | 
    
         
            +
            ```
         
     | 
| 
      
 281 
     | 
    
         
            +
             
     | 
| 
      
 282 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/list)
         
     | 
| 
      
 283 
     | 
    
         
            +
             
     | 
| 
      
 284 
     | 
    
         
            +
            ### Find Fine-Tune
         
     | 
| 
      
 285 
     | 
    
         
            +
             
     | 
| 
      
 286 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 287 
     | 
    
         
            +
            Openai::Client.fine_tunes.find(fine_tune_id)
         
     | 
| 
      
 288 
     | 
    
         
            +
            ```
         
     | 
| 
      
 289 
     | 
    
         
            +
             
     | 
| 
      
 290 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/retrieve)
         
     | 
| 
      
 291 
     | 
    
         
            +
             
     | 
| 
      
 292 
     | 
    
         
            +
            ### List Fine-Tune Events
         
     | 
| 
      
 293 
     | 
    
         
            +
             
     | 
| 
      
 294 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 295 
     | 
    
         
            +
            Openai::Client.fine_tunes.find_events(fine_tune_id)
         
     | 
| 
      
 296 
     | 
    
         
            +
            ```
         
     | 
| 
      
 297 
     | 
    
         
            +
             
     | 
| 
      
 298 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/events)
         
     | 
| 
      
 299 
     | 
    
         
            +
             
     | 
| 
      
 300 
     | 
    
         
            +
            ### Cancel Fine-Tune
         
     | 
| 
      
 301 
     | 
    
         
            +
             
     | 
| 
      
 302 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 303 
     | 
    
         
            +
            Openai::Client.fine_tunes.cancel(fine_tune_id)
         
     | 
| 
      
 304 
     | 
    
         
            +
            ```
         
     | 
| 
      
 305 
     | 
    
         
            +
             
     | 
| 
      
 306 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/cancel)
         
     | 
| 
      
 307 
     | 
    
         
            +
             
     | 
| 
      
 308 
     | 
    
         
            +
            ### Delete Fine-Tune Model
         
     | 
| 
      
 309 
     | 
    
         
            +
             
     | 
| 
      
 310 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 311 
     | 
    
         
            +
            Openai::Client.models.delete(model_id)
         
     | 
| 
      
 312 
     | 
    
         
            +
            ```
         
     | 
| 
      
 313 
     | 
    
         
            +
             
     | 
| 
      
 314 
     | 
    
         
            +
            [API Documentation](https://platform.openai.com/docs/api-reference/fine-tunes/delete-model)
         
     | 
| 
      
 315 
     | 
    
         
            +
             
     | 
| 
      
 316 
     | 
    
         
            +
            > - You must have the Owner role in your organization.
         
     | 
| 
      
 317 
     | 
    
         
            +
            > - Make sure you provide the Model ID and not the Fine-Tune ID.
         
     | 
| 
       228 
318 
     | 
    
         | 
| 
       229 
319 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       230 
320 
     | 
    
         | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -2,6 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'bundler/gem_tasks'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'rspec/core/rake_task'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'yard'
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            RSpec::Core::RakeTask.new(:spec)
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
         @@ -10,3 +11,9 @@ require 'rubocop/rake_task' 
     | 
|
| 
       10 
11 
     | 
    
         
             
            RuboCop::RakeTask.new
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
            task default: %i[spec rubocop]
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            YARD::Rake::YardocTask.new do |t|
         
     | 
| 
      
 16 
     | 
    
         
            +
              t.files = ['lib/**/*.rb'] # optional
         
     | 
| 
      
 17 
     | 
    
         
            +
              t.options = ['--any', '--extra', '--opts'] # optional
         
     | 
| 
      
 18 
     | 
    
         
            +
              t.stats_options = ['--list-undoc']         # optional
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/openai/client/files.rb
    CHANGED
    
    | 
         @@ -46,7 +46,7 @@ module Openai 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  #
         
     | 
| 
       47 
47 
     | 
    
         
             
                  # @param [String] id file ID
         
     | 
| 
       48 
48 
     | 
    
         
             
                  #
         
     | 
| 
       49 
     | 
    
         
            -
                  # @return [Hash] found file 
     | 
| 
      
 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 
     | 
| 
      
 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
         
     | 
    
        data/lib/openai/client/models.rb
    CHANGED
    
    | 
         @@ -20,12 +20,24 @@ module Openai 
     | 
|
| 
       20 
20 
     | 
    
         
             
                  #
         
     | 
| 
       21 
21 
     | 
    
         
             
                  # @param [String] id model id
         
     | 
| 
       22 
22 
     | 
    
         
             
                  #
         
     | 
| 
       23 
     | 
    
         
            -
                  # @return [Hash] found model 
     | 
| 
      
 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
         
     | 
    
        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 = [ 
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 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,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: openai-client
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.8.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ihor Tykhonenko
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2023-02- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-02-14 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: faraday
         
     | 
| 
         @@ -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
         
     |