chatgpt-ruby 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -3
- data/README.md +50 -0
- data/lib/chatgpt/client.rb +29 -0
- data/lib/chatgpt/ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adc49f5bb5b5d4862838cbb111ecd00bccf7a4adc3b7edb23b8f4e5157da2a8b
|
4
|
+
data.tar.gz: f4ec243a9aeeb0ee03c82b58241d9df097a2985ca7ba15a77707645b3922ff13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b7edafba1fdf4d46adada02994ea92ced8c510b11bfe03fadcf4445e39813b169a594f4baae6ae5cddb44d2146d8111827a328f5e424174826ab4eecbb2d0c0
|
7
|
+
data.tar.gz: d5c1d54f84fe5c478bbffc2d85571e9f139072a460272152088dc85e84bbbfa8b24a5b53df3030602ba22de0cbcdad019fef0f7a5ef99f718c8d1e89d18bfbf5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
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
|
+
|
1
9
|
## [1.0.0] - 2023-04-30
|
2
10
|
|
3
11
|
### Added
|
@@ -6,8 +14,6 @@
|
|
6
14
|
- Implements ChatGPT Client with methods for completions, search, classification, summary, and answer generation.
|
7
15
|
- Includes unit tests for each method.
|
8
16
|
|
9
|
-
## [Unreleased]
|
10
|
-
|
11
17
|
## [0.1.0] - 2023-03-22
|
12
18
|
|
13
|
-
- Initial release
|
19
|
+
- Initial release
|
data/README.md
CHANGED
@@ -62,6 +62,56 @@ puts completions["choices"].map { |c| c["text"] }
|
|
62
62
|
# Output: an array of completion strings
|
63
63
|
```
|
64
64
|
|
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:
|
77
|
+
|
78
|
+
```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?"
|
89
|
+
}
|
90
|
+
]
|
91
|
+
|
92
|
+
# Start a chat
|
93
|
+
response = client.chat(messages)
|
94
|
+
```
|
95
|
+
|
96
|
+
The response will be a hash containing the model's message(s). You can extract the assistant's message like this:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
|
100
|
+
puts response['choices'][0]['message']['content'] # Outputs the assistant's message
|
101
|
+
```
|
102
|
+
|
103
|
+
The conversation can be continued by extending the `messages` array and calling the `chat` method again:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
|
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
|
111
|
+
```
|
112
|
+
|
113
|
+
With this method, you can build an ongoing conversation with the model.
|
114
|
+
|
65
115
|
## Development
|
66
116
|
|
67
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.
|
data/lib/chatgpt/client.rb
CHANGED
@@ -52,6 +52,35 @@ module ChatGPT
|
|
52
52
|
request_api(url, data)
|
53
53
|
end
|
54
54
|
|
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
|
+
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
|
+
url = "#{@endpoint}/chat/completions"
|
72
|
+
|
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.
|
80
|
+
request_api(url, data)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
55
84
|
private
|
56
85
|
# Make a request to the API
|
57
86
|
#
|
data/lib/chatgpt/ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatgpt-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
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-
|
11
|
+
date: 2023-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|