aia 0.5.3 → 0.5.7

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: 63be1bf9f76bf377e09bd05cefc15651c05372863f411c343849d5a68d40a4d8
4
+ data.tar.gz: c979390da7d47566026c89590c283dda30c7cc9a4778242acf131d8a241b58ba
5
5
  SHA512:
6
- metadata.gz: 04fc7614ec13ba847e66def37dda93cdfbe8bd0f19425083339276c7bfa5f1ecc214684d0cb9fcb479fddb7fda2cd818ac74fd5498083af3452f8df4f8442a29
7
- data.tar.gz: 03d5adfdc25ac89cd29b752dd8a2af1c3d6876cad6206471ff9ae1c13e251ea8ee2b2c1038bb64f28febd3f977a375bbe03868b5b3b686a4c35b621e3216a2e1
6
+ metadata.gz: ceb70944b23cfe72c06fd3aa62bc377cfa95122238c75cc68906ac6f3117de1d2e9809064343b642016d729dc6cdc8af55706db292858231d0777ad7508d61d0
7
+ data.tar.gz: c1eb7647759e8c0dd9429df75ac4943e7399887e1ef0ffb3ccbc2d9f716a33d114e836c00957ebd6c192515fe4d7a2db336c4e9aa36fc84c446b06da3b1641b9
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 5
4
- :patch: 3
4
+ :patch: 7
5
5
  :special: ''
6
6
  :metadata: ''
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
  ## [Unreleased]
2
+ ## [0.5.7] 2024-01-15
3
+ - Added ERB processing to the config_file
4
+
5
+ ## [0.5.6] 2024-01-15
6
+ - Adding processing for directives, shell integration and erb to the follow up prompt in a chat session
7
+ - some code refactoring.
2
8
 
3
9
  ## [0.5.3] 2024-01-14
4
10
  - adding ability to render markdown to the terminal using the "glow" CLI utility
data/README.md CHANGED
@@ -5,6 +5,14 @@
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.7
9
+ - Added ERB processing to config files that have the pattern any_file.ext.erb where ext is the real extension of the file.
10
+
11
+ v0.5.6
12
+ - Directives within a chat session follow up are now available
13
+ - when the `--shell` option is set access to envars and shell scripts are availabe in a chat session follow up prompt
14
+ - when the `--erb` option is set, access to ERB-based dynamic content is available in a chat session follow up prompt.
15
+
8
16
  v0.5.3
9
17
  - `--render` will render markdown formatted content to the terminal using the `glow` CLI utility.
10
18
  - fixes to some terminal UI stuff like AI response is not being wrapped to the terminal width to make for easier reading.
