openai_ruby 0.3.7 → 0.3.8

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: 907d57ab5a2453a42e55dfd8fa220c0563e2378db3c4019bd2d7defeecc4dc03
4
- data.tar.gz: 71213f0cce287151916c2be919bd21444b51c1f5999ea4e9bc2b0601b47656ab
3
+ metadata.gz: 62f0b226a7ae9602b425e0e72149e058dd6d122ed54fd325a1799d7ec493daee
4
+ data.tar.gz: 8e3fa3d8842917acbbff93f0bff58b07fd953b11616d2e3b64508dab91351327
5
5
  SHA512:
6
- metadata.gz: f9c69651ff5145e4873e3e11e7e647ea448dc2c0c428c20863b8f1788d8f53e350dc33a0581aa25a958845137935eb1fc9d499112138d0629af1dddd3cc835e0
7
- data.tar.gz: 250654717fbdf1b099ba0cf0dcc19fc0dbd5234131bb6a14c2ee28a2273e8dbcb53ba987dafa50270f94c0ec6f2c1055711ded10772633fbc88ec8f92e61f277
6
+ metadata.gz: f70d3f04b8d1983186cc95870f6961b1ad88465123c3c2b0d83c0ba4cd9ccf5a254772a2586416b1374acd13291b4a456a088c463114f3b9e89b271b80bc776f
7
+ data.tar.gz: cab463d49f2a5ce6487e8e9b4ebb1a3ed0f5a270aa3697c56a6520ba72d4a808de356d38d9f9b48e8805fd0621ed498368d61117ffae996c20c8e5b757d5108a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openai_ruby (0.3.6)
4
+ openai_ruby (0.3.8)
5
5
  faraday (~> 2.7)
6
6
 
7
7
  GEM
@@ -51,6 +51,7 @@ GEM
51
51
  unicode-display_width (2.4.2)
52
52
 
53
53
  PLATFORMS
54
+ arm64-darwin-21
54
55
  arm64-darwin-22
55
56
  x86_64-linux
56
57
 
data/README.md CHANGED
@@ -29,7 +29,16 @@ create a client like this:
29
29
  client = OpenAI::Client.new("your OpenAI key here")
30
30
  ```
31
31
 
32
- ### Completion
32
+ Or you can pass a hash of options to customize the connection:
33
+
34
+ ```ruby
35
+ client = OpenAI::Client.new("your OpenAI key here", { request: { timeout: 20 } })
36
+ ```
37
+
38
+ For more options check [here](https://lostisland.github.io/faraday/#/customization/connection-options)
39
+
40
+ ### Completion
41
+
33
42
  https://platform.openai.com/docs/api-reference/completions
34
43
 
35
44
  ```ruby
@@ -48,7 +57,8 @@ p response.dig("choices", 0, "text") # "I am an AI created by OpenAI."
48
57
  p response.dig('usage', 'total_tokens') # 18
49
58
  ```
50
59
 
51
- ### Chat Completion
60
+ ### Chat Completion
61
+
52
62
  https://platform.openai.com/docs/api-reference/chat/create
53
63
 
54
64
  If you set `stream` param to `true`, a block will be called with the chunk data:
@@ -74,6 +84,7 @@ end
74
84
  ```
75
85
 
76
86
  ### Edit
87
+
77
88
  https://platform.openai.com/docs/api-reference/edits
78
89
 
79
90
  ```ruby
@@ -4,10 +4,11 @@ module OpenAI
4
4
  class Client
5
5
  BASE_URL = "https://api.openai.com"
6
6
 
7
- attr_reader :api_key
7
+ attr_reader :api_key, :options
8
8
 
9
- def initialize(api_key)
9
+ def initialize(api_key, options)
10
10
  @api_key = api_key
11
+ @options = options
11
12
  end
12
13
 
13
14
  def create_completion(params = {})
@@ -47,7 +48,7 @@ module OpenAI
47
48
  private
48
49
 
49
50
  def connection
50
- Faraday.new(url: BASE_URL, headers: headers, request: { timeout: 240 })
51
+ Faraday.new({ url: BASE_URL, headers: headers }.merge(options))
51
52
  end
52
53
 
53
54
  def headers
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenAI
4
- VERSION = "0.3.7"
4
+ VERSION = "0.3.8"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openai_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renny Ren