ask_chatgpt 0.4.0 → 0.5.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: e8d16800c079df0252e84b7448b7633ed07b4bdf1580a06bb76ba4e27292764e
4
+ data.tar.gz: 9233fd8f8bbbcfd3cea1db3745be6633b710585d77eaf056ee6681c5b202d65c
5
5
  SHA512:
6
- metadata.gz: 869bb402cb40bbaa8d0e60a4c0c9e3247a155a18b60d805c3943baa2b0c90d1ccf8471de4359df5ca63a6e5197231cca1cbae5398716e49ed0ecd0c14b2e45fe
7
- data.tar.gz: 83c04d9f695e3772ec35351b4de6e019d2f866023421045ec8f6dc2decdaded75f3feb9c70947caf1837b3942333ab69c23b4e02ca7e9efe87c77c7b248fb8af
6
+ metadata.gz: 9586b20bda0e6c3a485e1ac6e1eebf91a37ac8728a1e949c917a9ab972cdc1ee8a0b16aa8f76a700e5540ac15aa8f453d06315fdb1d418ba3de6b010504d9b07
7
+ data.tar.gz: 5516576d94f71d473545b77083990d005157138c97aba1e5992faf8215592b7c2025932b1d9ea74bfcea86b016370e8e00bd1502fb34934968f04f2395a97a84
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, 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")
@@ -261,6 +265,8 @@ How to use:
261
265
  ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
262
266
  ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
263
267
  ask_chatgpt -f test/dummy/Gemfile -q "sort Ruby gems alphabetically"
268
+ ask_chatgpt -m 3.5 -q "How to parse JSON file in Ruby?"
269
+ ask_chatgpt -m 4 -q "Why Ruby is the best language?"
264
270
  ```
265
271
 
266
272
  ## Streaming (async vs sync mode)
@@ -300,6 +306,7 @@ end
300
306
  - refactor voice input code :) as first version it's fine
301
307
  - can we discover audio device ID?
302
308
  - use tempfile for audio, instead of output.wav
309
+ - handle case when empty response is returned in CLI (when for example non-existing model is specified)
303
310
 
304
311
  ## Contributing
305
312
 
data/bin/ask_chatgpt CHANGED
@@ -21,11 +21,14 @@ 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 -m gpt-4 -q "How to parse JSON file in Ruby?"
24
25
  ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
25
26
  ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
26
27
  ask_chatgpt -f test/dummy/Gemfile -q "sort Ruby gems alphabetically"
27
28
  ask_chatgpt -s 1"
28
29
 
30
+ To specify model you can use shorter version: -m 4, -m 4.0, -m 3.5.
31
+
29
32
  Version: #{AskChatGPT::VERSION}
30
33
 
31
34
  USAGE
@@ -42,6 +45,10 @@ parser = OptionParser.new do |opts|
42
45
  options[:file_path] = file
43
46
  end
44
47
 
48
+ opts.on("-m", "--model MODEL", String, "Specify the ChatGPT model. Uses \"gpt-3.5-turbo\" by default") do |model|
49
+ options[:model] = model
50
+ end
51
+
45
52
  opts.on("-d", "--debug", "Output request/response") do |debug|
46
53
  options[:debug] = true
47
54
  end
@@ -56,6 +63,20 @@ parser.parse!
56
63
 
57
64
  AskChatGPT.debug = !!options[:debug]
58
65
 
66
+ if options[:model].present?
67
+ model = options[:model].to_s
68
+ disctionary = {
69
+ "4" => "gpt-4",
70
+ "4.0" => "gpt-4",
71
+ "40" => "gpt-4",
72
+ "3.5t" => "gpt-3.5-turbo",
73
+ "3.5" => "gpt-3.5-turbo",
74
+ "35" => "gpt-3.5-turbo",
75
+ }
76
+ model = disctionary[model.downcase] || model
77
+ AskChatGPT.model = model
78
+ end
79
+
59
80
  options[:prompt] = ARGV.join(" ") if options[:prompt].blank?
60
81
 
61
82
  if options[:prompt].blank? && options[:audio_device_id].blank?
@@ -1,6 +1,6 @@
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, :with_code, :find_bug, :code_review, :rspec_test, :unit_test, :explain]
4
4
 
5
5
  def with_model(*models)
6
6
  self.tap do
@@ -22,6 +22,7 @@ module AskChatgpt
22
22
  alias :how :question
23
23
  alias :find :question
24
24
  alias :review :code_review
25
+ alias :with_class :with_code
25
26
 
26
27
  def add_prompt(prompt)
27
28
  scope << prompt
@@ -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.5.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.5.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-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -167,6 +167,7 @@ files:
167
167
  - lib/ask_chatgpt/prompts/refactor.rb
168
168
  - lib/ask_chatgpt/prompts/rspec_test.rb
169
169
  - lib/ask_chatgpt/prompts/unit_test.rb
170
+ - lib/ask_chatgpt/prompts/with_code.rb
170
171
  - lib/ask_chatgpt/railtie.rb
171
172
  - lib/ask_chatgpt/sugar.rb
172
173
  - lib/ask_chatgpt/version.rb