chatgpt-ruby 2.0.0 → 2.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adc49f5bb5b5d4862838cbb111ecd00bccf7a4adc3b7edb23b8f4e5157da2a8b
4
- data.tar.gz: f4ec243a9aeeb0ee03c82b58241d9df097a2985ca7ba15a77707645b3922ff13
3
+ metadata.gz: 538f8eab513f3dba9966108690eb3e744d6381cf401b656c7c5780e3e141b2d4
4
+ data.tar.gz: 2ba9e1b0a888d03419f40efcef0c4e85aa88d6b8b1a9d7986e6b86475e1defe6
5
5
  SHA512:
6
- metadata.gz: 8b7edafba1fdf4d46adada02994ea92ced8c510b11bfe03fadcf4445e39813b169a594f4baae6ae5cddb44d2146d8111827a328f5e424174826ab4eecbb2d0c0
7
- data.tar.gz: d5c1d54f84fe5c478bbffc2d85571e9f139072a460272152088dc85e84bbbfa8b24a5b53df3030602ba22de0cbcdad019fef0f7a5ef99f718c8d1e89d18bfbf5
6
+ metadata.gz: 02ebe81d6af9b9fd3a1b2cfa03508e93917d764d5e873224575ee7d3fc986768c853027c9b1af8a7a6a2280b51a9531792a846b570b7e4eb3a1e114f29b3f32c
7
+ data.tar.gz: 074ba1aade1f0c6f20afa93e371b411c919afb7fceb38ce5ea898fd4efa5edb5206a0ca09867e803a72aa244c437c92c8562a1359258a5413723c75a159eee34
data/README.md CHANGED
@@ -1,131 +1,203 @@
1
1
  # ChatGPT Ruby
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/chatgpt-ruby.svg)](https://badge.fury.io/rb/chatgpt-ruby) [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Maintainability](https://api.codeclimate.com/v1/badges/08c7e7b58e9fbe7156eb/maintainability)](https://codeclimate.com/github/nagstler/chatgpt-ruby/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/08c7e7b58e9fbe7156eb/test_coverage)](https://codeclimate.com/github/nagstler/chatgpt-ruby/test_coverage) [![CI](https://github.com/nagstler/chatgpt-ruby/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/nagstler/chatgpt-ruby/actions/workflows/ci.yml) [![GitHub contributors](https://img.shields.io/github/contributors/nagstler/chatgpt-ruby)](https://github.com/nagstler/chatgpt-ruby/graphs/contributors)
4
-
5
- The `chatgpt-ruby` is a Ruby SDK for the OpenAI API, providing methods for generating text and completing prompts using the ChatGPT model.
3
+ <a href="https://badge.fury.io/rb/chatgpt-ruby"><img src="https://img.shields.io/gem/v/chatgpt-ruby?style=for-the-badge" alt="Gem Version"></a>
4
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow?style=for-the-badge" alt="License"></a>
5
+ <a href="https://codeclimate.com/github/nagstler/chatgpt-ruby/test_coverage"><img src="https://img.shields.io/codeclimate/coverage/nagstler/chatgpt-ruby?style=for-the-badge" alt="Test Coverage"></a>
6
+ <a href="https://github.com/nagstler/chatgpt-ruby/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/nagstler/chatgpt-ruby/ci.yml?branch=main&style=for-the-badge" alt="CI"></a>
7
+ <a href="https://github.com/nagstler/chatgpt-ruby/stargazers"><img src="https://img.shields.io/github/stars/nagstler/chatgpt-ruby?style=for-the-badge" alt="GitHub stars"></a>
8
+
9
+ 🤖💎 A lightweight Ruby wrapper for the OpenAI API, designed for simplicity and ease of integration.
10
+
11
+ ## Features
12
+
13
+ - API integration for chat completions and text completions
14
+ - Streaming capability for handling real-time response chunks
15
+ - Custom exception classes for different API error types
16
+ - Configurable timeout, retries and default parameters
17
+ - Complete test suite with mocked API responses
18
+
19
+ ## Table of Contents
20
+
21
+ - [Features](#features)
22
+ - [Installation](#installation)
23
+ - [Quick Start](#quick-start)
24
+ - [Configuration](#configuration)
25
+ - [Rails Integration](#rails-integration)
26
+ - [Error Handling](#error-handling)
27
+ - [Current Capabilities](#current-capabilities)
28
+ - [Chat Completions](#chat-completions)
29
+ - [Text Completions](#text-completions)
30
+ - [Roadmap](#roadmap)
31
+ - [Development](#development)
32
+ - [Contributing](#contributing)
33
+ - [License](#license)
6
34
 
7
35
  ## Installation
8
36
 
9
- Add this line to your application's Gemfile:
37
+ Add to your Gemfile:
10
38
 
11
39
  ```ruby
12
40
  gem 'chatgpt-ruby'
13
41
  ```
14
42
 
15
- And then execute:
43
+ Or install directly:
16
44
 
17
- ```ruby
18
- $ bundle install
45
+ ```bash
46
+ $ gem install chatgpt-ruby
19
47
  ```
20
48
 
21
- Or install it yourself as:
49
+ ## Quick Start
22
50
 
23
51
  ```ruby
24
- $ gem install chatgpt-ruby
25
- ```
52
+ require 'chatgpt'
26
53
 
27
- ## Usage
54
+ # Initialize with API key
55
+ client = ChatGPT::Client.new(ENV['OPENAI_API_KEY'])
28
56
 
29
- To use the ChatGPT API SDK, you will need an API key from OpenAI. You can obtain an API key by signing up for the [OpenAI API beta program](https://beta.openai.com/signup/) .
57
+ # Chat API (Recommended for GPT-3.5-turbo, GPT-4)
58
+ response = client.chat([
59
+ { role: "user", content: "What is Ruby?" }
60
+ ])
30
61
 
31
- Once you have an API key, you can create a new `ChatGPT::Client` instance with your API key:
62
+ puts response.dig("choices", 0, "message", "content")
32
63
 
33
- ```ruby
34
- require 'chatgpt/client'
64
+ # Completions API (For GPT-3.5-turbo-instruct)
65
+ response = client.completions("What is Ruby?")
66
+ puts response.dig("choices", 0, "text")
35
67
 
36
- api_key = 'your-api-key'
37
- client = ChatGPT::Client.new(api_key)
38
68
  ```
39
69
 
40
- ## Completions
70
+ ## Rails Integration
41
71
 
42
- To generate completions given a prompt, you can use the `completions` method:
72
+ In a Rails application, create an initializer:
43
73
 
44
74
  ```ruby
45
- prompt = 'Hello, my name is'
46
- completions = client.completions(prompt)
47
-
48
- # Output: an array of completion strings
75
+ # config/initializers/chat_gpt.rb
76
+ require 'chatgpt'
77
+
78
+ ChatGPT.configure do |config|
79
+ config.api_key = Rails.application.credentials.openai[:api_key]
80
+ config.default_engine = 'gpt-3.5-turbo'
81
+ config.request_timeout = 30
82
+ end
49
83
  ```
50
-
51
- You can customize the generation process by passing in additional parameters as a hash:
84
+ Then use it in your controllers or services:
52
85
 
53
86
  ```ruby
54
- params = {
55
- engine: 'text-davinci-002',
56
- max_tokens: 50,
57
- temperature: 0.7
58
- }
59
- completions = client.completions(prompt, params)
60
-
61
- puts completions["choices"].map { |c| c["text"] }
62
- # Output: an array of completion strings
87
+ # app/services/chat_gpt_service.rb
88
+ class ChatGPTService
89
+ def initialize
90
+ @client = ChatGPT::Client.new
91
+ end
92
+
93
+ def ask_question(question)
94
+ response = @client.chat([
95
+ { role: "user", content: question }
96
+ ])
97
+
98
+ response.dig("choices", 0, "message", "content")
99
+ end
100
+ end
101
+
102
+ # Usage in controller
103
+ def show
104
+ service = ChatGPTService.new
105
+ @response = service.ask_question("Tell me about Ruby on Rails")
106
+ end
63
107
  ```
64
108
 
65
- ## Chat
66
-
67
- The `chat` method allows for a dynamic conversation with the GPT model. It requires an array of messages where each message is a hash with two properties: `role` and `content`.
68
-
69
- `role` can be:
70
- - `'system'`: Used for instructions that guide the conversation.
71
- - `'user'`: Represents the user's input.
72
- - `'assistant'`: Represents the model's output.
73
-
74
- `content` contains the text message from the corresponding role.
75
-
76
- Here is how you would start a chat:
109
+ ## Configuration
77
110
 
78
111
  ```ruby
79
-
80
- # Define the conversation messages
81
- messages = [
82
- {
83
- role: "system",
84
- content: "You are a helpful assistant."
85
- },
86
- {
87
- role: "user",
88
- content: "Who won the world series in 2020?"
112
+ ChatGPT.configure do |config|
113
+ config.api_key = ENV['OPENAI_API_KEY']
114
+ config.api_version = 'v1'
115
+ config.default_engine = 'gpt-3.5-turbo'
116
+ config.request_timeout = 30
117
+ config.max_retries = 3
118
+ config.default_parameters = {
119
+ max_tokens: 16,
120
+ temperature: 0.5,
121
+ top_p: 1.0,
122
+ n: 1
89
123
  }
90
- ]
91
-
92
- # Start a chat
93
- response = client.chat(messages)
124
+ end
94
125
  ```
95
126
 
96
- The response will be a hash containing the model's message(s). You can extract the assistant's message like this:
127
+ ## Error handling
97
128
 
98
129
  ```ruby
99
-
100
- puts response['choices'][0]['message']['content'] # Outputs the assistant's message
130
+ begin
131
+ response = client.chat([
132
+ { role: "user", content: "Hello!" }
133
+ ])
134
+ rescue ChatGPT::AuthenticationError => e
135
+ puts "Authentication error: #{e.message}"
136
+ rescue ChatGPT::RateLimitError => e
137
+ puts "Rate limit hit: #{e.message}"
138
+ rescue ChatGPT::InvalidRequestError => e
139
+ puts "Bad request: #{e.message}"
140
+ rescue ChatGPT::APIError => e
141
+ puts "API error: #{e.message}"
142
+ end
101
143
  ```
102
144
 
103
- The conversation can be continued by extending the `messages` array and calling the `chat` method again:
145
+ ## Current Capabilities
104
146
 
147
+ ### Chat Completions
105
148
  ```ruby
149
+ # Basic chat
150
+ response = client.chat([
151
+ { role: "user", content: "What is Ruby?" }
152
+ ])
153
+
154
+ # With streaming
155
+ client.chat_stream([{ role: "user", content: "Tell me a story" }]) do |chunk|
156
+ print chunk.dig("choices", 0, "delta", "content")
157
+ end
158
+ ```
106
159
 
107
- messages << {role: "user", content: "Tell me more about it."}
108
-
109
- response = client.chat(messages)
110
- puts response['choices'][0]['message']['content'] # Outputs the assistant's new message
160
+ ### Text Completions
161
+ ```ruby
162
+ # Basic completion with GPT-3.5-turbo-instruct
163
+ response = client.completions("What is Ruby?")
164
+ puts response.dig("choices", 0, "text")
111
165
  ```
112
166
 
113
- With this method, you can build an ongoing conversation with the model.
167
+ ## Roadmap
168
+
169
+ While ChatGPT Ruby is functional, there are several areas planned for improvement:
170
+
171
+ - [ ] Response object wrapper & Rails integration with Railtie (v2.2)
172
+ - [ ] Token counting, function calling, and rate limiting (v2.3)
173
+ - [ ] Batch operations and async support (v3.0)
174
+ - [ ] DALL-E image generation and fine-tuning (Future)
175
+
176
+ ❤️ Contributions in any of these areas are welcome!
114
177
 
115
178
  ## Development
116
179
 
117
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
180
+ ```bash
181
+ # Run tests
182
+ bundle exec rake test
183
+
184
+ # Run linter
185
+ bundle exec rubocop
118
186
 
119
- To install this gem onto your local machine, run `bundle exec rake install`.
187
+ # Generate documentation
188
+ bundle exec yard doc
189
+ ```
120
190
 
121
191
  ## Contributing
122
192
 
123
- Bug reports and pull requests are welcome on GitHub at https://github.com/nagstler/chatgpt-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nagstler/chatgpt-ruby/blob/main/CODE_OF_CONDUCT.md).
193
+ 1. Fork it
194
+ 2. Create your feature branch (`git checkout -b feature/my-new-feature`)
195
+ 3. Add tests for your feature
196
+ 4. Make your changes
197
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
198
+ 6. Push to the branch (`git push origin feature/my-new-feature`)
199
+ 7. Create a new Pull Request
124
200
 
125
201
  ## License
126
202
 
127
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
128
-
129
- ## Code of Conduct
130
-
131
- Everyone interacting in the Chatgpt::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nagstler/chatgpt-ruby/blob/main/CODE_OF_CONDUCT.md).
203
+ Released under the MIT License. See [LICENSE](LICENSE.txt) for details.
@@ -1,111 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/chatgpt/client.rb
1
4
  require 'rest-client'
2
5
  require 'json'
3
6
 
4
7
  module ChatGPT
5
8
  class Client
6
- # Initialize the client with the API key
7
- #
8
- # @param api_key [String] The API key for the GPT-3 service
9
- def initialize(api_key)
10
- @api_key = api_key
11
- # Base endpoint for the OpenAI API
9
+ def initialize(api_key = nil)
10
+ @api_key = api_key || ChatGPT.configuration.api_key
12
11
  @endpoint = 'https://api.openai.com/v1'
12
+ @config = ChatGPT.configuration
13
13
  end
14
14
 
15
- # Prepare headers for the API request
16
- #
17
- # @return [Hash] The headers for the API request
18
- def headers
19
- {
20
- 'Content-Type' => 'application/json',
21
- 'Authorization' => "Bearer #{@api_key}"
22
- }
23
- end
24
-
25
- # Generate completions based on a given prompt
26
- #
27
- # @param prompt [String] The prompt to be completed
28
- # @param params [Hash] Additional parameters for the completion request
29
- #
30
- # @return [Hash] The completion results from the API
31
15
  def completions(prompt, params = {})
32
- # Set default parameters
33
- engine = params[:engine] || 'text-davinci-002'
34
- max_tokens = params[:max_tokens] || 16
35
- temperature = params[:temperature] || 0.5
36
- top_p = params[:top_p] || 1.0
37
- n = params[:n] || 1
38
-
39
- # Construct the URL for the completion request
16
+ engine = params[:engine] || @config.default_engine
40
17
  url = "#{@endpoint}/engines/#{engine}/completions"
41
-
42
- # Prepare the data for the request
43
- data = {
18
+
19
+ data = @config.default_parameters.merge(
44
20
  prompt: prompt,
45
- max_tokens: max_tokens,
46
- temperature: temperature,
47
- top_p: top_p,
48
- n: n
49
- }
50
-
51
- # Make the request to the API
21
+ max_tokens: params[:max_tokens],
22
+ temperature: params[:temperature],
23
+ top_p: params[:top_p],
24
+ n: params[:n]
25
+ ).compact
26
+
52
27
  request_api(url, data)
53
28
  end
54
29
 
55
-
56
- # This method sends a chat message to the API
57
- #
58
- # @param messages [Array<Hash>] The array of messages for the conversation.
59
- # Each message is a hash with a `role` and `content` key. The `role` key can be 'system', 'user', or 'assistant',
60
- # and the `content` key contains the text of the message.
61
- #
62
- # @param params [Hash] Optional parameters for the chat request. This can include the 'model' key to specify
63
- # the model to be used for the chat. If no 'model' key is provided, 'gpt-3.5-turbo' is used by default.
64
- #
65
- # @return [Hash] The response from the API.
66
30
  def chat(messages, params = {})
67
- # Set default parameters
68
- model = params[:model] || 'gpt-3.5-turbo'
69
-
70
- # Construct the URL for the chat request
71
31
  url = "#{@endpoint}/chat/completions"
72
32
 
73
- # Prepare the data for the request. The data is a hash with 'model' and 'messages' keys.
74
- data = {
75
- model: model,
76
- messages: messages
77
- }
78
-
79
- # Make the API request and return the response.
33
+ data = @config.default_parameters.merge(
34
+ model: params[:model] || @config.default_engine, # Use configured default_engine
35
+ messages: messages,
36
+ temperature: params[:temperature],
37
+ top_p: params[:top_p],
38
+ n: params[:n],
39
+ stream: params[:stream] || false
40
+ ).compact
41
+
80
42
  request_api(url, data)
81
43
  end
82
44
 
45
+ def chat_stream(messages, params = {}, &block)
46
+ raise ArgumentError, 'Block is required for streaming' unless block_given?
47
+
48
+ url = "#{@endpoint}/chat/completions"
49
+ data = @config.default_parameters.merge(
50
+ model: params[:model] || @config.default_engine, # Use configured default_engine
51
+ messages: messages,
52
+ stream: true
53
+ ).compact
54
+
55
+ request_streaming(url, data, &block)
56
+ end
83
57
 
84
58
  private
85
- # Make a request to the API
86
- #
87
- # @param url [String] The URL for the request
88
- # @param data [Hash] The data to be sent in the request
89
- # @param method [Symbol] The HTTP method for the request (:post by default)
90
- #
91
- # @return [Hash] The response from the API
92
- #
93
- # @raise [RestClient::ExceptionWithResponse] If the API request fails
94
- def request_api(url, data, method = :post)
95
- begin
96
- # Execute the request
97
- response = RestClient::Request.execute(method: method, url: url, payload: data.to_json, headers: headers)
98
-
99
- # Parse and return the response body
100
- JSON.parse(response.body)
101
- rescue RestClient::ExceptionWithResponse => e
102
- # Parse the error message from the API response
103
- error_msg = JSON.parse(e.response.body)['error']['message']
104
-
105
- # Raise an exception with the API error message
106
- raise RestClient::ExceptionWithResponse.new("#{e.message}: #{error_msg} (#{e.http_code})"), nil, e.backtrace
59
+
60
+ def request_api(url, data)
61
+ response = RestClient::Request.execute(
62
+ method: :post,
63
+ url: url,
64
+ payload: data.to_json,
65
+ headers: {
66
+ 'Authorization' => "Bearer #{@api_key}",
67
+ 'Content-Type' => 'application/json'
68
+ },
69
+ timeout: @config.request_timeout
70
+ )
71
+ JSON.parse(response.body)
72
+ rescue RestClient::ExceptionWithResponse => e
73
+ handle_error(e)
74
+ end
75
+
76
+ def handle_error(error)
77
+ error_response = JSON.parse(error.response.body)
78
+ error_message = error_response['error']['message']
79
+ status_code = error.response.code
80
+
81
+ case status_code
82
+ when 401
83
+ raise ChatGPT::AuthenticationError.new(error_message, status_code)
84
+ when 429
85
+ raise ChatGPT::RateLimitError.new(error_message, status_code)
86
+ when 400
87
+ raise ChatGPT::InvalidRequestError.new(error_message, status_code)
88
+ else
89
+ raise ChatGPT::APIError.new(error_message, status_code)
90
+ end
91
+ end
92
+
93
+ def request_streaming(url, data)
94
+ RestClient::Request.execute( # Remove the response = assignment
95
+ method: :post,
96
+ url: url,
97
+ payload: data.to_json,
98
+ headers: {
99
+ 'Authorization' => "Bearer #{@api_key}",
100
+ 'Content-Type' => 'application/json'
101
+ },
102
+ timeout: @config.request_timeout,
103
+ stream_to_buffer: true
104
+ ) do |chunk, _x, _z|
105
+ if chunk.include?('data: ')
106
+ chunk.split("\n").each do |line|
107
+ next unless line.start_with?('data: ')
108
+
109
+ data = line.sub(/^data: /, '')
110
+ next if data.strip == '[DONE]'
111
+
112
+ begin
113
+ parsed = JSON.parse(data)
114
+ yield parsed if block_given?
115
+ rescue JSON::ParserError
116
+ next
117
+ end
118
+ end
119
+ end
107
120
  end
121
+ rescue RestClient::ExceptionWithResponse => e
122
+ handle_error(e)
108
123
  end
109
-
110
124
  end
111
125
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/chatgpt/configuration.rb
4
+ module ChatGPT
5
+ class Configuration
6
+ attr_accessor :api_key, :api_version, :default_engine,
7
+ :request_timeout, :max_retries, :default_parameters
8
+
9
+ def initialize
10
+ @api_version = 'v1'
11
+ @default_engine = 'text-davinci-002'
12
+ @request_timeout = 30
13
+ @max_retries = 3
14
+ @default_parameters = {
15
+ max_tokens: 16,
16
+ temperature: 0.5,
17
+ top_p: 1.0,
18
+ n: 1
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/chatgpt/errors.rb
4
+ module ChatGPT
5
+ class Error < StandardError; end
6
+
7
+ class APIError < Error
8
+ attr_reader :status_code, :error_type
9
+
10
+ def initialize(message = nil, status_code = nil, error_type = nil)
11
+ @status_code = status_code
12
+ @error_type = error_type
13
+ super(message)
14
+ end
15
+ end
16
+
17
+ class AuthenticationError < APIError; end
18
+ class RateLimitError < APIError; end
19
+ class InvalidRequestError < APIError; end
20
+ class TokenLimitError < APIError; end
21
+ end
@@ -0,0 +1,11 @@
1
+ # lib/chatgpt/railtie.rb
2
+ module ChatGPT
3
+ class Railtie < Rails::Railtie
4
+ initializer "chatgpt.configure_rails_initialization" do
5
+ # Register inflection for Rails apps
6
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ inflect.acronym 'GPT'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/chatgpt/version.rb
4
+ module ChatGPT
5
+ VERSION = "2.1.1"
6
+ end
data/lib/chatgpt.rb ADDED
@@ -0,0 +1,26 @@
1
+ # lib/chatgpt.rb
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'chatgpt/version'
5
+ require_relative 'chatgpt/errors'
6
+ require_relative 'chatgpt/configuration'
7
+ require_relative 'chatgpt/client'
8
+
9
+ # Automatically load Railtie when used with Rails
10
+ require_relative 'chatgpt/railtie' if defined?(Rails)
11
+
12
+ module ChatGPT
13
+ class << self
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def configure
19
+ yield(configuration)
20
+ end
21
+
22
+ def reset_configuration!
23
+ @configuration = Configuration.new
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,57 +1,164 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatgpt-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagendra Dhanakeerthi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-08 00:00:00.000000000 Z
11
+ date: 2025-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- description: This gem provides a Ruby SDK for interacting with the OpenAI API, including
28
- methods for generating text, completing prompts, and more.
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: brakeman
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler-audit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.21'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.21'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.21'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.21'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov_json_formatter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.18'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.18'
139
+ description: A Ruby SDK for OpenAI's ChatGPT API
29
140
  email:
30
141
  - nagendra.dhanakeerthi@gmail.com
31
142
  executables: []
32
143
  extensions: []
33
144
  extra_rdoc_files: []
34
145
  files:
35
- - ".codeclimate.yml"
36
- - ".rubocop.yml"
37
- - CHANGELOG.md
38
- - CODE_OF_CONDUCT.md
39
- - Gemfile
40
- - Gemfile.lock
41
146
  - LICENSE.txt
42
147
  - README.md
43
- - Rakefile
148
+ - lib/chatgpt.rb
44
149
  - lib/chatgpt/client.rb
45
- - lib/chatgpt/ruby.rb
46
- - lib/chatgpt/ruby/version.rb
47
- - sig/chatgpt/ruby.rbs
48
- homepage: https://github.com/nagstler/chatgpt-ruby.git
150
+ - lib/chatgpt/configuration.rb
151
+ - lib/chatgpt/errors.rb
152
+ - lib/chatgpt/railtie.rb
153
+ - lib/chatgpt/version.rb
154
+ homepage: https://github.com/nagstler/chatgpt-ruby
49
155
  licenses:
50
156
  - MIT
51
157
  metadata:
52
- homepage_uri: https://github.com/nagstler/chatgpt-ruby.git
53
- source_code_uri: https://github.com/nagstler/chatgpt-ruby.git
158
+ homepage_uri: https://github.com/nagstler/chatgpt-ruby
159
+ source_code_uri: https://github.com/nagstler/chatgpt-ruby
54
160
  changelog_uri: https://github.com/nagstler/chatgpt-ruby/blob/main/CHANGELOG.md
161
+ rubygems_mfa_required: 'true'
55
162
  post_install_message:
56
163
  rdoc_options: []
57
164
  require_paths:
@@ -60,15 +167,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
167
  requirements:
61
168
  - - ">="
62
169
  - !ruby/object:Gem::Version
63
- version: 2.6.0
170
+ version: 3.0.0
64
171
  required_rubygems_version: !ruby/object:Gem::Requirement
65
172
  requirements:
66
173
  - - ">="
67
174
  - !ruby/object:Gem::Version
68
175
  version: '0'
69
176
  requirements: []
70
- rubygems_version: 3.3.26
177
+ rubygems_version: 3.5.2
71
178
  signing_key:
72
179
  specification_version: 4
73
- summary: A Ruby SDK for the OpenAI API
180
+ summary: Ruby client for OpenAI's ChatGPT API
74
181
  test_files: []
data/.codeclimate.yml DELETED
@@ -1,8 +0,0 @@
1
- version: "2"
2
- checks:
3
- rubocop:
4
- enabled: true
5
- channel: "stable"
6
- plugins:
7
- test-reporter:
8
- enabled: true
data/.rubocop.yml DELETED
@@ -1,13 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
3
-
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
data/CHANGELOG.md DELETED
@@ -1,19 +0,0 @@
1
- ## [2.0.0] - 2023-07-08
2
-
3
- ### Added
4
-
5
- - Added support for chat interactions with the GPT-3.5-turbo model.
6
- - Introduced a new `chat` method to the `ChatGPT::Client` class, which sends an array of chat messages to the API and receives the generated messages in return.
7
- - Updated the README to provide usage instructions for the new `chat` method.
8
-
9
- ## [1.0.0] - 2023-04-30
10
-
11
- ### Added
12
-
13
- - Initial release of the `chatgpt-ruby` gem.
14
- - Implements ChatGPT Client with methods for completions, search, classification, summary, and answer generation.
15
- - Includes unit tests for each method.
16
-
17
- ## [0.1.0] - 2023-03-22
18
-
19
- - Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nagendra.dhanakeerthi@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in chatgpt-ruby.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "minitest", "~> 5.0"
11
-
12
- gem "rubocop", "~> 1.21"
13
-
14
- gem 'rest-client'
15
-
16
- group :test do
17
- gem 'simplecov', require: false
18
- gem 'simplecov_json_formatter', require: false
19
- end
20
-
21
-
data/Gemfile.lock DELETED
@@ -1,72 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- chatgpt-ruby (1.0.0)
5
- rest-client
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- ast (2.4.2)
11
- docile (1.4.0)
12
- domain_name (0.5.20190701)
13
- unf (>= 0.0.5, < 1.0.0)
14
- http-accept (1.7.0)
15
- http-cookie (1.0.5)
16
- domain_name (~> 0.5)
17
- json (2.6.3)
18
- mime-types (3.4.1)
19
- mime-types-data (~> 3.2015)
20
- mime-types-data (3.2023.0218.1)
21
- minitest (5.18.0)
22
- netrc (0.11.0)
23
- parallel (1.22.1)
24
- parser (3.2.1.1)
25
- ast (~> 2.4.1)
26
- rainbow (3.1.1)
27
- rake (13.0.6)
28
- regexp_parser (2.7.0)
29
- rest-client (2.1.0)
30
- http-accept (>= 1.7.0, < 2.0)
31
- http-cookie (>= 1.0.2, < 2.0)
32
- mime-types (>= 1.16, < 4.0)
33
- netrc (~> 0.8)
34
- rexml (3.2.5)
35
- rubocop (1.48.1)
36
- json (~> 2.3)
37
- parallel (~> 1.10)
38
- parser (>= 3.2.0.0)
39
- rainbow (>= 2.2.2, < 4.0)
40
- regexp_parser (>= 1.8, < 3.0)
41
- rexml (>= 3.2.5, < 4.0)
42
- rubocop-ast (>= 1.26.0, < 2.0)
43
- ruby-progressbar (~> 1.7)
44
- unicode-display_width (>= 2.4.0, < 3.0)
45
- rubocop-ast (1.27.0)
46
- parser (>= 3.2.1.0)
47
- ruby-progressbar (1.13.0)
48
- simplecov (0.22.0)
49
- docile (~> 1.1)
50
- simplecov-html (~> 0.11)
51
- simplecov_json_formatter (~> 0.1)
52
- simplecov-html (0.12.3)
53
- simplecov_json_formatter (0.1.4)
54
- unf (0.1.4)
55
- unf_ext
56
- unf_ext (0.0.8.2)
57
- unicode-display_width (2.4.2)
58
-
59
- PLATFORMS
60
- arm64-darwin-21
61
-
62
- DEPENDENCIES
63
- chatgpt-ruby!
64
- minitest (~> 5.0)
65
- rake (~> 13.0)
66
- rest-client
67
- rubocop (~> 1.21)
68
- simplecov
69
- simplecov_json_formatter
70
-
71
- BUNDLED WITH
72
- 2.3.26
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
-
7
- Rake::TestTask.new(:test) do |t|
8
- t.libs << "test"
9
- t.pattern = 'test/**/*_test.rb'
10
- t.libs << "lib"
11
- t.test_files = FileList["test/**/test_*.rb"]
12
- end
13
-
14
- require "rubocop/rake_task"
15
-
16
- RuboCop::RakeTask.new
17
-
18
- task default: %i[test rubocop]
19
-
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Chatgpt
4
- module Ruby
5
- VERSION = "2.0.0"
6
- end
7
- end
data/lib/chatgpt/ruby.rb DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "ruby/version"
4
-
5
- module Chatgpt
6
- module Ruby
7
- class Error < StandardError; end
8
- # Your code goes here...
9
- end
10
- end
data/sig/chatgpt/ruby.rbs DELETED
@@ -1,6 +0,0 @@
1
- module Chatgpt
2
- module Ruby
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
- end
6
- end