chatgpt-ruby 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +19 -1
  4. data/lib/chatgpt/client.rb +14 -36
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94d035b49642b3f0c7ca90ef2443711f8b50007bde2ab538cb27a79db6d2198e
4
- data.tar.gz: 6013d9bf6c37d54da4c1b9c4686b2576605d394db5881c5d6db4b64ff3223bfa
3
+ metadata.gz: 6e959cc78a29b94543ca4a79c21905e11296cd5933b39397a31bdd3652b5bede
4
+ data.tar.gz: df28d307836ff2e4827f6fa37cd68839cef2089b8418ced1d85f87b6677b98ea
5
5
  SHA512:
6
- metadata.gz: fc802fd52f248b26f40352188b5f8876ffedba0dde39fa8a09655cf9716e50dc3f43c4ee1021187ad146aee5612f59411afa66cfd14eb254c69470b4f25b21b7
7
- data.tar.gz: 596422eebcc85c58b2c8800c0ddfdb5d00d1397f67c530f3c732523483dfbf90c88e0eeb420becf325a073f8801dc3dd7a390ce7b726b65dabeb009a3f09ab2c
6
+ metadata.gz: b06065d572303b32d01ce713968d9f92e582309e356061359a2e216f8afef229e7b5c00376ce805ab84d9612d038ec3f60245ed277c8b5ba24395e1ce4b6a020
7
+ data.tar.gz: 0a251cea4f557f855d3f515e786c875f62c2d2ea76d1c02bfbbcb85b2ed84adcc14cbf4dcd31983b3b8b1d285b3deb32cb9b9ca59dfd5165dfcdfaa3f8d863c9
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
10
10
  gem "minitest", "~> 5.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ gem 'rest-client'
data/Gemfile.lock CHANGED
@@ -1,20 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chatgpt-ruby (0.1.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
+ 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)
10
15
  json (2.6.3)
16
+ mime-types (3.4.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2023.0218.1)
11
19
  minitest (5.18.0)
20
+ netrc (0.11.0)
12
21
  parallel (1.22.1)
13
22
  parser (3.2.1.1)
14
23
  ast (~> 2.4.1)
15
24
  rainbow (3.1.1)
16
25
  rake (13.0.6)
17
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)
18
32
  rexml (3.2.5)
19
33
  rubocop (1.48.1)
20
34
  json (~> 2.3)
@@ -29,6 +43,9 @@ GEM
29
43
  rubocop-ast (1.27.0)
30
44
  parser (>= 3.2.1.0)
31
45
  ruby-progressbar (1.13.0)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.8.2)
32
49
  unicode-display_width (2.4.2)
33
50
 
34
51
  PLATFORMS
@@ -38,6 +55,7 @@ DEPENDENCIES
38
55
  chatgpt-ruby!
39
56
  minitest (~> 5.0)
40
57
  rake (~> 13.0)
58
+ rest-client
41
59
  rubocop (~> 1.21)
42
60
 
43
61
  BUNDLED WITH
@@ -1,45 +1,23 @@
1
- # chatgpt_client.rb
2
- require 'httparty'
3
- require 'json'
1
+ # lib/chatgpt_api.rb
4
2
 
5
- module ChatGPTRuby
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
- @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)
9
+ @endpoint = 'https://api.chatgpt.com'
33
10
  end
34
11
 
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
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
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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagendra Dhanakeerthi