@@ -25,11 +33,14 @@ v0.5.0 - Breaking changes:
25
33
  - [Shell Integration inside of a Prompt](#shell-integration-inside-of-a-prompt)
26
34
  - [Access to System Environment Variables](#access-to-system-environment-variables)
27
35
  - [Dynamic Shell Commands](#dynamic-shell-commands)
36
+ - [Chat Session Use](#chat-session-use)
28
37
  - [*E*mbedded *R*u*B*y (ERB)](#embedded-ruby-erb)
38
+ - [Chat Session Behavior](#chat-session-behavior)
29
39
  - [Prompt Directives](#prompt-directives)
30
40
  - [`aia` Specific Directive Commands](#aia-specific-directive-commands)
31
41
  - [//config](#config)
32
42
  - [Backend Directive Commands](#backend-directive-commands)
43
+ - [Using Directives in Chat Sessions](#using-directives-in-chat-sessions)
33
44
  - [All About ROLES](#all-about-roles)
34
45
  - [Other Ways to Insert Roles into Prompts](#other-ways-to-insert-roles-into-prompts)
35
46
  - [External CLI Tools Used](#external-cli-tools-used)
@@ -101,7 +112,15 @@ ARGUMENTS
101
112
 
102
113
  OPTIONS
103
114
  --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.
115
+ set --no-out_file so that the backend response comes to STDOUT. After the
116
+ initial prompt is processed, you will be asked to provide a follow up. Just
117
+ enter whatever is appropriate terminating your input with a RETURN. The
118
+ backend will provide a response to you follow up and ask you again if you have
119
+ another follow up. This back and forth chatting will continue until you enter a
120
+ RETURN without any other content - an empty follow up prompt. You may also
121
+ enter a directive to be processed after which another follow up is requested.
122
+ If you have the --shell and/or the --erb options set you may use those tools
123
+ within your follow up to provide dynamic content.
105
124
 
106
125
  --completion SHELL_NAME
107
126
 
@@ -147,7 +166,10 @@ OPTIONS
147
166
  Specify the backend prompt resolver - default is mods
148
167
 
149
168
  -c, --config_file PATH_TO_CONFIG_FILE
150
- Load Config File - default is nil
169
+ Load Config File. both YAML and TOML formats are supported. Also ERB is
170
+ supported. For example ~/aia_config.yml.erb will be processed through ERB and
171
+ then through YAML. The result will be written out to ~/aia_config.yml so that
172
+ you can manually verify that you got what you wanted from the ERB processing.
151
173
 
152
174
  -d, --debug
153
175
  Turn On Debugging - default is false
@@ -280,6 +302,7 @@ AUTHOR
280
302
  AIA 2024-01-01 aia(1)
281
303
  ```
282
304
 
305
+
283
306
  ## Configuration Using Envars
284
307
 
285
308
  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 +351,15 @@ or insert content from a file in your home directory:
328
351
  Given the following constraints $(cat ~/3_laws_of_robotics.txt) determine the best way to instruct my roomba to clean my kids room.
329
352
  ```
330
353
 
354
+ #### Chat Session Use
355
+
356
+ 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:
357
+
358
+ ```
359
+ The class I want to chat about refactoring is this one: $(cat my_class.rb)
360
+ ```
361
+
362
+ 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
363
 
332
364
  ## *E*mbedded *R*u*B*y (ERB)
333
365
 
@@ -337,6 +369,11 @@ The `--erb` option turns the prompt text file into a fully functioning ERB templ
337
369
 
338
370
  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
371
 
372
+ ### Chat Session Behavior
373
+
374
+ 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.
375
+
376
+ 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
377
 
341
378
  ## Prompt Directives
342
379
 
@@ -390,6 +427,17 @@ FOr example `mods` has a configuration item `topp` which can be set by a directi
390
427
 
391
428
  If `mods` is not the backend the `//topp` direcive is ignored.
392
429
 
430
+ ### Using Directives in Chat Sessions
431
+
432
+ 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:
433
+
434
+ ```
435
+ //config terse? false
436
+ ```
437
+
438
+ The directive is executed and a new follow up prompt can be entered with a more lengthy response generated from the backend.
439
+
440
+
393
441
  ## All About ROLES
394
442
 
395
443
  `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.
data/lib/aia/cli.rb CHANGED
@@ -97,7 +97,19 @@ class AIA::Cli
97
97
  end
98
98
 
99
99
 
100
+ def replace_erb_in_config_file
101
+ content = Pathname.new(AIA.config.config_file).read
102
+ content = ERB.new(content).result(binding)
103
+ AIA.config.config_file = AIA.config.config_file.to_s.gsub('.erb', '')
104
+ Pathname.new(AIA.config.config_file).write content
105
+ end
106
+
107
+
100
108
  def load_config_file
109
+ if AIA.config.config_file.to_s.end_with?(".erb")
110
+ replace_erb_in_config_file
111
+ end
112
+
101
113
  AIA.config.config_file = Pathname.new(AIA.config.config_file)
102
114
  if AIA.config.config_file.exist?
103
115
  AIA.config.merge! parse_config_file
@@ -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
@@ -57,7 +57,7 @@ Print Version \- default is false
57
57
  Specify the backend prompt resolver \- default is mods
58
58
  .TP
59
59
  \fB\-c\fR, \fB\-\-config\[ru]file\fR \fIPATH\[ru]TO\[ru]CONFIG\[ru]FILE\fP
60
- Load Config File \- default is nil
60
+ Load Config File\. both YAML and TOML formats are supported\. Also ERB is supported\. For example \[ti]\[sl]aia\[ru]config\.yml\.erb will be processed through ERB and then through YAML\. The result will be written out to \[ti]\[sl]aia\[ru]config\.yml so that you can manually verify that you got what you wanted from the ERB processing\.
61
61
  .TP
62
62
  \fB\-d\fR, \fB\-\-debug\fR
63
63
  Turn On Debugging \- default is false
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
@@ -62,7 +62,7 @@ The aia command-line tool is an interface for interacting with an AI model backe
62
62
  : Specify the backend prompt resolver - default is mods
63
63
 
64
64
  `-c`, `--config_file` *PATH_TO_CONFIG_FILE*
65
- : Load Config File - default is nil
65
+ : Load Config File. both YAML and TOML formats are supported. Also ERB is supported. For example ~/aia_config.yml.erb will be processed through ERB and then through YAML. The result will be written out to ~/aia_config.yml so that you can manually verify that you got what you wanted from the ERB processing.
66
66
 
67
67
  `-d`, `--debug`
68
68
  : Turn On Debugging - default is false
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.7
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-16 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