ruby-openai 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -3
- data/lib/openai/http.rb +3 -1
- data/lib/openai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '06199aaabd11e965f6d07f3948323b5226fdda82f09326c065cda4b5b2cc9237'
|
4
|
+
data.tar.gz: 59cce00dfeb08270e11b2c33b23af4558dfc53796c87ebb6cf64b1cb76739790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d9b9409e915f49284f8acdf4be10cde81d7065fadb254dc135aeaad5572c2278c3bb6115752e8c43619d4ea60d696bc55a8128af8981ec544db2320c2d4b89a
|
7
|
+
data.tar.gz: a202ca506f515e8933f00e0302dcd8a59b8d15f6b11c13263499ac140b9b045162089141f27cab5dda2dbde3d5b960c05c8081415a721b29cbdffcd3d375ddd0
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [4.1.0] - 2023-05-15
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add the ability to trigger any callable object as stream chunks come through, not just Procs. Big thanks to [@obie](https://github.com/obie) for this change.
|
13
|
+
|
8
14
|
## [4.0.0] - 2023-04-25
|
9
15
|
|
10
16
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,10 @@ Stream text with GPT-4, transcribe and translate audio with Whisper, or create i
|
|
10
10
|
|
11
11
|
[Ruby AI Builders Discord](https://discord.gg/k4Uc224xVD)
|
12
12
|
|
13
|
+
[Quick guide to streaming ChatGPT with Rails 7 and Hotwire](https://gist.github.com/alexrudall/cb5ee1e109353ef358adb4e66631799d)
|
14
|
+
|
15
|
+
Follow me on [Twitter](https://twitter.com/alexrudall) for more Ruby / AI content
|
16
|
+
|
13
17
|
### Bundler
|
14
18
|
|
15
19
|
Add this line to your application's Gemfile:
|
@@ -36,8 +40,8 @@ require "openai"
|
|
36
40
|
|
37
41
|
## Usage
|
38
42
|
|
39
|
-
- Get your API key from [https://
|
40
|
-
- If you belong to multiple organizations, you can get your Organization ID from [https://
|
43
|
+
- Get your API key from [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)
|
44
|
+
- If you belong to multiple organizations, you can get your Organization ID from [https://platform.openai.com/account/org-settings](https://platform.openai.com/account/org-settings)
|
41
45
|
|
42
46
|
### Quickstart
|
43
47
|
|
@@ -128,7 +132,9 @@ puts response.dig("choices", 0, "message", "content")
|
|
128
132
|
|
129
133
|
### Streaming ChatGPT
|
130
134
|
|
131
|
-
|
135
|
+
[Quick guide to streaming ChatGPT with Rails 7 and Hotwire](https://gist.github.com/alexrudall/cb5ee1e109353ef358adb4e66631799d)
|
136
|
+
|
137
|
+
You can stream from the API in realtime, which can be much faster and used to create a more engaging user experience. Pass a [Proc](https://ruby-doc.org/core-2.6/Proc.html) (or any object with a `#call` method) to the `stream` parameter to receive the stream of text chunks as they are generated. Each time one or more chunks is received, the proc will be called once with each chunk, parsed as a Hash. If OpenAI returns an error, `ruby-openai` will pass that to your proc as a Hash.
|
132
138
|
|
133
139
|
```ruby
|
134
140
|
client.chat(
|
data/lib/openai/http.rb
CHANGED
@@ -8,9 +8,11 @@ module OpenAI
|
|
8
8
|
|
9
9
|
def json_post(path:, parameters:)
|
10
10
|
to_json(conn.post(uri(path: path)) do |req|
|
11
|
-
if parameters[:stream].
|
11
|
+
if parameters[:stream].respond_to?(:call)
|
12
12
|
req.options.on_data = to_json_stream(user_proc: parameters[:stream])
|
13
13
|
parameters[:stream] = true # Necessary to tell OpenAI to stream.
|
14
|
+
elsif parameters[:stream]
|
15
|
+
raise ArgumentError, "The stream parameter must be a Proc or have a #call method"
|
14
16
|
end
|
15
17
|
|
16
18
|
req.headers = headers
|
data/lib/openai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-openai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|