ask_chatgpt 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a5ccd11d62b51d4422562be281edcf67254e9829f551edf2f91acd970fd091b
4
- data.tar.gz: 1328f4ffedb742cce8c330de2fedf7bca4632610a5e95e0215a6dabc6dc3d50d
3
+ metadata.gz: 1bc7b02b4d83823e029b13324c8b66abd9f4e291303d9a203963b3be1817aee9
4
+ data.tar.gz: 70c3c8987e5a1e4d2ead1b86f9de132e8834ca1ca256bbcecdd28cb351e34536
5
5
  SHA512:
6
- metadata.gz: 869bb402cb40bbaa8d0e60a4c0c9e3247a155a18b60d805c3943baa2b0c90d1ccf8471de4359df5ca63a6e5197231cca1cbae5398716e49ed0ecd0c14b2e45fe
7
- data.tar.gz: 83c04d9f695e3772ec35351b4de6e019d2f866023421045ec8f6dc2decdaded75f3feb9c70947caf1837b3942333ab69c23b4e02ca7e9efe87c77c7b248fb8af
6
+ metadata.gz: c73917306f9dfc1acf2f5ba6275ea8c0123253e07ba1f774eacea5e15658d00eb1166555c3c6714e1ad0d3c0860d029f1c8d17612d206e679676d0f64c5be536
7
+ data.tar.gz: 9b6bfd8026eccb6dac490ddc7ae39366153dcf48c84cd95956fe724241cfe7e89c17a0bdc2f78fc6fb6641b53aebae6de0e89b581aaf3c55103f0a76cdfa2048
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  AI-Powered Assistant Gem right in your Rails console.
7
7
 
8
+ NEW UPDATE: Voice input using your microphone, demo: https://youtu.be/uBR0wnQvKao
9
+
8
10
  ![AskChatGPT](docs/interactive.gif)
9
11
 
10
12
  A Gem that leverages the power of AI to make your development experience more efficient and enjoyable. With this gem, you can streamline your coding process, effortlessly refactor and improve your code, and even generate tests on the fly.
@@ -18,6 +20,8 @@ Go to Rails console and run:
18
20
  ```ruby
19
21
  gpt.ask("how to get max age of user with projects from Ukraine").with_model(User, Project, Country)
20
22
  gpt.ask("convert json to xml")
23
+ gpt.with_code("User.get_report", Project).ask "make it better" # with_class alias for with_code
24
+ gpt.with_class(User).ask "make it better"
21
25
  gpt.payload(json).ask("extract emails from json")
22
26
  gpt.refactor("User.get_report")
23
27
  gpt.improve("User.get_report")
@@ -258,11 +262,25 @@ How to use:
258
262
 
259
263
  ```
260
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?"
261
266
  ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
262
267
  ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
263
268
  ask_chatgpt -f test/dummy/Gemfile -q "sort Ruby gems alphabetically"
269
+ ask_chatgpt -m 3.5 -q "How to parse JSON file in Ruby?"
270
+ ask_chatgpt -m 4 -q "Why Ruby is the best language?"
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'
264
280
  ```
265
281
 
282
+ and now you can use `q "how to unzip file with Ruby"`
283
+
266
284
  ## Streaming (async vs sync mode)
267
285
 
268
286
  Control the mode from a console. Or, from the initializer, using `config.mode = :async` (or sync).
@@ -272,6 +290,23 @@ Control the mode from a console. Or, from the initializer, using `config.mode =
272
290
  gpt.sync!
