aia 0.5.3 → 0.5.6

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: 872817d33ce07dce0b81526206b55de4800df41adc7b31a295c0d690f677ff58
4
- data.tar.gz: f95bdf3845fec419a8b0e56a0c2075e2b1cbab79342538eeb32acb4dc255f8c1
3
+ metadata.gz: '021416691c11252ce3462ee7ec394691e0a7d0fd81eb6df473df3447dd02da3b'
4
+ data.tar.gz: 2bd5eb6bd2098c7e9bd04234a11c1192004bb217ec054aa9222334d9b96309d2
5
5
  SHA512:
6
- metadata.gz: 04fc7614ec13ba847e66def37dda93cdfbe8bd0f19425083339276c7bfa5f1ecc214684d0cb9fcb479fddb7fda2cd818ac74fd5498083af3452f8df4f8442a29
7
- data.tar.gz: 03d5adfdc25ac89cd29b752dd8a2af1c3d6876cad6206471ff9ae1c13e251ea8ee2b2c1038bb64f28febd3f977a375bbe03868b5b3b686a4c35b621e3216a2e1
6
+ metadata.gz: 0e2d78c3b6b1b8848645ef586c3b2f7a4557339504efc1a7434b12e313637e47b6803da8e5fa21908f88ee59046a372ef22553a5fdffe97d5777b65845f5ce41
7
+ data.tar.gz: 142dd7b40622124089363670fcb6ffde02368ad07de7016e6c12e0511a47d89d8b0be9b153d31076758c321e6762e1d361fd4ac086b6f8ffca8d2a2abebeff7b
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 5
4
- :patch: 3
4
+ :patch: 6
5
5
  :special: ''
6
6
  :metadata: ''
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.6] 2024-01-15
4
+ - Adding processing for directives, shell integration and erb to the follow up prompt in a chat session
5
+ - some code refactoring.
6
+
3
7
  ## [0.5.3] 2024-01-14
4
8
  - adding ability to render markdown to the terminal using the "glow" CLI utility
5
9
 
data/README.md CHANGED
@@ -5,6 +5,11 @@
5
5
  It leverages the `prompt_manager` gem to manage prompts for the `mods` and `sgpt` CLI utilities. It utilizes "ripgrep" for searching for prompt files. It uses `fzf` for prompt selection based on a search term and fuzzy matching.
6
6
 
7
7
  **Most Recent Change**: Refer to the [Changelog](CHANGELOG.md)
8
+ v0.5.6
9
+ - Directives within a chat session follow up are now available
10
+ - when the `--shell` option is set access to envars and shell scripts are availabe in a chat session follow up prompt
11
+ - when the `--erb` option is set, access to ERB-based dynamic content is available in a chat session follow up prompt.
12
+
8
13
  v0.5.3
9
14
  - `--render` will render markdown formatted content to the terminal using the `glow` CLI utility.
10
15
  - fixes to some terminal UI stuff like AI response is not being wrapped to the terminal width to make for easier reading.
