ask_chatgpt 0.5.0 → 0.6.1

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: e8d16800c079df0252e84b7448b7633ed07b4bdf1580a06bb76ba4e27292764e
4
- data.tar.gz: 9233fd8f8bbbcfd3cea1db3745be6633b710585d77eaf056ee6681c5b202d65c
3
+ metadata.gz: cc8c5b18804764ced049d50e8a55668634e0c8945a3d8b752b4632e79e3b42b2
4
+ data.tar.gz: 76af549756fbddcc287ab8fda259731d306ab871483ad37a3e9b1a1954da6338
5
5
  SHA512:
6
- metadata.gz: 9586b20bda0e6c3a485e1ac6e1eebf91a37ac8728a1e949c917a9ab972cdc1ee8a0b16aa8f76a700e5540ac15aa8f453d06315fdb1d418ba3de6b010504d9b07
7
- data.tar.gz: 5516576d94f71d473545b77083990d005157138c97aba1e5992faf8215592b7c2025932b1d9ea74bfcea86b016370e8e00bd1502fb34934968f04f2395a97a84
6
+ metadata.gz: aa76ea7a0467618c1d9b4ba756593c71ba9823c76ea442cf19ceee8669af9da0abf7849f771a21254daaa853b194cb310fe5bdc864ab1fc59f68ec6da6dfef3e
7
+ data.tar.gz: 33aac07b57f6d0bccca715de24686a06090ac0e805b79ed4bf5e5a56f65bf54c63126d1b5c7d4f7a37b50065208da04cc2b194f8e791e74c6540ccdac4fcdc27
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
+ ![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
+
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
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
- require 'active_support'
5
4
  require 'irb'
6
5
 
7
6
  require_relative "../lib/ask_chatgpt"
@@ -21,6 +20,7 @@ parser = OptionParser.new do |opts|
21
20
 
22
21
  Examples:
23
22
  ask_chatgpt -q "How to parse JSON file in Ruby?"
23
+ ask_chatgpt -t 0.5 -q "How to parse JSON file in Ruby?"
24
24
  ask_chatgpt -m gpt-4 -q "How to parse JSON file in Ruby?"
25
25
  ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
26
26
  ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
@@ -49,6 +49,10 @@ parser = OptionParser.new do |opts|
49
49
  options[:model] = model
50
50
  end
51
51
 
52
+ opts.on("-t", "--temperature 0.7", String, "Specify a temperature. Uses \"#{AskChatGPT.temperature}\" by default") do |temperature|
53
+ options[:temperature] = temperature
54
+ end
55
+
52
56
  opts.on("-d", "--debug", "Output request/response") do |debug|
53
57
  options[:debug] = true
54
58
  end
@@ -86,6 +90,10 @@ end
86
90
 
87
91
  include AskChatGPT::Console
88
92
 
93
+ if options[:temperature].present?
94
+ AskChatGPT.temperature = options[:temperature].to_f
95
+ end
96
+
89
97
  if options[:audio_device_id].present?
90
98
  AskChatGPT.voice_enabled = true
91
99
  AskChatGPT.voice_max_duration = 20
@@ -1,6 +1,7 @@
1
1
  module AskChatgpt
2
2
  module DefaultBehavior
3
- DEFAULT_PROMPTS = [:improve, :refactor, :question, :with_code, :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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AskChatgpt
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.1"
3
3
  end
data/lib/ask_chatgpt.rb CHANGED
@@ -11,6 +11,8 @@ require "tty-spinner"
11
11
  require "tty-cursor"
12
12
  require "irb"
13
13
 
14
+ require "active_support/all"
15
+
14
16
  require_relative "ask_chatgpt/console"
15
17
  require_relative "ask_chatgpt/executor"
16
18
  require_relative "ask_chatgpt/helpers"
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.5.0
4
+ version: 0.6.1
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-13 00:00:00.000000000 Z
12
+ date: 2023-06-18 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.3.7
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.