ruby-openai 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +14 -18
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/CHANGELOG.md +41 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +14 -16
- data/README.md +20 -6
- data/lib/ruby/openai/client.rb +22 -3
- data/lib/ruby/openai/version.rb +1 -1
- data/ruby-openai.gemspec +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdfaef88879152f3de0bd34e96e5cce4c669693347715a4cc776cd2da4e27864
|
4
|
+
data.tar.gz: 171f6b21eb32a63142a11c7964d3f1871343634bbe845c30a56a9ff72ea912dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2471a90fddcad074339e338f24df56980ab47c76b70aa3f4f4d5676b6e8d841525a5d911ee69d586165697ecd177d3b9f9d11bec93a7c73f7ecc1a6df5fb4036
|
7
|
+
data.tar.gz: 41c2a29991c0b60cc574fe65fdf3043fe610a96e36075ee963882bee2b52e741d1cb57ad8a95e4a02c72eabcbb3999318ddad7f822c9b27d92802d33ae66cc47
|
data/.circleci/config.yml
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
version: 2.1 # Use 2.1 to enable using orbs and other features.
|
2
2
|
|
3
3
|
# Declare the orbs that we'll use in our config.
|
4
|
-
# read more about orbs: https://circleci.com/docs/2.0/using-orbs/
|
5
4
|
orbs:
|
6
5
|
ruby: circleci/ruby@1.0
|
7
6
|
|
8
7
|
jobs:
|
9
|
-
|
8
|
+
rubocop:
|
9
|
+
parallelism: 1
|
10
10
|
docker:
|
11
|
-
- image: cimg/ruby:2.7-node
|
11
|
+
- image: cimg/ruby:2.7-node
|
12
12
|
steps:
|
13
|
-
- checkout
|
14
|
-
- ruby/install-deps
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
- checkout
|
14
|
+
- ruby/install-deps
|
15
|
+
- run:
|
16
|
+
name: Run Rubocop
|
17
|
+
command: bundle exec rubocop
|
18
|
+
test:
|
19
19
|
parallelism: 1
|
20
20
|
docker:
|
21
|
-
- image: cimg/ruby:2.7-node
|
22
|
-
# A series of steps to run, some are similar to those in "build".
|
21
|
+
- image: cimg/ruby:2.7-node
|
23
22
|
steps:
|
24
23
|
- checkout
|
25
24
|
- ruby/install-deps
|
@@ -27,12 +26,9 @@ jobs:
|
|
27
26
|
name: Run tests
|
28
27
|
command: bundle exec rspec -fd
|
29
28
|
|
30
|
-
# We use workflows to orchestrate the jobs that we declared above.
|
31
29
|
workflows:
|
32
30
|
version: 2
|
33
|
-
|
34
|
-
jobs:
|
35
|
-
-
|
36
|
-
- test
|
37
|
-
requires: # Test requires that build passes for it to run.
|
38
|
-
- build # Finally, run the build job.
|
31
|
+
checks:
|
32
|
+
jobs:
|
33
|
+
- rubocop
|
34
|
+
- test
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Steps to reproduce the behavior:
|
15
|
+
1. Go to '...'
|
16
|
+
2. Click on '....'
|
17
|
+
3. Scroll down to '....'
|
18
|
+
4. See error
|
19
|
+
|
20
|
+
**Expected behavior**
|
21
|
+
A clear and concise description of what you expected to happen.
|
22
|
+
|
23
|
+
**Screenshots**
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
25
|
+
|
26
|
+
**Desktop (please complete the following information):**
|
27
|
+
- OS: [e.g. iOS]
|
28
|
+
- Browser [e.g. chrome, safari]
|
29
|
+
- Version [e.g. 22]
|
30
|
+
|
31
|
+
**Smartphone (please complete the following information):**
|
32
|
+
- Device: [e.g. iPhone6]
|
33
|
+
- OS: [e.g. iOS8.1]
|
34
|
+
- Browser [e.g. stock browser, safari]
|
35
|
+
- Version [e.g. 22]
|
36
|
+
|
37
|
+
**Additional context**
|
38
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
A clear and concise description of what you want to happen.
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
Add any other context or screenshots about the feature request here.
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,47 @@ 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
|
-
## [
|
8
|
+
## [0.2.0] - 2020-11-22
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add method to use the search endpoint.
|
13
|
+
|
14
|
+
## [0.1.4] - 2020-10-18
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Bump Rubocop to 3.9.2.
|
19
|
+
- Bump Webmock to 3.9.1.
|
20
|
+
|
21
|
+
## [0.1.3] - 2020-09-09
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- Add ability to change API version in the future.
|
26
|
+
- Fix README typos.
|
27
|
+
|
28
|
+
## [0.1.2] - 2020-09-09
|
29
|
+
|
30
|
+
### Added
|
31
|
+
|
32
|
+
- Add tests and cached responses for the different engines.
|
33
|
+
- Add issue templates.
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
|
37
|
+
- Add README instructions for using the gem without dotenv.
|
38
|
+
- Add list of engines to README.
|
39
|
+
|
40
|
+
## [0.1.1] - 2020-09-08
|
41
|
+
|
42
|
+
### Added
|
43
|
+
|
44
|
+
- Run Rubocop on pulls using CircleCI.
|
45
|
+
|
46
|
+
### Changed
|
47
|
+
|
48
|
+
- Clean up CircleCI config file.
|
9
49
|
|
10
50
|
## [0.1.0] - 2020-09-06
|
11
51
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-openai (0.
|
4
|
+
ruby-openai (0.2.0)
|
5
5
|
dotenv (~> 2.7.6)
|
6
6
|
httparty (~> 0.18.1)
|
7
7
|
|
@@ -12,8 +12,7 @@ GEM
|
|
12
12
|
public_suffix (>= 2.0.2, < 5.0)
|
13
13
|
ast (2.4.1)
|
14
14
|
byebug (11.1.3)
|
15
|
-
crack (0.4.
|
16
|
-
safe_yaml (~> 1.0.0)
|
15
|
+
crack (0.4.4)
|
17
16
|
diff-lcs (1.4.4)
|
18
17
|
dotenv (2.7.6)
|
19
18
|
hashdiff (1.0.1)
|
@@ -25,12 +24,12 @@ GEM
|
|
25
24
|
mime-types-data (3.2020.0512)
|
26
25
|
multi_xml (0.6.0)
|
27
26
|
parallel (1.19.2)
|
28
|
-
parser (2.7.
|
27
|
+
parser (2.7.2.0)
|
29
28
|
ast (~> 2.4.1)
|
30
|
-
public_suffix (4.0.
|
29
|
+
public_suffix (4.0.6)
|
31
30
|
rainbow (3.0.0)
|
32
31
|
rake (13.0.1)
|
33
|
-
regexp_parser (1.
|
32
|
+
regexp_parser (1.8.2)
|
34
33
|
rexml (3.2.4)
|
35
34
|
rspec (3.9.0)
|
36
35
|
rspec-core (~> 3.9.0)
|
@@ -45,22 +44,21 @@ GEM
|
|
45
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
45
|
rspec-support (~> 3.9.0)
|
47
46
|
rspec-support (3.9.3)
|
48
|
-
rubocop (0.
|
47
|
+
rubocop (0.93.1)
|
49
48
|
parallel (~> 1.10)
|
50
|
-
parser (>= 2.7.1.
|
49
|
+
parser (>= 2.7.1.5)
|
51
50
|
rainbow (>= 2.2.2, < 4.0)
|
52
|
-
regexp_parser (>= 1.
|
51
|
+
regexp_parser (>= 1.8)
|
53
52
|
rexml
|
54
|
-
rubocop-ast (>= 0.
|
53
|
+
rubocop-ast (>= 0.6.0)
|
55
54
|
ruby-progressbar (~> 1.7)
|
56
55
|
unicode-display_width (>= 1.4.0, < 2.0)
|
57
|
-
rubocop-ast (0.
|
58
|
-
parser (>= 2.7.1.
|
56
|
+
rubocop-ast (0.7.1)
|
57
|
+
parser (>= 2.7.1.5)
|
59
58
|
ruby-progressbar (1.10.1)
|
60
|
-
safe_yaml (1.0.5)
|
61
59
|
unicode-display_width (1.7.0)
|
62
60
|
vcr (6.0.0)
|
63
|
-
webmock (3.
|
61
|
+
webmock (3.9.2)
|
64
62
|
addressable (>= 2.3.6)
|
65
63
|
crack (>= 0.3.2)
|
66
64
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -72,10 +70,10 @@ DEPENDENCIES
|
|
72
70
|
byebug (~> 11.1.3)
|
73
71
|
rake (~> 13.0)
|
74
72
|
rspec (~> 3.0)
|
75
|
-
rubocop (~> 0.
|
73
|
+
rubocop (~> 0.93.1)
|
76
74
|
ruby-openai!
|
77
75
|
vcr (~> 6.0.0)
|
78
|
-
webmock (~> 3.
|
76
|
+
webmock (~> 3.9.2)
|
79
77
|
|
80
78
|
BUNDLED WITH
|
81
79
|
2.1.4
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Ruby::OpenAI
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ruby-openai.svg)](https://badge.fury.io/rb/ruby-openai)
|
4
4
|
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexrudall/ruby-openai/blob/master/LICENSE.txt)
|
5
|
+
[![CircleCI Build Status](https://circleci.com/gh/alexrudall/ruby-openai.svg?style=shield)](https://circleci.com/gh/alexrudall/ruby-openai)
|
5
6
|
|
6
7
|
A simple Ruby wrapper for the [OpenAI GPT-3 API](https://openai.com/blog/openai-api/).
|
7
8
|
|
@@ -25,23 +26,36 @@ Or install it yourself as:
|
|
25
26
|
|
26
27
|
Get your API key from [https://beta.openai.com/docs/developer-quickstart/your-api-keys](https://beta.openai.com/docs/developer-quickstart/your-api-keys)
|
27
28
|
|
28
|
-
|
29
|
+
### With dotenv
|
30
|
+
|
31
|
+
If you're using [dotenv](https://github.com/motdotla/dotenv), you can add your secret key to your .env file:
|
29
32
|
|
30
33
|
```
|
31
|
-
OPENAI_ACCESS_TOKEN=
|
34
|
+
OPENAI_ACCESS_TOKEN=access_token_goes_here
|
32
35
|
```
|
33
36
|
|
34
|
-
|
37
|
+
And create a client:
|
35
38
|
|
36
39
|
```
|
37
40
|
client = OpenAI::Client.new
|
38
41
|
```
|
39
42
|
|
40
|
-
|
43
|
+
### Without dotenv
|
44
|
+
|
45
|
+
Alternatively you can pass your key directly to a new client:
|
46
|
+
|
47
|
+
```
|
48
|
+
client = OpenAI::Client.new(access_token: "access_token_goes_here")
|
49
|
+
```
|
50
|
+
|
51
|
+
### Get a response
|
52
|
+
|
53
|
+
The engine options are currently "ada", "babbage", "curie" and "davinci". Hit the OpenAI API for a completion:
|
41
54
|
|
42
55
|
```
|
43
56
|
response = client.call(engine: "davinci", prompt: "Once upon a time", max_tokens: 5)
|
44
|
-
response.parsed_response['choices'].map{ |c| c["text"] }
|
57
|
+
puts response.parsed_response['choices'].map{ |c| c["text"] }
|
58
|
+
=> [", there lived a great"]
|
45
59
|
```
|
46
60
|
|
47
61
|
## Development
|
data/lib/ruby/openai/client.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module OpenAI
|
2
2
|
class Client
|
3
3
|
include HTTParty
|
4
|
-
base_uri "https://api.openai.com
|
4
|
+
base_uri "https://api.openai.com"
|
5
5
|
|
6
6
|
def initialize(access_token: nil)
|
7
7
|
@access_token = access_token || ENV["OPENAI_ACCESS_TOKEN"]
|
8
8
|
end
|
9
9
|
|
10
|
-
def call(engine:, prompt:, max_tokens:)
|
10
|
+
def call(engine:, prompt:, max_tokens:, version: default_version)
|
11
11
|
self.class.post(
|
12
|
-
"/#{engine}/completions",
|
12
|
+
"/#{version}/engines/#{engine}/completions",
|
13
13
|
headers: {
|
14
14
|
"Content-Type" => "application/json",
|
15
15
|
"Authorization" => "Bearer #{@access_token}"
|
@@ -19,5 +19,24 @@ module OpenAI
|
|
19
19
|
}.to_json
|
20
20
|
)
|
21
21
|
end
|
22
|
+
|
23
|
+
def search(engine:, documents:, query:, version: default_version)
|
24
|
+
self.class.post(
|
25
|
+
"/#{version}/engines/#{engine}/search",
|
26
|
+
headers: {
|
27
|
+
"Content-Type" => "application/json",
|
28
|
+
"Authorization" => "Bearer #{@access_token}"
|
29
|
+
},
|
30
|
+
body: {
|
31
|
+
documents: documents, query: query
|
32
|
+
}.to_json
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def default_version
|
39
|
+
"v1".freeze
|
40
|
+
end
|
22
41
|
end
|
23
42
|
end
|
data/lib/ruby/openai/version.rb
CHANGED
data/ruby-openai.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.summary = "A Ruby gem for the OpenAI GPT-3 API"
|
10
10
|
spec.homepage = "https://github.com/alexrudall/ruby-openai"
|
11
11
|
spec.license = "MIT"
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
13
13
|
|
14
14
|
spec.metadata["homepage_uri"] = spec.homepage
|
15
15
|
spec.metadata["source_code_uri"] = "https://github.com/alexrudall/ruby-openai"
|
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: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -46,6 +46,8 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".circleci/config.yml"
|
49
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
50
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
49
51
|
- ".gitignore"
|
50
52
|
- ".rspec"
|
51
53
|
- ".rubocop.yml"
|
@@ -78,14 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
80
|
requirements:
|
79
81
|
- - ">="
|
80
82
|
- !ruby/object:Gem::Version
|
81
|
-
version: 2.
|
83
|
+
version: 2.7.0
|
82
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
85
|
requirements:
|
84
86
|
- - ">="
|
85
87
|
- !ruby/object:Gem::Version
|
86
88
|
version: '0'
|
87
89
|
requirements: []
|
88
|
-
rubygems_version: 3.1.
|
90
|
+
rubygems_version: 3.1.4
|
89
91
|
signing_key:
|
90
92
|
specification_version: 4
|
91
93
|
summary: A Ruby gem for the OpenAI GPT-3 API
|