ruby-openai 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +6 -6
- data/README.md +24 -0
- data/lib/ruby/openai.rb +1 -0
- data/lib/ruby/openai/client.rb +10 -4
- data/lib/ruby/openai/files.rb +57 -0
- data/lib/ruby/openai/version.rb +1 -1
- data/pull_request_template.md +5 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fb70b90b84ff4b23bf8e9ed757ae39b82adf291e5bdcb07b8f0ef5ccbe12394
|
4
|
+
data.tar.gz: 5391b9437fd05d7da1783e5ac960b216a7ad326f22a509ad28a21eb879bdf4a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cbf287bf8bfc9e1b949bc050ea456d62c5259a5316710db7a617126a7a3b018707c78c03d508a5619ac024a5767865f7e98925e5c6e867dc8cb1f3687e3b9c6
|
7
|
+
data.tar.gz: a45ed235da6d261371ae6f1b26ae45ea2f28dd9ca3f9b362b66045d851666ea1b72e89c0253d64830183c6bae6c3c8093f7c586c65aed940b5b3003d9b652399
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,13 @@ 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
|
+
## [1.1.0] - 2021-04-07
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add Client#files to allow file upload.
|
13
|
+
- Add Client#search(file:) so you can search a file.
|
14
|
+
|
8
15
|
## [1.0.0] - 2021-02-01
|
9
16
|
|
10
17
|
### Removed
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alexrudall/ruby-openai. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/alexrudall/ruby-openai/blob/main/CODE_OF_CONDUCT.md).
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-openai (1.
|
4
|
+
ruby-openai (1.1.0)
|
5
5
|
dotenv (~> 2.7.6)
|
6
6
|
httparty (~> 0.18.1)
|
7
7
|
|
@@ -30,7 +30,7 @@ GEM
|
|
30
30
|
public_suffix (4.0.6)
|
31
31
|
rainbow (3.0.0)
|
32
32
|
rake (13.0.3)
|
33
|
-
regexp_parser (2.
|
33
|
+
regexp_parser (2.1.1)
|
34
34
|
rexml (3.2.4)
|
35
35
|
rspec (3.10.0)
|
36
36
|
rspec-core (~> 3.10.0)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
46
|
rspec-support (~> 3.10.0)
|
47
47
|
rspec-support (3.10.1)
|
48
|
-
rubocop (1.
|
48
|
+
rubocop (1.12.1)
|
49
49
|
parallel (~> 1.10)
|
50
50
|
parser (>= 3.0.0.0)
|
51
51
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -59,7 +59,7 @@ GEM
|
|
59
59
|
ruby-progressbar (1.11.0)
|
60
60
|
unicode-display_width (2.0.0)
|
61
61
|
vcr (6.0.0)
|
62
|
-
webmock (3.
|
62
|
+
webmock (3.12.2)
|
63
63
|
addressable (>= 2.3.6)
|
64
64
|
crack (>= 0.3.2)
|
65
65
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -71,10 +71,10 @@ DEPENDENCIES
|
|
71
71
|
byebug (~> 11.1.3)
|
72
72
|
rake (~> 13.0)
|
73
73
|
rspec (~> 3.10)
|
74
|
-
rubocop (~> 1.
|
74
|
+
rubocop (~> 1.12.1)
|
75
75
|
ruby-openai!
|
76
76
|
vcr (~> 6.0.0)
|
77
|
-
webmock (~> 3.
|
77
|
+
webmock (~> 3.12.2)
|
78
78
|
|
79
79
|
BUNDLED WITH
|
80
80
|
2.2.3
|
data/README.md
CHANGED
@@ -58,6 +58,24 @@ The engine options are currently "ada", "babbage", "curie" and "davinci". Hit th
|
|
58
58
|
=> [", there lived a great"]
|
59
59
|
```
|
60
60
|
|
61
|
+
### Files
|
62
|
+
|
63
|
+
Put your data in a `.jsonl` file like this:
|
64
|
+
|
65
|
+
```
|
66
|
+
{"text": "puppy A is happy", "metadata": "emotional state of puppy A"}
|
67
|
+
{"text": "puppy B is sad", "metadata": "emotional state of puppy B"}
|
68
|
+
```
|
69
|
+
|
70
|
+
and pass the path to `client.files.upload` to upload it to OpenAI, and then interact with it:
|
71
|
+
|
72
|
+
```
|
73
|
+
client.files.upload(parameters: { file: 'path/to/puppy.jsonl', purpose: 'search' })
|
74
|
+
client.files.list
|
75
|
+
client.files.retrieve(id: 123)
|
76
|
+
client.files.delete(id: 123)
|
77
|
+
```
|
78
|
+
|
61
79
|
### Search
|
62
80
|
|
63
81
|
Pass documents and a query string to get semantic search scores against each document:
|
@@ -68,6 +86,12 @@ Pass documents and a query string to get semantic search scores against each doc
|
|
68
86
|
=> [202.0, 48.052, 19.247]
|
69
87
|
```
|
70
88
|
|
89
|
+
You can alternatively search using the ID of a file you've uploaded:
|
90
|
+
|
91
|
+
```
|
92
|
+
client.search(engine: "ada", file: "abc123", query: "happy")
|
93
|
+
```
|
94
|
+
|
71
95
|
## Development
|
72
96
|
|
73
97
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/ruby/openai.rb
CHANGED
data/lib/ruby/openai/client.rb
CHANGED
@@ -18,16 +18,18 @@ module OpenAI
|
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def files
|
22
|
+
@files ||= OpenAI::Files.new(access_token: @access_token)
|
23
|
+
end
|
24
|
+
|
25
|
+
def search(engine:, query:, documents: nil, file: nil, version: default_version)
|
22
26
|
self.class.post(
|
23
27
|
"/#{version}/engines/#{engine}/search",
|
24
28
|
headers: {
|
25
29
|
"Content-Type" => "application/json",
|
26
30
|
"Authorization" => "Bearer #{@access_token}"
|
27
31
|
},
|
28
|
-
body: {
|
29
|
-
documents: documents, query: query
|
30
|
-
}.to_json
|
32
|
+
body: { query: query }.merge(documents_or_file(documents: documents, file: file)).to_json
|
31
33
|
)
|
32
34
|
end
|
33
35
|
|
@@ -36,5 +38,9 @@ module OpenAI
|
|
36
38
|
def default_version
|
37
39
|
"v1".freeze
|
38
40
|
end
|
41
|
+
|
42
|
+
def documents_or_file(documents: nil, file: nil)
|
43
|
+
documents ? { documents: documents } : { file: file }
|
44
|
+
end
|
39
45
|
end
|
40
46
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module OpenAI
|
2
|
+
class Files
|
3
|
+
include HTTParty
|
4
|
+
base_uri "https://api.openai.com"
|
5
|
+
|
6
|
+
def initialize(access_token: nil)
|
7
|
+
@access_token = access_token || ENV["OPENAI_ACCESS_TOKEN"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(version: default_version)
|
11
|
+
self.class.get(
|
12
|
+
"/#{version}/files",
|
13
|
+
headers: {
|
14
|
+
"Content-Type" => "application/json",
|
15
|
+
"Authorization" => "Bearer #{@access_token}"
|
16
|
+
}
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload(version: default_version, parameters: {})
|
21
|
+
self.class.post(
|
22
|
+
"/#{version}/files",
|
23
|
+
headers: {
|
24
|
+
"Content-Type" => "application/json",
|
25
|
+
"Authorization" => "Bearer #{@access_token}"
|
26
|
+
},
|
27
|
+
body: parameters.merge(file: File.open(parameters[:file]))
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def retrieve(id:, version: default_version)
|
32
|
+
self.class.get(
|
33
|
+
"/#{version}/files/#{id}",
|
34
|
+
headers: {
|
35
|
+
"Content-Type" => "application/json",
|
36
|
+
"Authorization" => "Bearer #{@access_token}"
|
37
|
+
}
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(id:, version: default_version)
|
42
|
+
self.class.delete(
|
43
|
+
"/#{version}/files/#{id}",
|
44
|
+
headers: {
|
45
|
+
"Content-Type" => "application/json",
|
46
|
+
"Authorization" => "Bearer #{@access_token}"
|
47
|
+
}
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def default_version
|
54
|
+
"v1".freeze
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/ruby/openai/version.rb
CHANGED
@@ -0,0 +1,5 @@
|
|
1
|
+
## All Submissions:
|
2
|
+
|
3
|
+
* [ ] Have you followed the guidelines in our [Contributing document](../blob/main/CONTRIBUTING.md)?
|
4
|
+
* [ ] Have you checked to ensure there aren't other open [Pull Requests](../pulls) for the same update/change?
|
5
|
+
* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
|
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: 1.
|
4
|
+
version: 1.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: 2021-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- ".travis.yml"
|
55
55
|
- CHANGELOG.md
|
56
56
|
- CODE_OF_CONDUCT.md
|
57
|
+
- CONTRIBUTING.md
|
57
58
|
- Gemfile
|
58
59
|
- Gemfile.lock
|
59
60
|
- LICENSE.txt
|
@@ -63,7 +64,9 @@ files:
|
|
63
64
|
- bin/setup
|
64
65
|
- lib/ruby/openai.rb
|
65
66
|
- lib/ruby/openai/client.rb
|
67
|
+
- lib/ruby/openai/files.rb
|
66
68
|
- lib/ruby/openai/version.rb
|
69
|
+
- pull_request_template.md
|
67
70
|
- ruby-openai.gemspec
|
68
71
|
homepage: https://github.com/alexrudall/ruby-openai
|
69
72
|
licenses:
|