chatgpt-ruby 0.3.0 → 0.4.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 +1 -2
- data/Gemfile.lock +19 -8
- data/lib/chatgpt/client.rb +14 -36
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e959cc78a29b94543ca4a79c21905e11296cd5933b39397a31bdd3652b5bede
|
4
|
+
data.tar.gz: df28d307836ff2e4827f6fa37cd68839cef2089b8418ced1d85f87b6677b98ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b06065d572303b32d01ce713968d9f92e582309e356061359a2e216f8afef229e7b5c00376ce805ab84d9612d038ec3f60245ed277c8b5ba24395e1ce4b6a020
|
7
|
+
data.tar.gz: 0a251cea4f557f855d3f515e786c875f62c2d2ea76d1c02bfbbcb85b2ed84adcc14cbf4dcd31983b3b8b1d285b3deb32cb9b9ca59dfd5165dfcdfaa3f8d863c9
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
chatgpt-ruby (0.
|
4
|
+
chatgpt-ruby (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
domain_name (0.5.20190701)
|
11
|
+
unf (>= 0.0.5, < 1.0.0)
|
12
|
+
http-accept (1.7.0)
|
13
|
+
http-cookie (1.0.5)
|
14
|
+
domain_name (~> 0.5)
|
13
15
|
json (2.6.3)
|
14
|
-
|
16
|
+
mime-types (3.4.1)
|
17
|
+
mime-types-data (~> 3.2015)
|
18
|
+
mime-types-data (3.2023.0218.1)
|
15
19
|
minitest (5.18.0)
|
16
|
-
|
20
|
+
netrc (0.11.0)
|
17
21
|
parallel (1.22.1)
|
18
22
|
parser (3.2.1.1)
|
19
23
|
ast (~> 2.4.1)
|
20
24
|
rainbow (3.1.1)
|
21
25
|
rake (13.0.6)
|
22
26
|
regexp_parser (2.7.0)
|
27
|
+
rest-client (2.1.0)
|
28
|
+
http-accept (>= 1.7.0, < 2.0)
|
29
|
+
http-cookie (>= 1.0.2, < 2.0)
|
30
|
+
mime-types (>= 1.16, < 4.0)
|
31
|
+
netrc (~> 0.8)
|
23
32
|
rexml (3.2.5)
|
24
33
|
rubocop (1.48.1)
|
25
34
|
json (~> 2.3)
|
@@ -34,6 +43,9 @@ GEM
|
|
34
43
|
rubocop-ast (1.27.0)
|
35
44
|
parser (>= 3.2.1.0)
|
36
45
|
ruby-progressbar (1.13.0)
|
46
|
+
unf (0.1.4)
|
47
|
+
unf_ext
|
48
|
+
unf_ext (0.0.8.2)
|
37
49
|
unicode-display_width (2.4.2)
|
38
50
|
|
39
51
|
PLATFORMS
|
@@ -41,10 +53,9 @@ PLATFORMS
|
|
41
53
|
|
42
54
|
DEPENDENCIES
|
43
55
|
chatgpt-ruby!
|
44
|
-
httparty
|
45
|
-
json
|
46
56
|
minitest (~> 5.0)
|
47
57
|
rake (~> 13.0)
|
58
|
+
rest-client
|
48
59
|
rubocop (~> 1.21)
|
49
60
|
|
50
61
|
BUNDLED WITH
|
data/lib/chatgpt/client.rb
CHANGED
@@ -1,45 +1,23 @@
|
|
1
|
-
#
|
2
|
-
require 'httparty'
|
3
|
-
require 'json'
|
1
|
+
# lib/chatgpt_api.rb
|
4
2
|
|
5
|
-
|
6
|
-
class Client
|
7
|
-
include HTTParty
|
8
|
-
base_uri 'https://api.openai.com/v1'
|
3
|
+
require 'rest-client'
|
9
4
|
|
5
|
+
module ChatgptRuby
|
6
|
+
class Client
|
10
7
|
def initialize(api_key)
|
11
8
|
@api_key = api_key
|
12
|
-
@
|
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)
|
9
|
+
@endpoint = 'https://api.chatgpt.com'
|
33
10
|
end
|
34
11
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
12
|
+
# Methods for accessing the API here
|
13
|
+
def generate_response(prompt)
|
14
|
+
url = "#{@endpoint}/generate"
|
15
|
+
params = {
|
16
|
+
prompt: prompt,
|
17
|
+
api_key: @api_key
|
18
|
+
}
|
19
|
+
response = RestClient.get(url, params: params)
|
20
|
+
JSON.parse(response.body)
|
43
21
|
end
|
44
22
|
end
|
45
23
|
end
|