openai_ruby 0.3.7 → 0.3.8
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 +2 -1
- data/README.md +13 -2
- data/lib/openai_ruby/client.rb +4 -3
- data/lib/openai_ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62f0b226a7ae9602b425e0e72149e058dd6d122ed54fd325a1799d7ec493daee
|
4
|
+
data.tar.gz: 8e3fa3d8842917acbbff93f0bff58b07fd953b11616d2e3b64508dab91351327
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f70d3f04b8d1983186cc95870f6961b1ad88465123c3c2b0d83c0ba4cd9ccf5a254772a2586416b1374acd13291b4a456a088c463114f3b9e89b271b80bc776f
|
7
|
+
data.tar.gz: cab463d49f2a5ce6487e8e9b4ebb1a3ed0f5a270aa3697c56a6520ba72d4a808de356d38d9f9b48e8805fd0621ed498368d61117ffae996c20c8e5b757d5108a
|
data/Gemfile.lock
CHANGED
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
|
-
|
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
|
data/lib/openai_ruby/client.rb
CHANGED
@@ -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
|
51
|
+
Faraday.new({ url: BASE_URL, headers: headers }.merge(options))
|
51
52
|
end
|
52
53
|
|
53
54
|
def headers
|
data/lib/openai_ruby/version.rb
CHANGED