ruby-openai 3.3.0 → 3.5.0
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/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -7
- data/README.md +49 -2
- data/lib/openai/client.rb +12 -0
- data/lib/openai/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe7d331fc5d5a16f74089b9395232cd1abf0d6b05bd78be4db91e1b65d71a4c
|
4
|
+
data.tar.gz: 610d363ebf1d6a53f015aeaf20cd551c1020731fd423ba4074ff3eb044239fa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08b25f159fc149ccd09034da891cf5e77c999964a6d06ea6d916c62ad3e4a9ba2b1aa73757b617c0152ca1760f386514da081e978a6ca9963706f3f385814b78'
|
7
|
+
data.tar.gz: 144bd11f3791fa818193eaab7d8eeb6b04c33f4b99342ca573acea76f0ffcef4604033daaea54b2ae43411abf84e572db97304f7195c08116a55fedd1524d2aa
|
data/CHANGELOG.md
CHANGED
@@ -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
|
+
## [3.5.0] - 2023-03-02
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add Client#transcribe and Client translate endpoints - Whisper over the wire! Thanks to [@Clemalfroy](https://github.com/Clemalfroy)
|
13
|
+
|
14
|
+
## [3.4.0] - 2023-03-01
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Add Client#chat endpoint - ChatGPT over the wire!
|
19
|
+
|
8
20
|
## [3.3.0] - 2023-02-15
|
9
21
|
|
10
22
|
### Changed
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-openai (3.
|
4
|
+
ruby-openai (3.5.0)
|
5
5
|
httparty (>= 0.18.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
mini_mime (1.1.2)
|
24
24
|
multi_xml (0.6.0)
|
25
25
|
parallel (1.22.1)
|
26
|
-
parser (3.2.
|
26
|
+
parser (3.2.1.0)
|
27
27
|
ast (~> 2.4.1)
|
28
28
|
public_suffix (5.0.1)
|
29
29
|
rainbow (3.1.1)
|
@@ -43,18 +43,18 @@ GEM
|
|
43
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
44
|
rspec-support (~> 3.12.0)
|
45
45
|
rspec-support (3.12.0)
|
46
|
-
rubocop (1.
|
46
|
+
rubocop (1.46.0)
|
47
47
|
json (~> 2.3)
|
48
48
|
parallel (~> 1.10)
|
49
49
|
parser (>= 3.2.0.0)
|
50
50
|
rainbow (>= 2.2.2, < 4.0)
|
51
51
|
regexp_parser (>= 1.8, < 3.0)
|
52
52
|
rexml (>= 3.2.5, < 4.0)
|
53
|
-
rubocop-ast (>= 1.
|
53
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
54
54
|
ruby-progressbar (~> 1.7)
|
55
55
|
unicode-display_width (>= 2.4.0, < 3.0)
|
56
|
-
rubocop-ast (1.
|
57
|
-
parser (>= 3.
|
56
|
+
rubocop-ast (1.26.0)
|
57
|
+
parser (>= 3.2.1.0)
|
58
58
|
ruby-progressbar (1.11.0)
|
59
59
|
unicode-display_width (2.4.2)
|
60
60
|
vcr (6.1.0)
|
@@ -71,7 +71,7 @@ DEPENDENCIES
|
|
71
71
|
dotenv (~> 2.8.1)
|
72
72
|
rake (~> 13.0)
|
73
73
|
rspec (~> 3.12)
|
74
|
-
rubocop (~> 1.
|
74
|
+
rubocop (~> 1.46.0)
|
75
75
|
ruby-openai!
|
76
76
|
vcr (~> 6.1.0)
|
77
77
|
webmock (~> 3.18.1)
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
Use the [OpenAI API](https://openai.com/blog/openai-api/) with Ruby! 🤖❤️
|
9
9
|
|
10
|
-
Generate text with
|
10
|
+
Generate text with ChatGPT, transcribe or translate audio with Whisper, create images with DALL·E, or write code with Codex...
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -89,9 +89,24 @@ There are different models that can be used to generate text. For a full list an
|
|
89
89
|
- code-davinci-002
|
90
90
|
- code-cushman-001
|
91
91
|
|
92
|
+
### ChatGPT
|
93
|
+
|
94
|
+
ChatGPT is a model that can be used to generate text in a conversational style. You can use it to generate a response to a sequence of [messages](https://platform.openai.com/docs/guides/chat/introduction):
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
response = client.chat(
|
98
|
+
parameters: {
|
99
|
+
model: "gpt-3.5-turbo",
|
100
|
+
messages: [{ role: "user", content: "Hello!"}],
|
101
|
+
})
|
102
|
+
puts response.dig("choices", 0, "message", "content")
|
103
|
+
=> "Hello! How may I assist you today?"
|
104
|
+
|
105
|
+
```
|
106
|
+
|
92
107
|
### Completions
|
93
108
|
|
94
|
-
Hit the OpenAI API for a completion:
|
109
|
+
Hit the OpenAI API for a completion using other GPT-3 models:
|
95
110
|
|
96
111
|
```ruby
|
97
112
|
response = client.completions(
|
@@ -252,6 +267,38 @@ Pass a string to check if it violates OpenAI's Content Policy:
|
|
252
267
|
=> 5.505014632944949e-05
|
253
268
|
```
|
254
269
|
|
270
|
+
### Whisper
|
271
|
+
|
272
|
+
Whisper is a speech to text model that can be used to generate text based on an audio files:
|
273
|
+
|
274
|
+
#### Translate
|
275
|
+
|
276
|
+
The translations API takes as input the audio file in any of the supported languages and transcribes the audio into English.
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
response = client.translate(
|
280
|
+
parameters: {
|
281
|
+
model: "whisper-1",
|
282
|
+
file: File.open('path_to_file'),
|
283
|
+
})
|
284
|
+
puts response.parsed_body['text']
|
285
|
+
=> "Translation of the text"
|
286
|
+
```
|
287
|
+
|
288
|
+
#### Transcribe
|
289
|
+
|
290
|
+
The transcriptions API takes as input the audio file you want to transcribe and returns the text in the desired output file format.
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
response = client.transcribe(
|
294
|
+
parameters: {
|
295
|
+
model: "whisper-1",
|
296
|
+
file: File.open('path_to_file'),
|
297
|
+
})
|
298
|
+
puts response.parsed_body['text']
|
299
|
+
=> "Transcription of the text"
|
300
|
+
```
|
301
|
+
|
255
302
|
## Development
|
256
303
|
|
257
304
|
After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/openai/client.rb
CHANGED
@@ -7,6 +7,10 @@ module OpenAI
|
|
7
7
|
OpenAI.configuration.organization_id = organization_id if organization_id
|
8
8
|
end
|
9
9
|
|
10
|
+
def chat(parameters: {})
|
11
|
+
OpenAI::Client.json_post(path: "/chat/completions", parameters: parameters)
|
12
|
+
end
|
13
|
+
|
10
14
|
def completions(parameters: {})
|
11
15
|
OpenAI::Client.json_post(path: "/completions", parameters: parameters)
|
12
16
|
end
|
@@ -39,6 +43,14 @@ module OpenAI
|
|
39
43
|
OpenAI::Client.json_post(path: "/moderations", parameters: parameters)
|
40
44
|
end
|
41
45
|
|
46
|
+
def transcribe(parameters: {})
|
47
|
+
OpenAI::Client.multipart_post(path: "/audio/transcriptions", parameters: parameters)
|
48
|
+
end
|
49
|
+
|
50
|
+
def translate(parameters: {})
|
51
|
+
OpenAI::Client.multipart_post(path: "/audio/translations", parameters: parameters)
|
52
|
+
end
|
53
|
+
|
42
54
|
def self.get(path:)
|
43
55
|
HTTParty.get(
|
44
56
|
uri(path: path),
|
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: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02
|
11
|
+
date: 2023-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.18.1
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- alexrudall@users.noreply.github.com
|
30
30
|
executables: []
|
@@ -85,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
rubygems_version: 3.4.
|
89
|
-
signing_key:
|
88
|
+
rubygems_version: 3.4.6
|
89
|
+
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: A Ruby gem for the OpenAI GPT-3 API
|
92
92
|
test_files: []
|