You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,18 @@ 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.0.0] - 2023-04-25
9
+
10
+
### Added
11
+
12
+
- Add the ability to stream Chat responses from the API! Thanks to everyone who requested this and made suggestions.
13
+
- Added instructions for streaming to the README.
14
+
15
+
### Changed
16
+
17
+
- Switch HTTP library from HTTParty to Faraday to allow streaming and future feature and performance improvements.
18
+
-[BREAKING] Endpoints now return JSON rather than HTTParty objects. You will need to update your code to handle this change, changing `JSON.parse(response.body)["key"]` and `response.parsed_response["key"]` to just `response["key"]`.
Copy file name to clipboardExpand all lines: README.md
+32-19Lines changed: 32 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
7
7
Use the [OpenAI API](https://openai.com/blog/openai-api/) with Ruby! 🤖❤️
8
8
9
-
Generate text with ChatGPT, transcribe and translate audio with Whisper, or create images with DALL·E...
9
+
Stream text with GPT-4, transcribe and translate audio with Whisper, or create images with DALL·E...
10
10
11
11
[Ruby AI Builders Discord](https://discord.gg/k4Uc224xVD)
12
12
@@ -34,10 +34,6 @@ and require with:
34
34
require"openai"
35
35
```
36
36
37
-
## Upgrading
38
-
39
-
The `::Ruby::OpenAI` module has been removed and all classes have been moved under the top level `::OpenAI` module. To upgrade, change `require 'ruby/openai'` to `require 'openai'` and change all references to `Ruby::OpenAI` to `OpenAI`.
40
-
41
37
## Usage
42
38
43
39
- Get your API key from [https://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys)
@@ -57,8 +53,8 @@ For a more robust setup, you can configure the gem with your API keys, for examp
The default timeout for any OpenAI request is 120 seconds. You can change that passing the `request_timeout` when initializing the client. You can also change the base URI used for all requests, eg. to use observability tools like [Helicone](https://docs.helicone.ai/quickstart/integrate-in-one-line-of-code):
69
+
The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the `request_timeout` when initializing the client. You can also change the base URI used for all requests, eg. to use observability tools like [Helicone](https://docs.helicone.ai/quickstart/integrate-in-one-line-of-code):
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.
132
+
133
+
```ruby
134
+
client.chat(
135
+
parameters: {
136
+
model:"gpt-3.5-turbo", # Required.
137
+
messages: [{ role:"user", content:"Describe a character called Anna!"}], # Required.
138
+
temperature:0.7,
139
+
stream:procdo |chunk, _bytesize|
140
+
print chunk.dig("choices", 0, "delta", "content")
141
+
end
142
+
})
143
+
# => "Anna is a young woman in her mid-twenties, with wavy chestnut hair that falls to her shoulders..."
144
+
```
145
+
133
146
### Completions
134
147
135
148
Hit the OpenAI API for a completion using other GPT-3 models:
@@ -188,9 +201,9 @@ and pass the path to `client.files.upload` to upload it to OpenAI, and then inte
spec.post_install_message="Note if upgrading: The `::Ruby::OpenAI` module has been removed and all classes have been moved under the top level `::OpenAI` module. To upgrade, change `require 'ruby/openai'` to `require 'openai'` and change all references to `Ruby::OpenAI` to `OpenAI`."
0 commit comments