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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -2
  3. data/Gemfile.lock +0 -7
  4. data/README.md +33 -9
  5. data/lib/chatgpt/client.rb +45 -0
  6. metadata +7 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca17c95688832308817de8b5b620a4ac0d0a2f3a0899ad611dc897fef95b8b3c
4
- data.tar.gz: d6e9c97daa3e6ed5c393b9aafdee36b40493e04d1ec1da2f3371e791a6d0d19d
3
+ metadata.gz: 94d035b49642b3f0c7ca90ef2443711f8b50007bde2ab538cb27a79db6d2198e
4
+ data.tar.gz: 6013d9bf6c37d54da4c1b9c4686b2576605d394db5881c5d6db4b64ff3223bfa
5
5
  SHA512:
6
- metadata.gz: b36305d061100c22443212a342414237f6a12ce2ebba2a7b13534b0e00941ce76eb59ea37438cab29b08fac00ebecc6238dfbd2b723d7064dcb32e3b9b400c6f
7
- data.tar.gz: 0f53b700e3b9daeabb43a27690c488db5ad11638a1854dc31d14381c4765a7abc91ff3de688527a2cec4bb6732068a34ff24f81a08b024e6ec02e5b1dc6aabf7
6
+ metadata.gz: fc802fd52f248b26f40352188b5f8876ffedba0dde39fa8a09655cf9716e50dc3f43c4ee1021187ad146aee5612f59411afa66cfd14eb254c69470b4f25b21b7
7
+ data.tar.gz: 596422eebcc85c58b2c8800c0ddfdb5d00d1397f67c530f3c732523483dfbf90c88e0eeb420becf325a073f8801dc3dd7a390ce7b726b65dabeb009a3f09ab2c
data/Gemfile CHANGED
@@ -10,5 +10,3 @@ gem "rake", "~> 13.0"
10
10
  gem "minitest", "~> 5.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
-
14
- gem "httparty", "~> 0.21.0"
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
- # Chatgpt::Ruby
1
+ # ChatGPTRuby
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/chatgpt/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
5
+ ### Bundler
6
6
 
7
- ## Installation
7
+ Add this line to your application's Gemfile:
8
8
 
9
- Install the gem and add to the application's Gemfile by executing:
9
+ ```ruby
10
+ gem "chatgpt-ruby"
11
+ ```
10
12
 
11
- $ bundle add chatgpt-ruby
13
+ And then execute:
12
14
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
15
+ $ bundle install
14
16
 
15
- $ gem install chatgpt-ruby
17
+ ### Gem install
18
+
19
+ Or install with:
20
+
21
+ $ gem install chatgpt-ruby
16
22
 
17
23
  ## Usage
18
24
 
19
- TODO: Write usage instructions here
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.1.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
- - !ruby/object:Gem::Dependency
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: https://github.com/nagstler/chatgpt-ruby.git
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. [WIP]
54
+ summary: Write a short summary, because RubyGems requires one.
71
55
  test_files: []