rubygpt 0.1.0 → 0.1.2
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 +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +12 -11
- data/lib/rubygpt/common/message.rb +3 -0
- data/lib/rubygpt/connection/faraday.rb +3 -1
- data/lib/rubygpt/requester/chat_requester.rb +1 -1
- data/lib/rubygpt/response/chat_completion.rb +1 -4
- data/lib/rubygpt/version.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 341d3c4631e9e3f821bbcda5d1d29e0b0bbabd9310f8c24a78aa5c4ebaa6f1bc
|
4
|
+
data.tar.gz: c07408238baa0cd2d103faa2c89853ff2ab79f2f1739ae98e6e031a22cf1856c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a996047c56be2ac33c2000aa8056cdb8905d7c79902d4e5c2a531db24dea3bd39308dd2ae09c2b8d33ed9259761beb0a409cf139c9681a5f477a06bd0053fb0
|
7
|
+
data.tar.gz: a0061994955323c6b4e6ddd89ac588e807adfcb5be02159e4a385daa6a213607190406893e4d932be2c88b38fd61051ccb7574196200a81f26a0c6ebc89aae99
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
-
##
|
1
|
+
## RubyGPT
|
2
|
+
|
3
|
+
## [0.1.2] - 2024-08-28
|
4
|
+
|
5
|
+
- Fixed unexpected EOF error message when running gem
|
6
|
+
- Gem dependency updates
|
7
|
+
|
8
|
+
## [0.1.1] - 2024-03-13
|
9
|
+
|
10
|
+
- Fixed cost reader in response object
|
11
|
+
- Fixed standard response generation from faraday response
|
12
|
+
- Fixed a bug in message building from hash contents
|
13
|
+
- Gemspec configuration adjustments (license)
|
2
14
|
|
3
15
|
## [0.1.0] - 2024-03-08
|
4
16
|
|
data/README.md
CHANGED
@@ -94,10 +94,10 @@ After configuring the Rubygpt client, you can perform requests to the Chat Compl
|
|
94
94
|
|
95
95
|
```ruby
|
96
96
|
# Send a message to GPT
|
97
|
-
Rubygpt.chat.create("
|
97
|
+
Rubygpt.chat.create("Where is London?.") # any message you'd like to send
|
98
98
|
|
99
99
|
# Send multiple messages
|
100
|
-
Rubygpt.chat.create(["
|
100
|
+
Rubygpt.chat.create(["Where is UK?", "What Continent?", "What timezone?"])
|
101
101
|
```
|
102
102
|
|
103
103
|
To use the received responses, refer to the [Using Chat Completion Responses](#using-chat-completion-responses) section.
|
@@ -142,14 +142,13 @@ You can send any available request body parameter supported by OpenAI Chat Compl
|
|
142
142
|
|
143
143
|
```ruby
|
144
144
|
Rubygpt.chat.create(
|
145
|
-
n:
|
146
|
-
messages: ["
|
145
|
+
n: 3,
|
146
|
+
messages: ["Explain the history of Istanbul."],
|
147
147
|
model: 'gpt-4-turbo-preview', # overrides your client config when provided explicity here
|
148
148
|
max_tokens: 100,
|
149
149
|
frequency_penalty: 1.0,
|
150
|
-
|
151
|
-
user: 'feapaydin'
|
152
|
-
json: true # DO NOT provide response_format for JSON mode, use this flag
|
150
|
+
temperature: 1,
|
151
|
+
user: 'feapaydin'
|
153
152
|
)
|
154
153
|
```
|
155
154
|
|
@@ -165,16 +164,18 @@ To send a message in JSON mode, you can simply send `json: true` option along wi
|
|
165
164
|
|
166
165
|
```ruby
|
167
166
|
# Single message with JSON mode
|
168
|
-
Rubygpt.chat.create(content: "List all programming languages by their creation date.", json: true)
|
167
|
+
Rubygpt.chat.create(content: "List all programming languages by their creation date in a json.", json: true)
|
169
168
|
|
170
169
|
# Multiple messages with JSON mode
|
171
170
|
messages = [
|
172
|
-
{ role: 'user', content: "List all programming languages by their creation date." },
|
173
|
-
{ role: 'user', content: "Also add their creator's name to the objects." }
|
171
|
+
{ role: 'user', content: "List all programming languages by their creation date as JSON." },
|
172
|
+
{ role: 'user', content: "Also add their creator's name to the objects to JSON attributes." }
|
174
173
|
]
|
175
174
|
Rubygpt.chat.create(messages:, json: true)
|
176
175
|
```
|
177
176
|
|
177
|
+
An important note is that the `messages` data must contain the keyword `json` ("explain in JSON format...") when using the JSON mode. This is required by ChatGPT APIs.
|
178
|
+
|
178
179
|
### Stream Mode
|
179
180
|
|
180
181
|
Streaming mode is a feature of the Chat Completions API that allows the model to generate a continuous stream of messages. This is useful for chat applications where the model is expected to generate multiple or longer responses to a single prompt.
|
@@ -202,7 +203,7 @@ Each Choice in the response is an instance of `Response::ChatCompletion::Choice`
|
|
202
203
|
|
203
204
|
```ruby
|
204
205
|
response = Rubygpt.chat.create("What time is it?", "Also tell me the date.")
|
205
|
-
response.choices # => [Response::ChatCompletion::Choice
|
206
|
+
response.choices # => [Response::ChatCompletion::Choice]
|
206
207
|
response.choices.first.index # => 0
|
207
208
|
response.choices.first.message # => <#Common::Message>
|
208
209
|
response.choices.first.content # => "It's 12:00 PM." - delegated from message
|
@@ -6,6 +6,9 @@ module Common
|
|
6
6
|
# Represents a Message object that is used in OpenAI Chat API requests
|
7
7
|
# This object is referenced by both ChatRequester and ChatCompletion objects
|
8
8
|
class Message
|
9
|
+
# The keys that are used in the request body for messages
|
10
|
+
MESSAGE_REQUEST_KEYS = %i[role content name tool_calls tool_call_id].freeze
|
11
|
+
|
9
12
|
# The role of the author of this message.
|
10
13
|
# One of: user, assistant, system
|
11
14
|
# Default: system
|
@@ -23,7 +23,9 @@ module Rubygpt
|
|
23
23
|
faraday_response = super(*args)
|
24
24
|
Rubygpt::Response::StandardApiResponse.new(
|
25
25
|
adapter_response: faraday_response,
|
26
|
-
|
26
|
+
status: faraday_response.status,
|
27
|
+
body: faraday_response.body,
|
28
|
+
headers: faraday_response.headers
|
27
29
|
)
|
28
30
|
end
|
29
31
|
end
|
@@ -37,7 +37,7 @@ module Rubygpt
|
|
37
37
|
# https://platform.openai.com/docs/guides/text-generation/json-mode
|
38
38
|
request_body[:response_format] = { type: "json_object" } if args[:json]
|
39
39
|
request_body[:messages] = messages_from_hash(args)
|
40
|
-
request_body.merge! args.except(:messages, :json)
|
40
|
+
request_body.merge! args.except(:messages, :json, *Common::Message::MESSAGE_REQUEST_KEYS)
|
41
41
|
else
|
42
42
|
request_body[:messages] = messages_from_args(args)
|
43
43
|
end
|
@@ -48,9 +48,6 @@ module Rubygpt
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
# Readers for the standard attributes of the ChatCompletion object
|
52
|
-
attr_reader :id, :object, :created, :model, :system_fingerprint, :usage, :choices
|
53
|
-
|
54
51
|
# Initializes the ChatCompletion object
|
55
52
|
#
|
56
53
|
# @param [StandardApiResponse] api_response The response from the API, standardized by the connection object
|
@@ -76,7 +73,7 @@ module Rubygpt
|
|
76
73
|
end
|
77
74
|
|
78
75
|
def cost
|
79
|
-
usage[:total_tokens]
|
76
|
+
usage["total_tokens"] || usage[:total_tokens]
|
80
77
|
end
|
81
78
|
|
82
79
|
def to_h
|
data/lib/rubygpt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubygpt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Furkan Enes Apaydin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,7 +66,10 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.23.0
|
69
|
-
description:
|
69
|
+
description: |
|
70
|
+
This gem aims to provide an easy-to-use Ruby wrapper for all modules of OpenAI's GPT API.
|
71
|
+
It is designed to be simple and easy to use, while also providing a high level of customization.
|
72
|
+
It is also aiming to work efficiently in Ruby on Rails applications.
|
70
73
|
email:
|
71
74
|
- feapaydin@gmail.com
|
72
75
|
executables: []
|
@@ -95,7 +98,8 @@ files:
|
|
95
98
|
- lib/rubygpt/version.rb
|
96
99
|
- sig/rubygpt.rbs
|
97
100
|
homepage: https://github.com/feapaydin/rubygpt
|
98
|
-
licenses:
|
101
|
+
licenses:
|
102
|
+
- MIT
|
99
103
|
metadata:
|
100
104
|
homepage_uri: https://github.com/feapaydin/rubygpt
|
101
105
|
source_code_uri: https://github.com/feapaydin/rubygpt
|
@@ -115,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
119
|
- !ruby/object:Gem::Version
|
116
120
|
version: '0'
|
117
121
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
122
|
+
rubygems_version: 3.5.10
|
119
123
|
signing_key:
|
120
124
|
specification_version: 4
|
121
125
|
summary: Ruby wrapper for OpenAI's ChatGPT APIs.
|