ask_chatgpt 0.5.0 → 0.6.0
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/README.md +30 -1
- data/bin/ask_chatgpt +9 -0
- data/lib/ask_chatgpt/default_behavior.rb +4 -1
- data/lib/ask_chatgpt/executor.rb +17 -3
- data/lib/ask_chatgpt/prompts/random_tip.rb +54 -0
- data/lib/ask_chatgpt/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: 1bc7b02b4d83823e029b13324c8b66abd9f4e291303d9a203963b3be1817aee9
|
4
|
+
data.tar.gz: 70c3c8987e5a1e4d2ead1b86f9de132e8834ca1ca256bbcecdd28cb351e34536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c73917306f9dfc1acf2f5ba6275ea8c0123253e07ba1f774eacea5e15658d00eb1166555c3c6714e1ad0d3c0860d029f1c8d17612d206e679676d0f64c5be536
|
7
|
+
data.tar.gz: 9b6bfd8026eccb6dac490ddc7ae39366153dcf48c84cd95956fe724241cfe7e89c17a0bdc2f78fc6fb6641b53aebae6de0e89b581aaf3c55103f0a76cdfa2048
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Go to Rails console and run:
|
|
20
20
|
```ruby
|
21
21
|
gpt.ask("how to get max age of user with projects from Ukraine").with_model(User, Project, Country)
|
22
22
|
gpt.ask("convert json to xml")
|
23
|
-
gpt.with_code(User, Project).ask "make it better" # with_class alias for with_code
|
23
|
+
gpt.with_code("User.get_report", Project).ask "make it better" # with_class alias for with_code
|
24
24
|
gpt.with_class(User).ask "make it better"
|
25
25
|
gpt.payload(json).ask("extract emails from json")
|
26
26
|
gpt.refactor("User.get_report")
|
@@ -262,6 +262,7 @@ How to use:
|
|
262
262
|
|
263
263
|
```
|
264
264
|
ask_chatgpt -q "How to parse JSON file in Ruby?"
|
265
|
+
ask_chatgpt -t 0.7 -q "How to parse JSON file in Ruby?"
|
265
266
|
ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
|
266
267
|
ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
|
267
268
|
ask_chatgpt -f test/dummy/Gemfile -q "sort Ruby gems alphabetically"
|
@@ -269,6 +270,17 @@ How to use:
|
|
269
270
|
ask_chatgpt -m 4 -q "Why Ruby is the best language?"
|
270
271
|
```
|
271
272
|
|
273
|
+
You can also create an alias "a" or "q" for example:
|
274
|
+
|
275
|
+
Edit file: `nano ~/.bash_profile`
|
276
|
+
|
277
|
+
```bash
|
278
|
+
alias a='ask_chatgpt'
|
279
|
+
alias q='ask_chatgpt'
|
280
|
+
```
|
281
|
+
|
282
|
+
and now you can use `q "how to unzip file with Ruby"`
|
283
|
+
|
272
284
|
## Streaming (async vs sync mode)
|
273
285
|
|
274
286
|
Control the mode from a console. Or, from the initializer, using `config.mode = :async` (or sync).
|
@@ -278,6 +290,23 @@ Control the mode from a console. Or, from the initializer, using `config.mode =
|
|
278
290
|
gpt.sync!
|
279
291
|
```
|
280
292
|
|
293
|
+
## Random Tips
|
294
|
+
|
295
|
+

|
296
|
+
|
297
|
+
Surprise yourself with random facts and useful tips. To use just call `gpt.random` (or `gpt.tip`, `gpt.random_tip`).
|
298
|
+
|
299
|
+
By default it's using Ruby/Rails topics (see `RandomTip` class).
|
300
|
+
|
301
|
+
But you can also use other topics, e.g.:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
gpt.tip
|
305
|
+
gpt.tip("active record")
|
306
|
+
gpt.tip("sidekiq")
|
307
|
+
gpt.tip("security")
|
308
|
+
```
|
309
|
+
|
281
310
|
## Markdown
|
282
311
|
|
283
312
|
Try to format response from Markdown and print it nicely in the console.
|
data/bin/ask_chatgpt
CHANGED
@@ -21,6 +21,7 @@ parser = OptionParser.new do |opts|
|
|
21
21
|
|
22
22
|
Examples:
|
23
23
|
ask_chatgpt -q "How to parse JSON file in Ruby?"
|
24
|
+
ask_chatgpt -t 0.5 -q "How to parse JSON file in Ruby?"
|
24
25
|
ask_chatgpt -m gpt-4 -q "How to parse JSON file in Ruby?"
|
25
26
|
ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
|
26
27
|
ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
|
@@ -49,6 +50,10 @@ parser = OptionParser.new do |opts|
|
|
49
50
|
options[:model] = model
|
50
51
|
end
|
51
52
|
|
53
|
+
opts.on("-t", "--temperature 0.7", String, "Specify a temperature. Uses \"#{AskChatGPT.temperature}\" by default") do |temperature|
|
54
|
+
options[:temperature] = temperature
|
55
|
+
end
|
56
|
+
|
52
57
|
opts.on("-d", "--debug", "Output request/response") do |debug|
|
53
58
|
options[:debug] = true
|
54
59
|
end
|
@@ -86,6 +91,10 @@ end
|
|
86
91
|
|
87
92
|
include AskChatGPT::Console
|
88
93
|
|
94
|
+
if options[:temperature].present?
|
95
|
+
AskChatGPT.temperature = options[:temperature].to_f
|
96
|
+
end
|
97
|
+
|
89
98
|
if options[:audio_device_id].present?
|
90
99
|
AskChatGPT.voice_enabled = true
|
91
100
|
AskChatGPT.voice_max_duration = 20
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module AskChatgpt
|
2
2
|
module DefaultBehavior
|
3
|
-
DEFAULT_PROMPTS = [:improve, :refactor, :question, :
|
3
|
+
DEFAULT_PROMPTS = [:improve, :refactor, :question, :random_tip,
|
4
|
+
:with_code, :find_bug, :code_review, :rspec_test, :unit_test, :explain]
|
4
5
|
|
5
6
|
def with_model(*models)
|
6
7
|
self.tap do
|
@@ -23,6 +24,8 @@ module AskChatgpt
|
|
23
24
|
alias :find :question
|
24
25
|
alias :review :code_review
|
25
26
|
alias :with_class :with_code
|
27
|
+
alias :random :random_tip
|
28
|
+
alias :tip :random_tip
|
26
29
|
|
27
30
|
def add_prompt(prompt)
|
28
31
|
scope << prompt
|
data/lib/ask_chatgpt/executor.rb
CHANGED
@@ -127,11 +127,25 @@ module AskChatgpt
|
|
127
127
|
|
128
128
|
def executor_parameters
|
129
129
|
@executor_parameters ||= {
|
130
|
-
model:
|
131
|
-
temperature:
|
132
|
-
max_tokens:
|
130
|
+
model: model,
|
131
|
+
temperature: temperature,
|
132
|
+
max_tokens: max_tokens,
|
133
133
|
messages: scope.map { |e| { role: "user", content: e.content } }.reject { |e| e[:content].blank? },
|
134
134
|
}.reject { |_, v| v.blank? }
|
135
135
|
end
|
136
|
+
|
137
|
+
def temperature
|
138
|
+
# see RandomFact class for example
|
139
|
+
new_temperature = scope.map { |e| e.class.const_get("TEMPERATURE") rescue nil }.compact.first
|
140
|
+
new_temperature.presence || AskChatGPT.temperature
|
141
|
+
end
|
142
|
+
|
143
|
+
def model
|
144
|
+
AskChatGPT.model
|
145
|
+
end
|
146
|
+
|
147
|
+
def max_tokens
|
148
|
+
AskChatGPT.max_tokens
|
149
|
+
end
|
136
150
|
end
|
137
151
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module AskChatgpt
|
2
|
+
module Prompts
|
3
|
+
class RandomTip < Question
|
4
|
+
TEMPERATURE = 0.8
|
5
|
+
TOPIC = <<~TOPIC
|
6
|
+
- Ruby
|
7
|
+
- Ruby on Rails
|
8
|
+
- Active Record
|
9
|
+
- Active Record Migrations
|
10
|
+
- Active Record Validations
|
11
|
+
- Active Record Callbacks
|
12
|
+
- Active Record Associations
|
13
|
+
- Active Record Query Interface
|
14
|
+
- Active Support Core Extensions
|
15
|
+
- Action Mailer
|
16
|
+
- Active Job
|
17
|
+
- Active Storage
|
18
|
+
- Action Cable
|
19
|
+
- Layouts and Rendering in Rails
|
20
|
+
- Action View Form Helpers
|
21
|
+
- Action Controller Overview
|
22
|
+
- Rails Routing from the Outside In
|
23
|
+
- Rails Internationalization (I18n)
|
24
|
+
- Testing Rails Applications
|
25
|
+
- Securing Rails Applications
|
26
|
+
- Debugging Rails Applications
|
27
|
+
- Configuring Rails Applications
|
28
|
+
- The Rails Command Line
|
29
|
+
- The Asset Pipeline
|
30
|
+
- Autoloading and Reloading Constants
|
31
|
+
- Classic to Zeitwerk
|
32
|
+
- Caching with Rails: An Overview
|
33
|
+
- Using Rails for API-only Applications
|
34
|
+
- Multiple Databases with Active Record
|
35
|
+
- Ruby-related gems
|
36
|
+
- Ruby, Rails open-source projects
|
37
|
+
TOPIC
|
38
|
+
|
39
|
+
def initialize(topic = TOPIC)
|
40
|
+
prompt_text = <<~PROMPT
|
41
|
+
Tell me interesting or useful tips,facts,method,code,etc for any of:
|
42
|
+
#{topic}
|
43
|
+
|
44
|
+
Answer with direct answer and no other text.
|
45
|
+
Try to be shoft by informative and clear.
|
46
|
+
Code examples reply in markdown format.
|
47
|
+
|
48
|
+
Level of difficulty: ADVANCED
|
49
|
+
PROMPT
|
50
|
+
super(prompt_text)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/ask_chatgpt/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ask_chatgpt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-05-
|
12
|
+
date: 2023-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/ask_chatgpt/prompts/improve.rb
|
165
165
|
- lib/ask_chatgpt/prompts/model.rb
|
166
166
|
- lib/ask_chatgpt/prompts/question.rb
|
167
|
+
- lib/ask_chatgpt/prompts/random_tip.rb
|
167
168
|
- lib/ask_chatgpt/prompts/refactor.rb
|
168
169
|
- lib/ask_chatgpt/prompts/rspec_test.rb
|
169
170
|
- lib/ask_chatgpt/prompts/unit_test.rb
|
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
197
|
- !ruby/object:Gem::Version
|
197
198
|
version: '0'
|
198
199
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
200
|
+
rubygems_version: 3.4.13
|
200
201
|
signing_key:
|
201
202
|
specification_version: 4
|
202
203
|
summary: AI-Powered Assistant Gem right in your Rails console.
|