chatgpt-ruby 0.1.0 → 0.2.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/Gemfile +0 -2
- data/Gemfile.lock +0 -7
- data/README.md +33 -9
- data/lib/chatgpt/client.rb +45 -0
- metadata +7 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94d035b49642b3f0c7ca90ef2443711f8b50007bde2ab538cb27a79db6d2198e
|
4
|
+
data.tar.gz: 6013d9bf6c37d54da4c1b9c4686b2576605d394db5881c5d6db4b64ff3223bfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc802fd52f248b26f40352188b5f8876ffedba0dde39fa8a09655cf9716e50dc3f43c4ee1021187ad146aee5612f59411afa66cfd14eb254c69470b4f25b21b7
|
7
|
+
data.tar.gz: 596422eebcc85c58b2c8800c0ddfdb5d00d1397f67c530f3c732523483dfbf90c88e0eeb420becf325a073f8801dc3dd7a390ce7b726b65dabeb009a3f09ab2c
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,19 +2,13 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
chatgpt-ruby (0.1.0)
|
5
|
-
httparty (~> 0.18)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
9
|
ast (2.4.2)
|
11
|
-
httparty (0.21.0)
|
12
|
-
mini_mime (>= 1.0.0)
|
13
|
-
multi_xml (>= 0.5.2)
|
14
10
|
json (2.6.3)
|
15
|
-
mini_mime (1.1.2)
|
16
11
|
minitest (5.18.0)
|
17
|
-
multi_xml (0.6.0)
|
18
12
|
parallel (1.22.1)
|
19
13
|
parser (3.2.1.1)
|
20
14
|
ast (~> 2.4.1)
|
@@ -42,7 +36,6 @@ PLATFORMS
|
|
42
36
|
|
43
37
|
DEPENDENCIES
|
44
38
|
chatgpt-ruby!
|
45
|
-
httparty (~> 0.21.0)
|
46
39
|
minitest (~> 5.0)
|
47
40
|
rake (~> 13.0)
|
48
41
|
rubocop (~> 1.21)
|
data/README.md
CHANGED
@@ -1,22 +1,46 @@
|
|
1
|
-
#
|
1
|
+
# ChatGPTRuby
|
2
2
|
|
3
|
-
|
3
|
+
The `chatgpt-ruby` gem is a simple Ruby SDK for accessing the OpenAI ChatGPT API. This client makes it easy to integrate the ChatGPT API into your Ruby applications.
|
4
4
|
|
5
|
-
|
5
|
+
### Bundler
|
6
6
|
|
7
|
-
|
7
|
+
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem "chatgpt-ruby"
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
And then execute:
|
12
14
|
|
13
|
-
|
15
|
+
$ bundle install
|
14
16
|
|
15
|
-
|
17
|
+
### Gem install
|
18
|
+
|
19
|
+
Or install with:
|
20
|
+
|
21
|
+
$ gem install chatgpt-ruby
|
16
22
|
|
17
23
|
## Usage
|
18
24
|
|
19
|
-
|
25
|
+
To use the gem in a Ruby script or application, simply require it and initialize the client:
|
26
|
+
```ruby
|
27
|
+
require 'chatgpt_client'
|
28
|
+
|
29
|
+
client = ChatGPTClient::Client.new('your_api_key')
|
30
|
+
response = client.chat('Please translate the following English text to French: "Hello, how are you?"')
|
31
|
+
puts response
|
32
|
+
```
|
33
|
+
|
34
|
+
Replace 'your_api_key' with your actual ChatGPT API key.
|
35
|
+
|
36
|
+
### Parameters
|
37
|
+
|
38
|
+
The `chat` method accepts a mandatory `prompt` parameter and an optional `options` parameter.
|
39
|
+
|
40
|
+
The `prompt` parameter is a string representing the input you want to send to the ChatGPT API.
|
41
|
+
|
42
|
+
The `options` parameter is a hash that can include the following keys:
|
43
|
+
- `max_tokens`: The maximum number of tokens
|
20
44
|
|
21
45
|
## Development
|
22
46
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# chatgpt_client.rb
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module ChatGPTRuby
|
6
|
+
class Client
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'https://api.openai.com/v1'
|
9
|
+
|
10
|
+
def initialize(api_key)
|
11
|
+
@api_key = api_key
|
12
|
+
@headers = {
|
13
|
+
'Authorization' => "Bearer #{@api_key}",
|
14
|
+
'Content-Type' => 'application/json'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Methods to interact with the API
|
19
|
+
def generate(prompt, options = {})
|
20
|
+
body = {
|
21
|
+
'prompt' => prompt,
|
22
|
+
'max_tokens' => options.fetch(:max_tokens, 100),
|
23
|
+
'n' => options.fetch(:n, 1),
|
24
|
+
'stop' => options.fetch(:stop, nil),
|
25
|
+
'temperature' => options.fetch(:temperature, 1.0),
|
26
|
+
'top_p' => options.fetch(:top_p, 1.0),
|
27
|
+
'frequency_penalty' => options.fetch(:frequency_penalty, 0.0),
|
28
|
+
'presence_penalty' => options.fetch(:presence_penalty, 0.0),
|
29
|
+
}.to_json
|
30
|
+
|
31
|
+
response = self.class.post('/davinci-codex/completions', headers: @headers, body: body)
|
32
|
+
handle_response(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def handle_response(response)
|
38
|
+
if response.code == 200
|
39
|
+
JSON.parse(response.body)
|
40
|
+
else
|
41
|
+
raise "Error: #{response.code} - #{response.message}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatgpt-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nagendra Dhanakeerthi
|
@@ -9,22 +9,8 @@ autorequire:
|
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-03-22 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: httparty
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.18'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.18'
|
27
|
-
description: Write a longer description or delete this line. [WIP]
|
12
|
+
dependencies: []
|
13
|
+
description: Write a longer description or delete this line.
|
28
14
|
email:
|
29
15
|
- nagendra.dhanakeerthi@gmail.com
|
30
16
|
executables: []
|
@@ -39,16 +25,14 @@ files:
|
|
39
25
|
- LICENSE.txt
|
40
26
|
- README.md
|
41
27
|
- Rakefile
|
28
|
+
- lib/chatgpt/client.rb
|
42
29
|
- lib/chatgpt/ruby.rb
|
43
30
|
- lib/chatgpt/ruby/version.rb
|
44
31
|
- sig/chatgpt/ruby.rbs
|
45
|
-
homepage:
|
32
|
+
homepage:
|
46
33
|
licenses:
|
47
34
|
- MIT
|
48
|
-
metadata:
|
49
|
-
homepage_uri: https://github.com/nagstler/chatgpt-ruby.git
|
50
|
-
source_code_uri: https://github.com/nagstler/chatgpt-ruby.git
|
51
|
-
changelog_uri: https://github.com/nagstler/chatgpt-ruby/blob/main/CHANGELOG.md
|
35
|
+
metadata: {}
|
52
36
|
post_install_message:
|
53
37
|
rdoc_options: []
|
54
38
|
require_paths:
|
@@ -67,5 +51,5 @@ requirements: []
|
|
67
51
|
rubygems_version: 3.3.26
|
68
52
|
signing_key:
|
69
53
|
specification_version: 4
|
70
|
-
summary: Write a short summary, because RubyGems requires one.
|
54
|
+
summary: Write a short summary, because RubyGems requires one.
|
71
55
|
test_files: []
|