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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed826c08b658bc553da53acfc53a57c5a2f09320787dbe00fa6c901f1941e7a8
4
- data.tar.gz: 0b1cb51e0cd24f1e50877045881485cdb1c0ecf772c98464ff159b1001abd81d
3
+ metadata.gz: '06199aaabd11e965f6d07f3948323b5226fdda82f09326c065cda4b5b2cc9237'
4
+ data.tar.gz: 59cce00dfeb08270e11b2c33b23af4558dfc53796c87ebb6cf64b1cb76739790
5
5
  SHA512:
6
- metadata.gz: d8575821c9b6921840c3e8b34916992ef0d947f1cce1308e19b2e82d0d3f968870649eb9e456d9c38cfb95ae667576330176bae45cb173dab116735450cfc0b2
7
- data.tar.gz: 8846dceef8669867c09168b19e0aedcb77cd76cd403a8ddf8a16e259132a17116c6c318adcbd4b04d0316c123166ef5e7da7e02cbbbe30e4e2ad3b13983fd67b
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai (4.0.0)
4
+ ruby-openai (4.1.0)
5
5
  faraday (>= 1)
6
6
  faraday-multipart (>= 1)
7
7
 
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://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys)
40
- - If you belong to multiple organizations, you can get your Organization ID from [https://beta.openai.com/account/org-settings](https://beta.openai.com/account/org-settings)
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
- 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) 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.
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].is_a?(Proc)
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
@@ -1,3 +1,3 @@
1
1
  module OpenAI
2
- VERSION = "4.0.0".freeze
2
+ VERSION = "4.1.0".freeze
3
3
  end
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.0.0
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-04-26 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday