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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -2
  3. data/Gemfile.lock +19 -8
  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: 5f01f292bb8825b0d36f4474f988a1cee11a9f065eb9f02643de9e4b9d4c433b
4
- data.tar.gz: c5ef2ddfeaccacfcb68be33257384facc83b33f983233acda917c9962bef0826
3
+ metadata.gz: 6e959cc78a29b94543ca4a79c21905e11296cd5933b39397a31bdd3652b5bede
4
+ data.tar.gz: df28d307836ff2e4827f6fa37cd68839cef2089b8418ced1d85f87b6677b98ea
5
5
  SHA512:
6
- metadata.gz: 27062bcbbba5cdc8804235ea72d305e4699e8b40faef562693428007f3564b227db2ec13ddc8100bafa955c9234f85d9bc1582f8a88aa9b486207b9daaf8965a
7
- data.tar.gz: 5b60cc1a80ff20fcb4f6f2b45452758847c1585a02541658c49e8a432a0fa62145a0bde1fcb81ff5a5e92ab7ddf67ca373c52fe0cb96f705c6bd24e33b6628fc
6
+ metadata.gz: b06065d572303b32d01ce713968d9f92e582309e356061359a2e216f8afef229e7b5c00376ce805ab84d9612d038ec3f60245ed277c8b5ba24395e1ce4b6a020
7
+ data.tar.gz: 0a251cea4f557f855d3f515e786c875f62c2d2ea76d1c02bfbbcb85b2ed84adcc14cbf4dcd31983b3b8b1d285b3deb32cb9b9ca59dfd5165dfcdfaa3f8d863c9
data/Gemfile CHANGED
@@ -11,5 +11,4 @@ gem "minitest", "~> 5.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
13
 
14
- gem 'httparty'
15
- gem 'json'
14
+ gem 'rest-client'
data/Gemfile.lock CHANGED
@@ -1,25 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chatgpt-ruby (0.3.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
- httparty (0.21.0)
11
- mini_mime (>= 1.0.0)
12
- multi_xml (>= 0.5.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)
13
15
  json (2.6.3)
14
- mini_mime (1.1.2)
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
- multi_xml (0.6.0)
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
@@ -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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagendra Dhanakeerthi