ruby-openai 7.0.0 → 7.0.1
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 +46 -21
- data/lib/openai/assistants.rb +3 -1
- data/lib/openai/batches.rb +1 -1
- data/lib/openai/messages.rb +1 -1
- data/lib/openai/run_steps.rb +1 -1
- data/lib/openai/runs.rb +1 -1
- data/lib/openai/threads.rb +1 -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: 4067ee94a830c3637d339dff7445d0176610bcb1d381754915a9279bedac59fa
|
4
|
+
data.tar.gz: b2f6e4e7331e1f60f32aa3c1fb5628124c3b09539b5d4e2a99ebf9e539420cd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f81268cc24c111b011aa87e1a0a877a72caf7a8b9d52cea367c35edf222909f5b8648d6925e30755a71692bd00974fc6d630c055a1639d5bbb8e9a33da11ef9
|
7
|
+
data.tar.gz: 2393f1d34582d37c2ee23f07d81d792fb60b0d5f3e9e5e2b900aa056d4ec49b23244d1d7766a3256a521e7621d17fa349f53134f9bdd64499a1fb760b2818038
|
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
|
+
## [7.0.1] - 2024-04-30
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Update to v2 of Assistants in Messages, Runs, RunSteps and Threads - thanks to [@willywg](https://github.com/willywg) and others for pointing this out.
|
13
|
+
|
8
14
|
## [7.0.0] - 2024-04-27
|
9
15
|
|
10
16
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexrudall/ruby-openai/blob/main/LICENSE.txt)
|
5
5
|
[![CircleCI Build Status](https://circleci.com/gh/alexrudall/ruby-openai.svg?style=shield)](https://circleci.com/gh/alexrudall/ruby-openai)
|
6
6
|
|
7
|
-
Use the [OpenAI API](https://openai.com/blog/openai-api/) with Ruby!
|
7
|
+
Use the [OpenAI API](https://openai.com/blog/openai-api/) with Ruby! 🤖❤️
|
8
8
|
|
9
9
|
Stream text with GPT-4, transcribe and translate audio with Whisper, or create images with DALL·E...
|
10
10
|
|
11
11
|
[🚢 Hire me](https://peaceterms.com?utm_source=ruby-openai&utm_medium=readme&utm_id=26072023) | [🎮 Ruby AI Builders Discord](https://discord.gg/k4Uc224xVD) | [🐦 Twitter](https://twitter.com/alexrudall) | [🧠 Anthropic Gem](https://github.com/alexrudall/anthropic) | [🚂 Midjourney Gem](https://github.com/alexrudall/midjourney)
|
12
12
|
|
13
|
-
|
13
|
+
## Contents
|
14
14
|
|
15
15
|
- [Ruby OpenAI](#ruby-openai)
|
16
16
|
- [Table of Contents](#table-of-contents)
|
@@ -27,6 +27,7 @@ Stream text with GPT-4, transcribe and translate audio with Whisper, or create i
|
|
27
27
|
- [Faraday middleware](#faraday-middleware)
|
28
28
|
- [Azure](#azure)
|
29
29
|
- [Ollama](#ollama)
|
30
|
+
- [Groq](#groq)
|
30
31
|
- [Counting Tokens](#counting-tokens)
|
31
32
|
- [Models](#models)
|
32
33
|
- [Chat](#chat)
|
@@ -100,7 +101,10 @@ require "openai"
|
|
100
101
|
For a quick test you can pass your token directly to a new client:
|
101
102
|
|
102
103
|
```ruby
|
103
|
-
client = OpenAI::Client.new(
|
104
|
+
client = OpenAI::Client.new(
|
105
|
+
access_token: "access_token_goes_here",
|
106
|
+
log_errors: true # Highly recommended in development, so you can see what errors OpenAI is returning. Not recommended in production.
|
107
|
+
)
|
104
108
|
```
|
105
109
|
|
106
110
|
### With Config
|
@@ -109,8 +113,9 @@ For a more robust setup, you can configure the gem with your API keys, for examp
|
|
109
113
|
|
110
114
|
```ruby
|
111
115
|
OpenAI.configure do |config|
|
112
|
-
|
113
|
-
|
116
|
+
config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN")
|
117
|
+
config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID") # Optional.
|
118
|
+
config.log_errors = true # Highly recommended in development, so you can see what errors OpenAI is returning. Not recommended in production.
|
114
119
|
end
|
115
120
|
```
|
116
121
|
|
@@ -239,6 +244,27 @@ client.chat(
|
|
239
244
|
# => Hi! It's nice to meet you. Is there something I can help you with, or would you like to chat?
|
240
245
|
```
|
241
246
|
|
247
|
+
#### Groq
|
248
|
+
|
249
|
+
[Groq API Chat](https://console.groq.com/docs/quickstart) is broadly compatible with the OpenAI API, with a [few minor differences](https://console.groq.com/docs/openai). Get an access token from [here](https://console.groq.com/keys), then:
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
client = OpenAI::Client.new(
|
253
|
+
access_token: "groq_access_token_goes_here",
|
254
|
+
uri_base: "https://api.groq.com/"
|
255
|
+
)
|
256
|
+
|
257
|
+
client.chat(
|
258
|
+
parameters: {
|
259
|
+
model: "llama3-8b-8192", # Required.
|
260
|
+
messages: [{ role: "user", content: "Hello!"}], # Required.
|
261
|
+
temperature: 0.7,
|
262
|
+
stream: proc do |chunk, _bytesize|
|
263
|
+
print chunk.dig("choices", 0, "delta", "content")
|
264
|
+
end
|
265
|
+
})
|
266
|
+
```
|
267
|
+
|
242
268
|
### Counting Tokens
|
243
269
|
|
244
270
|
OpenAI parses prompt text into [tokens](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them), which are words or portions of words. (These tokens are unrelated to your API access_token.) Counting tokens can help you estimate your [costs](https://openai.com/pricing). It can also help you ensure your prompt text size is within the max-token limits of your model's context window, and choose an appropriate [`max_tokens`](https://platform.openai.com/docs/api-reference/chat/create#chat/create-max_tokens) completion parameter so your response will fit as well.
|
@@ -247,7 +273,7 @@ To estimate the token-count of your text:
|
|
247
273
|
|
248
274
|
```ruby
|
249
275
|
OpenAI.rough_token_count("Your text")
|
250
|
-
|
276
|
+
````
|
251
277
|
|
252
278
|
If you need a more accurate count, try [tiktoken_ruby](https://github.com/IAPark/tiktoken_ruby).
|
253
279
|
|
@@ -320,12 +346,12 @@ puts response.dig("choices", 0, "message", "content")
|
|
320
346
|
|
321
347
|
#### JSON Mode
|
322
348
|
|
323
|
-
You can set the response_format to ask for responses in JSON
|
349
|
+
You can set the response_format to ask for responses in JSON:
|
324
350
|
|
325
351
|
```ruby
|
326
352
|
response = client.chat(
|
327
353
|
parameters: {
|
328
|
-
model: "gpt-3.5-turbo
|
354
|
+
model: "gpt-3.5-turbo",
|
329
355
|
response_format: { type: "json_object" },
|
330
356
|
messages: [{ role: "user", content: "Hello! Give me some JSON please."}],
|
331
357
|
temperature: 0.7,
|
@@ -345,7 +371,7 @@ You can stream it as well!
|
|
345
371
|
```ruby
|
346
372
|
response = client.chat(
|
347
373
|
parameters: {
|
348
|
-
model: "gpt-3.5-turbo
|
374
|
+
model: "gpt-3.5-turbo",
|
349
375
|
messages: [{ role: "user", content: "Can I have some JSON please?"}],
|
350
376
|
response_format: { type: "json_object" },
|
351
377
|
stream: proc do |chunk, _bytesize|
|
@@ -542,7 +568,7 @@ These files are in JSONL format, with each line representing the output or error
|
|
542
568
|
"id": "chatcmpl-abc123",
|
543
569
|
"object": "chat.completion",
|
544
570
|
"created": 1677858242,
|
545
|
-
"model": "gpt-3.5-turbo
|
571
|
+
"model": "gpt-3.5-turbo",
|
546
572
|
"choices": [
|
547
573
|
{
|
548
574
|
"index": 0,
|
@@ -638,16 +664,19 @@ To create a new assistant:
|
|
638
664
|
```ruby
|
639
665
|
response = client.assistants.create(
|
640
666
|
parameters: {
|
641
|
-
model: "gpt-3.5-turbo
|
667
|
+
model: "gpt-3.5-turbo",
|
642
668
|
name: "OpenAI-Ruby test assistant",
|
643
669
|
description: nil,
|
644
|
-
instructions: "You are a
|
670
|
+
instructions: "You are a Ruby dev bot. When asked a question, write and run Ruby code to answer the question",
|
645
671
|
tools: [
|
646
|
-
{ type:
|
647
|
-
{ type: 'code_interpreter' }, # Allow access to Python code interpreter
|
672
|
+
{ type: "code_interpreter" },
|
648
673
|
],
|
649
|
-
|
650
|
-
|
674
|
+
tool_resources: {
|
675
|
+
"code_interpreter": {
|
676
|
+
"file_ids": [] # See Files section above for how to upload files
|
677
|
+
}
|
678
|
+
},
|
679
|
+
"metadata": { my_internal_version_id: "1.0.0" }
|
651
680
|
})
|
652
681
|
assistant_id = response["id"]
|
653
682
|
```
|
@@ -829,11 +858,7 @@ client.runs.list(thread_id: thread_id, parameters: { order: "asc", limit: 3 })
|
|
829
858
|
You can also create a thread and run in one call like this:
|
830
859
|
|
831
860
|
```ruby
|
832
|
-
response = client.
|
833
|
-
parameters: {
|
834
|
-
model: 'gpt-3.5-turbo',
|
835
|
-
messages: [{ role: 'user', content: "What's deep learning?"}]
|
836
|
-
})
|
861
|
+
response = client.runs.create_thread_and_run(parameters: { assistant_id: assistant_id })
|
837
862
|
run_id = response['id']
|
838
863
|
thread_id = response['thread_id']
|
839
864
|
```
|
data/lib/openai/assistants.rb
CHANGED
data/lib/openai/batches.rb
CHANGED
data/lib/openai/messages.rb
CHANGED
data/lib/openai/run_steps.rb
CHANGED
data/lib/openai/runs.rb
CHANGED
data/lib/openai/threads.rb
CHANGED
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: 7.0.
|
4
|
+
version: 7.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|