openai_ruby 0.4.0 → 0.4.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/.rubocop.yml +4 -1
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/openai_ruby/client.rb +7 -6
- data/lib/openai_ruby/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5873de02b645485ae0e1850fe232ac3a4825f083f227fc0eccd886a2ae9c6b1
|
4
|
+
data.tar.gz: 4e1fdaca2c2dd90aa5e1f20f7628d1896e3dfc0f0cf9a57682f44a622232268c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a608e43e0b62805b44a817db7a0000f219c2d6fe82bf742a0f2f5f176d4d2e536fb2a723071fef5e69520b193e4af7fa6b1a2834ac502438d2c39903a34681f
|
7
|
+
data.tar.gz: 691b0d2f5c0ca192a5e9079157407ee79d044d7fce237cc1eedacaf0eb02dd95bce07f89273f6e4580f4f0d259eb488eb9c0033b6bfc6599549da33518fef8cf
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ client = OpenAI::Client.new("your OpenAI key here")
|
|
32
32
|
Or you can pass a hash of options to customize the connection:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
client = OpenAI::Client.new("your OpenAI key here", { request: { timeout: 20 } })
|
35
|
+
client = OpenAI::Client.new("your OpenAI key here", { base_uri: "https://example.com/", request: { timeout: 20 } })
|
36
36
|
```
|
37
37
|
|
38
38
|
For more options check [here](https://lostisland.github.io/faraday/#/customization/connection-options)
|
data/lib/openai_ruby/client.rb
CHANGED
@@ -2,18 +2,19 @@
|
|
2
2
|
|
3
3
|
module OpenAI
|
4
4
|
class Client
|
5
|
-
|
5
|
+
DEFAULT_BASE_URI = "https://api.openai.com"
|
6
6
|
|
7
7
|
attr_reader :api_key, :options
|
8
8
|
|
9
9
|
def initialize(api_key, options = {})
|
10
10
|
@api_key = api_key
|
11
11
|
@options = options
|
12
|
+
@base_uri = options[:base_uri] || DEFAULT_BASE_URI
|
12
13
|
end
|
13
14
|
|
14
15
|
def create_completion(params = {})
|
15
16
|
Faraday.post(
|
16
|
-
"#{
|
17
|
+
"#{base_uri}/v1/completions",
|
17
18
|
params.to_json,
|
18
19
|
headers
|
19
20
|
)
|
@@ -26,7 +27,7 @@ module OpenAI
|
|
26
27
|
if params["stream"]
|
27
28
|
connection.post("/v1/chat/completions") do |req|
|
28
29
|
req.body = params.to_json
|
29
|
-
req.options.on_data = proc do |chunk,
|
30
|
+
req.options.on_data = proc do |chunk, _overall_received_bytes, env|
|
30
31
|
if env && env.status != 200
|
31
32
|
raise_error = Faraday::Response::RaiseError.new
|
32
33
|
raise_error.on_complete(env.merge(body: try_parse_json(chunk)))
|
@@ -44,7 +45,7 @@ module OpenAI
|
|
44
45
|
|
45
46
|
def create_edit(params = {})
|
46
47
|
Faraday.post(
|
47
|
-
"#{
|
48
|
+
"#{base_uri}/v1/edits",
|
48
49
|
params.to_json,
|
49
50
|
headers
|
50
51
|
)
|
@@ -57,13 +58,13 @@ module OpenAI
|
|
57
58
|
private
|
58
59
|
|
59
60
|
def connection
|
60
|
-
Faraday.new({ url:
|
61
|
+
Faraday.new({ url: base_uri, headers: headers }.merge(options))
|
61
62
|
end
|
62
63
|
|
63
64
|
def headers
|
64
65
|
{
|
65
66
|
"Content-Type" => "application/json",
|
66
|
-
"Authorization" => "Bearer #{api_key}"
|
67
|
+
"Authorization" => "Bearer #{api_key}",
|
67
68
|
}
|
68
69
|
end
|
69
70
|
|
data/lib/openai_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openai_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renny Ren
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: event_stream_parser
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.7'
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- rennyrjh@gmail.com
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.4.
|
84
|
+
rubygems_version: 3.4.19
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: A Ruby wrapper for OpenAI API
|