273
291
  ```
274
292
 
293
+ ## Random Tips
294
+
295
+ ![AskChatGPT](docs/random_facts.png)
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
+
275
310
  ## Markdown
276
311
 
277
312
  Try to format response from Markdown and print it nicely in the console.
@@ -300,6 +335,7 @@ end
300
335
  - refactor voice input code :) as first version it's fine
301
336
  - can we discover audio device ID?
302
337
  - use tempfile for audio, instead of output.wav
338
+ - handle case when empty response is returned in CLI (when for example non-existing model is specified)
303
339
 
304
340
  ## Contributing
305
341
 
data/bin/ask_chatgpt CHANGED
@@ -21,11 +21,15 @@ 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?"
25
+ ask_chatgpt -m gpt-4 -q "How to parse JSON file in Ruby?"
24
26
  ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
25
27
  ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
26
28
  ask_chatgpt -f test/dummy/Gemfile -q "sort Ruby gems alphabetically"
27
29
  ask_chatgpt -s 1"
28
30
 
31
+ To specify model you can use shorter version: -m 4, -m 4.0, -m 3.5.
32
+
29
33
  Version: #{AskChatGPT::VERSION}
30
34
 
31
35
  USAGE
@@ -42,6 +46,14 @@ parser = OptionParser.new do |opts|
42
46
  options[:file_path] = file
43
47
  end
44
48
 
49
+ opts.on("-m", "--model MODEL", String, "Specify the ChatGPT model. Uses \"gpt-3.5-turbo\" by default") do |model|
50
+ options[:model] = model
51
+ end
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
+
45
57
  opts.on("-d", "--debug", "Output request/response") do |debug|
46
58
  options[:debug] = true
47
59
  end
@@ -56,6 +68,20 @@ parser.parse!
56
68
 
57
69
  AskChatGPT.debug = !!options[:debug]
58
70
 
71
+ if options[:model].present?
72
+ model = options[:model].to_s
73
+ disctionary = {
74
+ "4" => "gpt-4",
75
+ "4.0" => "gpt-4",
76
+ "40" => "gpt-4",
77
+ "3.5t" => "gpt-3.5-turbo",
78
+ "3.5" => "gpt-3.5-turbo",
79
+ "35" => "gpt-3.5-turbo",
80
+ }
81
+ model = disctionary[model.downcase] || model
82
+ AskChatGPT.model = model
83
+ end
84
+
59
85
  options[:prompt] = ARGV.join(" ") if options[:prompt].blank?
60
86
 
61
87
  if options[:prompt].blank? && options[:audio_device_id].blank?
@@ -65,6 +91,10 @@ end
65
91
 
66
92
  include AskChatGPT::Console
67
93
 
94
+ if options[:temperature].present?
95
+ AskChatGPT.temperature = options[:temperature].to_f
96
+ end
97
+
68
98
  if options[:audio_device_id].present?
69
99
  AskChatGPT.voice_enabled = true
70
100
  AskChatGPT.voice_max_duration = 20
@@ -1,6 +1,7 @@
1
1
  module AskChatgpt
2
2
  module DefaultBehavior
3
- DEFAULT_PROMPTS = [:improve, :refactor, :question, :find_bug, :code_review, :rspec_test, :unit_test, :explain]
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
@@ -22,6 +23,9 @@ module AskChatgpt
22
23
  alias :how :question
23
24
  alias :find :question
24
25
  alias :review :code_review
26
+ alias :with_class :with_code
27
+ alias :random :random_tip
28
+ alias :tip :random_tip
25
29
 
26
30
  def add_prompt(prompt)
27
31
  scope << prompt
@@ -127,11 +127,25 @@ module AskChatgpt
127
127
 
128
128
  def executor_parameters
129
129
  @executor_parameters ||= {
130
- model: AskChatGPT.model,
131
- temperature: AskChatGPT.temperature,
132
- max_tokens: AskChatGPT.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
@@ -0,0 +1,25 @@
1
+ module AskChatgpt
2
+ module Prompts
3
+ class WithCode < Base
4
+
5
+ attr_reader :args
6
+
7
+ def initialize(*args)
8
+ @args = args
9
+ end
10
+
11
+ def content
12
+ code_info.reject { |v| v.blank? }.join("\n")
13
+ end
14
+
15
+ private
16
+
17
+ def code_info
18
+ args.compact.map do |arg|
19
+ AskChatGPT::Helpers.extract_source(arg)
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module AskChatgpt
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
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.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-09 00:00:00.000000000 Z
12
+ date: 2023-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -164,9 +164,11 @@ 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
171
+ - lib/ask_chatgpt/prompts/with_code.rb
170
172
  - lib/ask_chatgpt/railtie.rb
171
173
  - lib/ask_chatgpt/sugar.rb
172
174
  - lib/ask_chatgpt/version.rb
@@ -195,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
197
  - !ruby/object:Gem::Version
196
198
  version: '0'
197
199
  requirements: []
198
- rubygems_version: 3.3.7
200
+ rubygems_version: 3.4.13
199
201
  signing_key:
200
202
  specification_version: 4
201
203
  summary: AI-Powered Assistant Gem right in your Rails console.