openai_ruby 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -9
- data/lib/openai_ruby/client.rb +9 -1
- data/lib/openai_ruby/version.rb +1 -1
- data/lib/openai_ruby.rb +1 -0
- data/openai_ruby.gemspec +36 -0
- metadata +2 -3
- data/.rspec_status +0 -3
- data/Gemfile.lock +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4c166c6a904ae2e24c863aa5fc906f92ae6be0a01b239524c5f6ceb9f1db125
|
4
|
+
data.tar.gz: ce98d485c2a40eda5dd2139721bd4507e7eb9b7e947757cfe790e6061c4534a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3e938b3e14930e9c12f5b4aa68e1f56e528e298a48089a6a0e96a2ae0dddff6ce6a54b66cfeec0f09512dc7d62a65117f889606bfe9570d133c629e022853c0
|
7
|
+
data.tar.gz: acad979520949c2d763f3834f97411b44a0532795451af51f63e72737957cae79bc219b421ed41187f3352232600914cf52e9e79fbc7f1dc1bc9234a741ce276
|
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# OpenAI Ruby library
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/openai_ruby.svg)](https://badge.fury.io/rb/openai_ruby)
|
4
|
+
[![Build Status](https://travis-ci.org/renny-ren/openai_ruby.svg?branch=main)](https://travis-ci.org/renny-ren/openai_ruby)
|
5
|
+
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/renny-ren/openai_ruby/blob/main/LICENSE)
|
4
6
|
|
5
|
-
This is a Ruby wrapper for [OpenAI API](https://openai.com/api/), which provides convenient access to the OpenAI API from applications written in Ruby
|
7
|
+
This is a Ruby wrapper for [OpenAI API](https://openai.com/api/), which provides convenient access to the OpenAI API from applications written in Ruby.
|
8
|
+
|
9
|
+
Let's build next-gen apps with OpenAI’s powerful models.
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
@@ -18,24 +22,65 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
25
|
+
Before starting, you need to have an API key, if not, create one [here](https://platform.openai.com/account/api-keys)
|
26
|
+
|
27
|
+
create a client like this:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
client = OpenAI::Client.new("your OpenAI key here")
|
31
|
+
```
|
32
|
+
|
33
|
+
### Completion
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
res = client.create_completion(
|
37
|
+
model: "text-davinci-003", # The model which will generate the completion
|
38
|
+
prompt: "Hello, who are you?",
|
39
|
+
max_tokens: 100 # The maximum number of tokens to generate
|
40
|
+
temperature: 0.5, # Control randomness
|
41
|
+
top_p: 1,
|
42
|
+
frequency_penalty: 0,
|
43
|
+
presence_penalty: 0,
|
44
|
+
stop: "\n"
|
45
|
+
)
|
46
|
+
p res.status # 200
|
47
|
+
response = JSON.parse(res.body)
|
48
|
+
|
49
|
+
p response.dig("choices", 0, "text") # "I am an AI created by OpenAI."
|
50
|
+
p response.dig('usage', 'total_tokens') # 18
|
51
|
+
```
|
52
|
+
|
53
|
+
### Edit
|
54
|
+
|
21
55
|
```ruby
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
max_tokens: 100
|
56
|
+
res = client.create_edit(
|
57
|
+
model: "text-davinci-edit-001",
|
58
|
+
input: "What are the date today?",
|
59
|
+
instruction: "Fix the grammer."
|
27
60
|
)
|
61
|
+
response = JSON.parse(res.body)
|
62
|
+
p response.dig("choices", 0, "text") # "What is the date today?\n"
|
63
|
+
```
|
64
|
+
|
65
|
+
### Image
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
|
28
69
|
```
|
29
70
|
|
30
71
|
## Development
|
31
72
|
|
32
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
74
|
+
|
75
|
+
You can run `rake spec` to run the tests.
|
76
|
+
|
77
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
78
|
|
34
79
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
80
|
|
36
81
|
## Contributing
|
37
82
|
|
38
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/renny-ren/
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/renny-ren/openai_ruby. 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/renny-ren/openai_ruby/blob/main/CODE_OF_CONDUCT.md).
|
39
84
|
|
40
85
|
## License
|
41
86
|
|
@@ -43,4 +88,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
43
88
|
|
44
89
|
## Code of Conduct
|
45
90
|
|
46
|
-
Everyone interacting in the Openai::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/renny-ren/
|
91
|
+
Everyone interacting in the Openai::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/renny-ren/openai_ruby/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/openai_ruby/client.rb
CHANGED
@@ -10,7 +10,7 @@ module OpenAI
|
|
10
10
|
@api_key = api_key
|
11
11
|
end
|
12
12
|
|
13
|
-
def create_completion(params)
|
13
|
+
def create_completion(params = {})
|
14
14
|
Faraday.post(
|
15
15
|
"#{BASE_URL}/v1/completions",
|
16
16
|
params.to_json,
|
@@ -18,6 +18,14 @@ module OpenAI
|
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
|
+
def create_edit(params = {})
|
22
|
+
Faraday.post(
|
23
|
+
"#{BASE_URL}/v1/edits",
|
24
|
+
params.to_json,
|
25
|
+
headers
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
21
29
|
private
|
22
30
|
|
23
31
|
def headers
|
data/lib/openai_ruby/version.rb
CHANGED
data/lib/openai_ruby.rb
CHANGED
data/openai_ruby.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/openai_ruby/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "openai_ruby"
|
7
|
+
spec.version = OpenAI::VERSION
|
8
|
+
spec.authors = ["Renny Ren"]
|
9
|
+
spec.email = ["rennyrjh@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A Ruby wrapper for OpenAI API"
|
12
|
+
spec.homepage = "https://github.com/renny-ren/openai_ruby"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/renny-ren/openai_ruby"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/renny-ren/openai_ruby/blob/main/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency "faraday", "~> 2.7"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, check out our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openai_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renny Ren
|
@@ -32,18 +32,17 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".rspec"
|
35
|
-
- ".rspec_status"
|
36
35
|
- ".rubocop.yml"
|
37
36
|
- CHANGELOG.md
|
38
37
|
- CODE_OF_CONDUCT.md
|
39
38
|
- Gemfile
|
40
|
-
- Gemfile.lock
|
41
39
|
- LICENSE
|
42
40
|
- README.md
|
43
41
|
- Rakefile
|
44
42
|
- lib/openai_ruby.rb
|
45
43
|
- lib/openai_ruby/client.rb
|
46
44
|
- lib/openai_ruby/version.rb
|
45
|
+
- openai_ruby.gemspec
|
47
46
|
- sig/openai_ruby/ruby.rbs
|
48
47
|
homepage: https://github.com/renny-ren/openai_ruby
|
49
48
|
licenses:
|
data/.rspec_status
DELETED
data/Gemfile.lock
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
oepnai_ruby (0.2.1)
|
5
|
-
faraday (~> 2.7)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ast (2.4.2)
|
11
|
-
diff-lcs (1.5.0)
|
12
|
-
faraday (2.7.4)
|
13
|
-
faraday-net_http (>= 2.0, < 3.1)
|
14
|
-
ruby2_keywords (>= 0.0.4)
|
15
|
-
faraday-net_http (3.0.2)
|
16
|
-
json (2.6.3)
|
17
|
-
parallel (1.22.1)
|
18
|
-
parser (3.2.1.0)
|
19
|
-
ast (~> 2.4.1)
|
20
|
-
rainbow (3.1.1)
|
21
|
-
rake (13.0.6)
|
22
|
-
regexp_parser (2.7.0)
|
23
|
-
rexml (3.2.5)
|
24
|
-
rspec (3.12.0)
|
25
|
-
rspec-core (~> 3.12.0)
|
26
|
-
rspec-expectations (~> 3.12.0)
|
27
|
-
rspec-mocks (~> 3.12.0)
|
28
|
-
rspec-core (3.12.1)
|
29
|
-
rspec-support (~> 3.12.0)
|
30
|
-
rspec-expectations (3.12.2)
|
31
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
-
rspec-support (~> 3.12.0)
|
33
|
-
rspec-mocks (3.12.3)
|
34
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
-
rspec-support (~> 3.12.0)
|
36
|
-
rspec-support (3.12.0)
|
37
|
-
rubocop (1.45.1)
|
38
|
-
json (~> 2.3)
|
39
|
-
parallel (~> 1.10)
|
40
|
-
parser (>= 3.2.0.0)
|
41
|
-
rainbow (>= 2.2.2, < 4.0)
|
42
|
-
regexp_parser (>= 1.8, < 3.0)
|
43
|
-
rexml (>= 3.2.5, < 4.0)
|
44
|
-
rubocop-ast (>= 1.24.1, < 2.0)
|
45
|
-
ruby-progressbar (~> 1.7)
|
46
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
47
|
-
rubocop-ast (1.26.0)
|
48
|
-
parser (>= 3.2.1.0)
|
49
|
-
ruby-progressbar (1.11.0)
|
50
|
-
ruby2_keywords (0.0.5)
|
51
|
-
unicode-display_width (2.4.2)
|
52
|
-
|
53
|
-
PLATFORMS
|
54
|
-
arm64-darwin-22
|
55
|
-
|
56
|
-
DEPENDENCIES
|
57
|
-
oepnai_ruby!
|
58
|
-
rake (~> 13.0)
|
59
|
-
rspec (~> 3.12)
|
60
|
-
rubocop (~> 1.45)
|
61
|
-
|
62
|
-
BUNDLED WITH
|
63
|
-
2.3.16
|