rubygpt 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- 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 +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c29fd99d6a0b1e185d8df9c9dea607414db86b0f1f08390c00c80f2c0e31d64a
|
4
|
+
data.tar.gz: 6022ab29a185b796cf5dbe6b1fe79f1e2b5cb17bfd4423bf9f150a0478bae6f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95a6b8a8e896b1c3d781d4f5b3f7b1eda88fc20d1e7c8fa32212d952d00ffff505b3ae23d74d37eabddfca07a787f0b7b9adaa81e71ad18efc11df097c632f0c
|
7
|
+
data.tar.gz: 8f2d721b411df74759b2401105d36bf8b61d55ef8af3ab003d3eefe27d2e82fcf0f9637b7e6ff7fe9c2c63c5f534a52f00f92b96c219a1fbf3f9e616593a36f3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.1] - 2024-03-13
|
4
|
+
|
5
|
+
- Fixed cost reader in response object
|
6
|
+
- Fixed standard response generation from faraday response
|
7
|
+
- Fixed a bug in message building from hash contents
|
8
|
+
- Gemspec configuration adjustments (license)
|
9
|
+
|
3
10
|
## [0.1.0] - 2024-03-08
|
4
11
|
|
5
12
|
- Created the core of the project
|
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.1
|
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-03-
|
11
|
+
date: 2024-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -95,7 +95,8 @@ files:
|
|
95
95
|
- lib/rubygpt/version.rb
|
96
96
|
- sig/rubygpt.rbs
|
97
97
|
homepage: https://github.com/feapaydin/rubygpt
|
98
|
-
licenses:
|
98
|
+
licenses:
|
99
|
+
- MIT
|
99
100
|
metadata:
|
100
101
|
homepage_uri: https://github.com/feapaydin/rubygpt
|
101
102
|
source_code_uri: https://github.com/feapaydin/rubygpt
|