Skip to content

Commit

Permalink
[0.2.0] - added support for gpt-4 models
Browse files Browse the repository at this point in the history
  • Loading branch information
Sulman Baig committed Apr 7, 2023
1 parent 2662d61 commit 483fdd0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## [0.1.2] - 2022=04-07
## [0.2.0] - 2022-04-07

- added chatgpt 4 models "gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314" by [@sulmanweb](https://github.com/sulmanweb)
- added `gpt-4` as default model by [@sulmanweb](https://github.com/sulmanweb)
- added `timeout_request` option in initializer by [@mennovergeer](https://github.com/mennovergeer)

## [0.1.2] - 2022-04-07

- increased `timeout` option to faraday connection by [@mennovergeer](https://github.com/mennovergeer)

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
openai_chatgpt (0.1.2)
openai_chatgpt (0.2.0)
faraday (~> 2.5)

GEM
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

OpenAI ChatGPT API is a light-weight Ruby wrapper for the Rubyists. It gives nice struct objects for completions of the chatgpt, even the raw responses are returned in nice open struct objects. It uses Faraday for HTTP requests.

> It supports all models of gpt-4 and gpt-3.5
## Installation

Install the gem and add to the application's Gemfile by executing:
Expand Down Expand Up @@ -51,8 +53,8 @@ resp = OpenaiChatgpt::Client.new(api_key: "fake").completions(
Params:
- messages: Array[String] - Required - Messages to generate response for
`[{role: "user", text: "Hello"}, {role: "bot", text: "Hi"}]`
- model: String - Optional - Default: "gpt-3.5-turbo" - Model to use for generating response
["gpt-3.5-turbo", "gpt-3.5-turbo-0301"]
- model: String - Optional - Default: "gpt-4" - Model to use for generating response
["gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301"]
- temperature: Float - Optional - Default: 1.0 - Temperature for response generation between 0.0 and 2.0
- top_p: Float - Optional - Default: 1.0 - Top p for response generation between 0.0 and 1.0
- n: Integer - Optional - Default: 1 - Number of responses to generate
Expand Down
12 changes: 7 additions & 5 deletions lib/openai_chatgpt/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class Client
# api_key: String - Required - API key for OpenAI ChatGPT API (https://platform.openai.com/account/api-keys)
# adapter: Symbol - Optional - Default: :net_http - Adapter for Faraday connection
# stubs: Faraday::Adapter::Test::Stubs - Optional - Default: nil - Stubs for Faraday connection
# request_timeout: Integer - Optional - Default: 1200 - Timeout for Faraday connection
# #### Example:
# client = OpenaiChatgpt::Client.new api_key: "test"
# #### Description:
# Client for OpenAI ChatGPT API
def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil, request_timeout: 1200)
@api_key = api_key
@adapter = adapter
@request_timeout = request_timeout

# Test stubs for requests
@stubs = stubs
Expand All @@ -26,8 +28,8 @@ def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
# #### Params:
# messages: Array[String] - Required - Messages to generate response for
# [{role: "user", text: "Hello"}, {role: "bot", text: "Hi"}]
# model: String - Optional - Default: "gpt-3.5-turbo" - Model to use for generating response
# ["gpt-3.5-turbo", "gpt-3.5-turbo-0301"]
# model: String - Optional - Default: "gpt-4" - Model to use for generating response
# ["gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301"]
# temperature: Float - Optional - Default: 1.0 - Temperature for response generation between 0.0 and 2.0
# top_p: Float - Optional - Default: 1.0 - Top p for response generation between 0.0 and 1.0
# n: Integer - Optional - Default: 1 - Number of responses to generate
Expand All @@ -51,7 +53,7 @@ def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
# OpenaiChatgpt::Error
def completions( # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
messages:,
model: "gpt-3.5-turbo",
model: "gpt-4",
temperature: 1.0,
top_p: 1.0,
n: 1, # rubocop:disable Naming/MethodParameterName
Expand Down Expand Up @@ -100,7 +102,7 @@ def connection
@connection ||= Faraday.new(BASE_URL) do |conn|
conn.headers["Authorization"] = "Bearer #{@api_key}"
conn.headers["Content-Type"] = "application/json"
conn.options.timeout = 1200 # Increase the timeout limit to 1200 seconds
conn.options.timeout = @request_timeout
conn.response :json, content_type: "application/json"
conn.adapter adapter, @stubs
end
Expand Down
2 changes: 1 addition & 1 deletion lib/openai_chatgpt/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OpenaiChatgpt
VERSION = "0.1.2"
VERSION = "0.2.0"
end
9 changes: 6 additions & 3 deletions openai_chatgpt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ Gem::Specification.new do |spec|
spec.authors = ["Sulman Baig"]
spec.email = ["[email protected]"]

spec.summary = "OpenAI ChatGPT API is a light-weight Ruby wrapper for the Rubyists. gpt-3.5-turbo, gpt-3.5-turbo-0301"
spec.description = "OpenAI ChatGPT API is a light-weight Ruby wrapper for the Rubyists. gpt-3.5-turbo,\
gpt-3.5-turbo-0301. You can use this gem to generate text using OpenAI's ChatGPT chat responses API."
spec.summary = "OpenAI ChatGPT API is a light-weight Ruby wrapper for the Rubyists.\
All models of gpt-4 and gpt-3.5 supported."
spec.description = "OpenAI ChatGPT API is a light-weight Ruby wrapper for the Rubyists.\
[`gpt-4`, `gpt-4-0314`, `gpt-4-32k`, `gpt-4-32k-0314`, `gpt-3.5-turbo`,\
`gpt-3.5-turbo-0301`]. You can use this gem to generate text using OpenAI's ChatGPT\
chat responses API."
spec.homepage = "https://github.com/sulmanweb/openai_chatgpt"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.6"
Expand Down

0 comments on commit 483fdd0

Please sign in to comment.