@@ -25,11 +30,14 @@ v0.5.0 - Breaking changes:
25
30
  - [Shell Integration inside of a Prompt](#shell-integration-inside-of-a-prompt)
26
31
  - [Access to System Environment Variables](#access-to-system-environment-variables)
27
32
  - [Dynamic Shell Commands](#dynamic-shell-commands)
33
+ - [Chat Session Use](#chat-session-use)
28
34
  - [*E*mbedded *R*u*B*y (ERB)](#embedded-ruby-erb)
35
+ - [Chat Session Behavior](#chat-session-behavior)
29
36
  - [Prompt Directives](#prompt-directives)
30
37
  - [`aia` Specific Directive Commands](#aia-specific-directive-commands)
31
38
  - [//config](#config)
32
39
  - [Backend Directive Commands](#backend-directive-commands)
40
+ - [Using Directives in Chat Sessions](#using-directives-in-chat-sessions)
33
41
  - [All About ROLES](#all-about-roles)
34
42
  - [Other Ways to Insert Roles into Prompts](#other-ways-to-insert-roles-into-prompts)
35
43
  - [External CLI Tools Used](#external-cli-tools-used)
@@ -101,7 +109,15 @@ ARGUMENTS
101
109
 
102
110
  OPTIONS
103
111
  --chat begin a chat session with the backend after the initial prompt response; will
104
- set --no-out_file so that the backend response comes to STDOUT.
112
+ set --no-out_file so that the backend response comes to STDOUT. After the
113
+ initial prompt is processed, you will be asked to provide a follow up. Just
114
+ enter whatever is appropriate terminating your input with a RETURN. The
115
+ backend will provide a response to you follow up and ask you again if you have
116
+ another follow up. This back and forth chatting will continue until you enter a
117
+ RETURN without any other content - an empty follow up prompt. You may also
118
+ enter a directive to be processed after which another follow up is requested.
119
+ If you have the --shell and/or the --erb options set you may use those tools
120
+ within your follow up to provide dynamic content.
105
121
 
106
122
  --completion SHELL_NAME
107
123
 
@@ -280,6 +296,7 @@ AUTHOR
280
296
  AIA 2024-01-01 aia(1)
281
297
  ```
282
298
 
299
+
283
300
  ## Configuration Using Envars
284
301
 
285
302
  The `aia` configuration defaults can be over-ridden by system environment variables *(envars)* with the prefix "AIA_" followed by the config item name also in uppercase. All configuration items can be over-ridden in this way by an envar. The following table show a few examples.
@@ -328,6 +345,15 @@ or insert content from a file in your home directory:
328
345
  Given the following constraints $(cat ~/3_laws_of_robotics.txt) determine the best way to instruct my roomba to clean my kids room.
329
346
  ```
330
347
 
348
+ #### Chat Session Use
349
+
350
+ When you use the `--shell` option to start a chat session, shell integration is available in your follow up prompts. Suppose you started up a chat session using a roll of "Ruby Expert" expecting to chat about changes that could be made to a specific class BUT you forgot to include the class source file as part of the context when you got started. You could enter this as your follow up prompt to this to keep going:
351
+
352
+ ```
353
+ The class I want to chat about refactoring is this one: $(cat my_class.rb)
354
+ ```
355
+
356
+ That inserts the entire class source file into your follow up prompt. You can continue chatting with you AI Assistant avout changes to the class.
331
357
 
332
358
  ## *E*mbedded *R*u*B*y (ERB)
333
359
 
@@ -337,6 +363,11 @@ The `--erb` option turns the prompt text file into a fully functioning ERB templ
337
363
 
338
364
  Most websites that have information about ERB will give examples of how to use ERB to generate dynamice HTML content for web-based applications. That is a common use case for ERB. `aia` on the other hand uses ERB to generate dynamic prompt text.
339
365
 
366
+ ### Chat Session Behavior
367
+
368
+ In a chat session whether started by the `--chat` option or its equivalent with a directive within a prompt text file behaves a little differently w/r/t its binding and local variable assignments. Since a chat session by definition has multiple prompts, setting a local variable in one prompt and expecting it to be available in a subsequent prompt does not work. You need to use instance variables to accomplish this prompt to prompt carry over of information.
369
+
370
+ Also since follow up prompts are expected to be a single thing - sentence or paragraph - terminated by a single return, its likely that ERB enhance will be of benefit; but, you may find a use for it.
340
371
 
341
372
  ## Prompt Directives
342
373
 
@@ -390,6 +421,17 @@ FOr example `mods` has a configuration item `topp` which can be set by a directi
390
421
 
391
422
  If `mods` is not the backend the `//topp` direcive is ignored.
392
423
 
424
+ ### Using Directives in Chat Sessions
425
+
426
+ Whe you are in a chat session, you may use a directive as a follow up prompt. For example if you started the chat session with the option `--terse` expecting to get short answers from the backend; but, then you decide that you want more comprehensive answers you may do this:
427
+
428
+ ```
429
+ //config terse? false
430
+ ```
431
+
432
+ The directive is executed and a new follow up prompt can be entered with a more lengthy response generated from the backend.
433
+
434
+
393
435
  ## All About ROLES
394
436
 
395
437
  `aia` provides the `--role` CLI option to identify a prompt ID within your prompts directory which defines the context within which the LLM is to provide its response. The text of the role ID is pre-pended to the text of the primary prompt to form a complete prompt to be processed by the backend.
@@ -2,13 +2,15 @@
2
2
 
3
3
  require 'hashie'
4
4
 
5
- class AIA::Directives
6
- def initialize( prompt: )
7
- @prompt = prompt # PromptManager::Prompt instance
8
- AIA.config.directives = @prompt.directives
9
- end
5
+ =begin
6
+ AIA.config.directives is an Array of Arrays. An
7
+ entry looks like this:
8
+ [directive, parameters]
9
+ where both are String objects
10
+ =end
10
11
 
11
12
 
13
+ class AIA::Directives
12
14
  def execute_my_directives
13
15
  return if AIA.config.directives.nil? || AIA.config.directives.empty?
14
16
 
@@ -0,0 +1,26 @@
1
+ # aia/lib/aia/dynamic_content.rb
2
+
3
+ require 'erb'
4
+
5
+ module AIA::DynamicContent
6
+
7
+ # inserts environment variables (envars) and dynamic content into a prompt
8
+ # replaces patterns like $HOME and ${HOME} with the value of ENV['HOME']
9
+ # replaces patterns like $(shell command) with the output of the shell command
10
+ #
11
+ def render_env(a_string)
12
+ a_string.gsub(/\$(\w+|\{\w+\})/) do |match|
13
+ ENV[match.tr('$', '').tr('{}', '')]
14
+ end.gsub(/\$\((.*?)\)/) do |match|
15
+ `#{match[2..-2]}`.chomp
16
+ end
17
+ end
18
+
19
+
20
+ # Need to use instance variables in assignments
21
+ # to maintain binding from one follow up prompt
22
+ # to another.
23
+ def render_erb(the_prompt_text)
24
+ ERB.new(the_prompt_text).result(binding)
25
+ end
26
+ end
data/lib/aia/main.rb CHANGED
@@ -5,6 +5,7 @@ module AIA ; end
5
5
  require_relative 'config'
6
6
  require_relative 'cli'
7
7
  require_relative 'directives'
8
+ require_relative 'dynamic_content'
8
9
  require_relative 'prompt'
9
10
  require_relative 'logging'
10
11
  require_relative 'tools'
@@ -13,6 +14,7 @@ require_relative 'tools'
13
14
  # of a single class.
14
15
 
15
16
  class AIA::Main
17
+ include AIA::DynamicContent
16
18
 
17
19
  attr_accessor :logger, :tools, :backend
18
20
 
@@ -33,7 +35,8 @@ class AIA::Main
33
35
 
34
36
  @prompt = AIA::Prompt.new.prompt
35
37
 
36
- @engine = AIA::Directives.new(prompt: @prompt)
38
+
39
+ @directives_processor = AIA::Directives.new
37
40
 
38
41
  # TODO: still should verify that the tools are ion the $PATH
39
42
  # tools.class.verify_tools
@@ -71,7 +74,7 @@ class AIA::Main
71
74
 
72
75
 
73
76
  def call
74
- @engine.execute_my_directives
77
+ @directives_processor.execute_my_directives
75
78
 
76
79
  if AIA.config.chat?
77
80
  AIA.config.out_file = STDOUT
@@ -170,31 +173,41 @@ class AIA::Main
170
173
  a_string
171
174
  end
172
175
 
176
+
177
+ def handle_directives(the_prompt_text)
178
+ signal = PromptManager::Prompt::DIRECTIVE_SIGNAL
179
+ result = the_prompt_text.start_with?(signal)
180
+
181
+ if result
182
+ parts = the_prompt_text[signal.size..].split(' ')
183
+ directive = parts.shift
184
+ parameters = parts.join(' ')
185
+ AIA.config.directives << [directive, parameters]
186
+ @directives_processor.execute_my_directives
187
+ end
188
+
189
+ result
190
+ end
191
+
173
192
 
174
193
  def lets_chat
175
194
  add_continue_option
176
195
 
177
196
  the_prompt_text = ask_question_with_reline("\nFollow Up: ")
178
-
197
+
179
198
  until the_prompt_text.empty?
180
- the_prompt_text = insert_terse_phrase(the_prompt_text)
181
-
182
- result = get_and_display_result(the_prompt_text)
199
+ the_prompt_text = render_erb(the_prompt_text) if AIA.config.erb?
200
+ the_prompt_text = render_env(the_prompt_text) if AIA.config.shell?
183
201
 
184
- log_the_follow_up(the_prompt_text, result)
185
-
186
- speak result
202
+ unless handle_directives(the_prompt_text)
203
+ the_prompt_text = insert_terse_phrase(the_prompt_text)
204
+ result = get_and_display_result(the_prompt_text)
187
205
 
206
+ log_the_follow_up(the_prompt_text, result)
207
+ speak result
208
+ end
188
209
 
189
- # TODO: Allow user to enter a directive; loop
190
- # until answer is not a directive
191
- #
192
- # while !directive do
193
-
194
210
  the_prompt_text = ask_question_with_reline("\nFollow Up: ")
195
-
196
- # execute the directive
197
- # end
198
211
  end
199
212
  end
200
213
  end
data/lib/aia/prompt.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  # lib/aia/prompt.rb
2
2
 
3
3
  require 'reline'
4
- require 'erb'
4
+
5
+ require_relative 'dynamic_content'
5
6
 
6
7
  class AIA::Prompt
8
+ include AIA::DynamicContent
9
+
7
10
  #
8
11
  # used when no prompt_id is provided but there
9
12
  # are extra parameters that need to be passed
@@ -42,9 +45,11 @@ class AIA::Prompt
42
45
 
43
46
  if build
44
47
  @prompt.text = render_erb(@prompt.text) if AIA.config.erb?
45
- @prompt.text = replace_env(@prompt.text) if AIA.config.shell?
48
+ @prompt.text = render_env(@prompt.text) if AIA.config.shell?
46
49
  process_prompt
47
50
  end
51
+
52
+ AIA.config.directives = @prompt.directives
48
53
  end
49
54
 
50
55
 
@@ -93,25 +98,6 @@ class AIA::Prompt
93
98
  end
94
99
 
95
100
 
96
- # inserts environmant variables and dynamic content into a prompt
97
- # replaces patterns like $HOME and ${HOME} with the value of ENV['HOME']
98
- # replaces patterns like $(shell command) with the output of the shell command
99
- #
100
- def replace_env(a_string)
101
- a_string.gsub(/\$(\w+|\{\w+\})/) do |match|
102
- ENV[match.tr('$', '').tr('{}', '')]
103
- end.gsub(/\$\((.*?)\)/) do |match|
104
- `#{match[2..-2]}`.chomp
105
- end
106
- end
107
-
108
-
109
- # You are just asking for trouble!
110
- def render_erb(a_string)
111
- ERB.new(a_string).result(binding)
112
- end
113
-
114
-
115
101
  def replace_keywords
116
102
  puts
117
103
  puts "ID: #{@prompt.id}"
@@ -12,9 +12,12 @@ module AIA::BackendCommon
12
12
  build_command
13
13
  end
14
14
 
15
+
15
16
  def sanitize(input)
16
17
  Shellwords.escape(input)
17
18
  end
19
+
20
+
18
21
  def build_command
19
22
  @parameters += " --model #{AIA.config.model} " if AIA.config.model
20
23
  @parameters += AIA.config.extra
@@ -29,6 +32,7 @@ module AIA::BackendCommon
29
32
  @command
30
33
  end
31
34
 
35
+
32
36
  def set_parameter_from_directives
33
37
  AIA.config.directives.each do |entry|
34
38
  directive, value = entry
@@ -38,6 +42,7 @@ module AIA::BackendCommon
38
42
  end
39
43
  end
40
44
 
45
+
41
46
  def run
42
47
  case @files.size
43
48
  when 0
@@ -45,32 +50,9 @@ module AIA::BackendCommon
45
50
  when 1
46
51
  @result = `#{build_command} < #{@files.first}`
47
52
  else
48
- create_temp_file_with_contexts
49
- run_with_temp_file
50
- clean_up_temp_file
53
+ @result = %x[cat #{@files.join(' ')} | #{build_command}]
51
54
  end
52
55
 
53
56
  @result
54
57
  end
55
-
56
- def create_temp_file_with_contexts
57
- @temp_file = Tempfile.new("#{self.class::COMMAND_NAME}-context")
58
-
59
- @files.each do |file|
60
- content = File.read(file)
61
- @temp_file.write(content)
62
- @temp_file.write("\n")
63
- end
64
-
65
- @temp_file.close
66
- end
67
-
68
- def run_with_temp_file
69
- command = "#{build_command} < #{@temp_file.path}"
70
- @result = `#{command}`
71
- end
72
-
73
- def clean_up_temp_file
74
- @temp_file.unlink if @temp_file
75
- end
76
58
  end
data/man/aia.1 CHANGED
@@ -23,7 +23,7 @@ External options are optional\. Anything that follow \[lq] \-\- \[lq] will be s
23
23
  .SH OPTIONS
24
24
  .TP
25
25
  \fB\-\-chat\fR
26
- begin a chat session with the backend after the initial prompt response; will set \-\-no\-out\[ru]file so that the backend response comes to STDOUT\.
26
+ begin a chat session with the backend after the initial prompt response; will set \-\-no\-out\[ru]file so that the backend response comes to STDOUT\. After the initial prompt is processed, you will be asked to provide a follow up\. Just enter whatever is appropriate terminating your input with a RETURN\. The backend will provide a response to you follow up and ask you again if you have another follow up\. This back and forth chatting will continue until you enter a RETURN without any other content \- an empty follow up prompt\. You may also enter a directive to be processed after which another follow up is requested\. If you have the \fB\-\-shell\fR and\[sl]or the \fB\-\-erb\fR options set you may use those tools within your follow up to provide dynamic content\.
27
27
  .TP
28
28
  \fB\-\-completion\fR \fISHELL\[ru]NAME\fP
29
29
  .TP
data/man/aia.1.md CHANGED
@@ -26,7 +26,7 @@ The aia command-line tool is an interface for interacting with an AI model backe
26
26
  ## OPTIONS
27
27
 
28
28
  `--chat`
29
- : begin a chat session with the backend after the initial prompt response; will set --no-out_file so that the backend response comes to STDOUT.
29
+ : begin a chat session with the backend after the initial prompt response; will set --no-out_file so that the backend response comes to STDOUT. After the initial prompt is processed, you will be asked to provide a follow up. Just enter whatever is appropriate terminating your input with a RETURN. The backend will provide a response to you follow up and ask you again if you have another follow up. This back and forth chatting will continue until you enter a RETURN without any other content - an empty follow up prompt. You may also enter a directive to be processed after which another follow up is requested. If you have the `--shell` and/or the `--erb` options set you may use those tools within your follow up to provide dynamic content.
30
30
 
31
31
  `--completion` *SHELL_NAME*
32
32
  : Show completion script for bash|zsh|fish - default is nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-14 00:00:00.000000000 Z
11
+ date: 2024-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -229,6 +229,7 @@ files:
229
229
  - lib/aia/cli.rb
230
230
  - lib/aia/config.rb
231
231
  - lib/aia/directives.rb
232
+ - lib/aia/dynamic_content.rb
232
233
  - lib/aia/logging.rb
233
234
  - lib/aia/main.rb
234
235
  - lib/aia/prompt.rb