aia 0.5.10 → 0.5.11

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: 1cd315c42710fcff586cb6159b981fd3a1ba8c85cc950985dd46b93eb9b00ef1
4
- data.tar.gz: c97d4f8db6bfc74f047ad439a6ddbddcdde72cd5dce614b1341c356a71bbad92
3
+ metadata.gz: 740cb6d71c83fae27f2918e76a10802d805e4172aef40154b8cea3ae6800ad65
4
+ data.tar.gz: 0e9aac0e6a0917b6adb04550cac137be65d7e0fa3507af89058f0a1d96aa3b58
5
5
  SHA512:
6
- metadata.gz: 7cb087fe893bae9bf366c8cee81d4c35f329198a3508c475cbfd077661afff794299791d41b5af6faed0580e2a22eae9559ea69d6edad2a61705b81e54d52dd1
7
- data.tar.gz: d76aba8685317e19ca534202a6dcce5ac61255702abc9e5f8ffd751c2f9ff778499048ac45a5ff7a5a5ffd5222e3249e5cd51a15398f20430f010d6900a27c99
6
+ metadata.gz: 24f4eb6ace28c79ccf7c5465e3027dd03e25457df5c522b828775c681e51cfeab207d1c6eb9f237b3b84fa768b20f2c49b27779a8987fb1c7160f68152fe5e8f
7
+ data.tar.gz: 260685bca6ab7c0cc53b2fc566b997026d857d96c71b6889bcff3b85bd57bbfa526d4a8df6d0044b7c400a2b3be26669a81be77900669deffc4f318f1a7674c2
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 5
4
- :patch: 10
4
+ :patch: 11
5
5
  :special: ''
6
6
  :metadata: ''
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.11] 2024-02-18
4
+ - allow directives to return information that is inserted into the prompt text
5
+ - added //shell command directive
6
+ - added //ruby ruby_code directive
7
+ - added //include path_to_file directive
8
+
3
9
  ## [0.5.10] 2024-02-03
4
10
  - Added --roles_dir to isolate roles from other prompts if desired
5
11
  - Changed --prompts to --prompts_dir to be consistent
data/README.md CHANGED
@@ -6,16 +6,18 @@ It leverages the `prompt_manager` gem to manage prompts for the `mods` and `sgpt
6
6
 
7
7
  **Most Recent Change**: Refer to the [Changelog](CHANGELOG.md)
8
8
 
9
+ > v0.5.11
10
+ > - Allow directives to prepend content into the prompt text
11
+ > - Added //include path_to_file
12
+ > - Added //shell shell_command
13
+ > - Added //ruby ruby code
14
+ >
9
15
  > v0.5.10
10
16
  > - Added --roles_dir
11
17
  > - Changed --prompts to --prompts_dir
12
18
  > - Fixed Issue 33
13
19
  >
14
- > v0.5.9
15
- > - When "--verbose" is used, an animation is shown while the backend is composing its response to the prompt.
16
- >
17
- > v0.5.7
18
- > - Added ERB processing to config files that have the pattern any_file.ext.erb where ext is the real extension of the file.
20
+
19
21
 
20
22
  <!-- Tocer[start]: Auto-generated, don't remove. -->
21
23
 
@@ -31,8 +33,12 @@ It leverages the `prompt_manager` gem to manage prompts for the `mods` and `sgpt
31
33
  - [*E*mbedded *R*u*B*y (ERB)](#embedded-ruby-erb)
32
34
  - [Chat Session Behavior](#chat-session-behavior)
33
35
  - [Prompt Directives](#prompt-directives)
36
+ - [Parameter and Shell Substitution in Directives](#parameter-and-shell-substitution-in-directives)
34
37
  - [`aia` Specific Directive Commands](#aia-specific-directive-commands)
35
38
  - [//config](#config)
39
+ - [//include](#include)
40
+ - [//ruby](#ruby)
41
+ - [//shell](#shell)
36
42
  - [Backend Directive Commands](#backend-directive-commands)
37
43
  - [Using Directives in Chat Sessions](#using-directives-in-chat-sessions)
38
44
  - [All About ROLES](#all-about-roles)
@@ -76,298 +82,8 @@ You may also want to install the completion script for your shell. To get a cop
76
82
 
77
83
  The usage report obtained using either `-h` or `--help` is implemented as a standard `man` page. You can use both `--help --verbose` of `-h -v` together to get not only the `aia` man page but also the usage report from the `backend` LLM processing tool.
78
84
 
79
- ```text
85
+ ```shell
80
86
  $ aia --help
81
-
82
- aia(1) User Manuals aia(1)
83
-
84
- NAME
85
- aia - command-line interface for an AI assistant
86
-
87
- SYNOPSIS
88
- aia [options]* PROMPT_ID [CONTEXT_FILE]* [--
89
- EXTERNAL_OPTIONS+]
90
-
91
- DESCRIPTION
92
- The aia command-line tool is an interface for interacting
93
- with an AI model backend, providing a simple way to send
94
- prompts and receive responses. The CLI supports various
95
- options to customize the interaction, load a
96
- configuration file, edit prompts, set debugging levels,
97
- and more.
98
-
99
- ARGUMENTS
100
- PROMPT_ID
101
- This is a required argument.
102
-
103
- CONTEXT_FILES
104
- This is an optional argument. One or more files
105
- can be added to the prompt as context for the
106
- backend gen-AI tool to process.
107
-
108
- EXTERNAL_OPTIONS
109
- External options are optional. Anything that
110
- follow “ -- “ will be sent to the backend gen-AI
111
- tool. For example “-- -C -m gpt4-128k” will send
112
- the options “-C -m gpt4-128k” to the backend
113
- gen-AI tool. aia will not validate these external
114
- options before sending them to the backend gen-AI
115
- tool.
116
-
117
- OPTIONS
118
- --chat begin a chat session with the backend after the
119
- initial prompt response; will set --no-out_file
120
- so that the backend response comes to STDOUT.
121
- After the initial prompt is processed, you will be
122
- asked to provide a follow up. Just enter whatever
123
- is appropriate terminating your input with a
124
- RETURN. The backend will provide a response to
125
- you follow up and ask you again if you have
126
- another follow up. This back and forth chatting
127
- will continue until you enter a RETURN without any
128
- other content - an empty follow up prompt. You
129
- may also enter a directive to be processed after
130
- which another follow up is requested. If you have
131
- the --shell and/or the --erb options set you may
132
- use those tools within your follow up to provide
133
- dynamic content.
134
-
135
- --completion SHELL_NAME
136
-
137
- --dump PATH/TO/FILE.ext
138
- Dump the current configuration to a file in the
139
- format denoted by the file’s extension. Currently
140
- only .yml, .yaml and .toml are acceptable file
141
- extensions. If the file exists, it will be
142
- over-written without warning.
143
-
144
- -e, --edit
145
- Invokes an editor on the prompt file. You can
146
- make changes to the prompt file, save it and the
147
- newly saved prompt will be processed by the
148
- backend.
149
-
150
- --shell
151
- This option tells aia to replace references to
152
- system environment variables in the prompt with
153
- the value of the envar. envars are like $HOME and
154
- ${HOME} in this example their occurance will be
155
- replaced by the value of ENV[‘HOME’]. Also the
156
- dynamic shell command in the pattern $(shell
157
- command) will be executed and its output replaces
158
- its pattern. It does not matter if your shell
159
- uses different patters than BASH since the
160
- replacement is being done within a Ruby context.
161
-
162
- --erb If dynamic prompt content using $(...) wasn’t
163
- enough here is ERB. Embedded RUby. <%= ruby code
164
- %> within a prompt will have its ruby code
165
- executed and the results of that execution will be
166
- inserted into the prompt. I’m sure we will find a
167
- way to truly misuse this capability. Remember,
168
- some say that the simple prompt is the best
169
- prompt.
170
-
171
- --model NAME
172
- Name of the LLM model to use - default is
173
- gpt-4-1106-preview
174
-
175
- --render
176
- Render markdown to the terminal using the external
177
- tool “glow” - default: false
178
-
179
- --speak
180
- Simple implementation. Uses the “say” command to
181
- speak the response. Fun with --chat
182
-
183
- --terse
184
- Add a clause to the prompt text that instructs the
185
- backend to be terse in its response.
186
-
187
- --version
188
- Print Version - default is false
189
-
190
- -b, --[no]-backend LLM TOOL
191
- Specify the backend prompt resolver - default is
192
- mods
193
-
194
- -c, --config_file PATH_TO_CONFIG_FILE
195
- Load Config File. both YAML and TOML formats are
196
- supported. Also ERB is supported. For example
197
- ~/aia_config.yml.erb will be processed through ERB
198
- and then through YAML. The result will be written
199
- out to ~/aia_config.yml so that you can manually
200
- verify that you got what you wanted from the ERB
201
- processing.
202
-
203
- -d, --debug
204
- Turn On Debugging - default is false
205
-
206
- -e, --edit
207
- Edit the Prompt File - default is false
208
-
209
- -f, --fuzzy`
210
- Use Fuzzy Matching when searching for a prompt -
211
- default is false
212
-
213
- -h, --help
214
- Show Usage - default is false
215
-
216
- -l, --[no]-log_file PATH_TO_LOG_FILE
217
- Log FILEPATH - default is
218
- $HOME/.prompts/prompts.log
219
-
220
- -m, --[no]-markdown
221
- Format with Markdown - default is true
222
-
223
- -o, --[no]-out_file PATH_TO_OUTPUT_FILE
224
- Out FILENAME - default is ./temp.md
225
-
226
- -p, --prompts_dir PATH_TO_DIRECTORY
227
- Directory containing the prompt files - default is
228
- ~/.prompts
229
-
230
- --roles_dir PATH_TO_DIRECTORY
231
- Directory containing the personification prompt
232
- files - default is ~/.prompts/roles
233
-
234
- -r, --role ROLE_ID
235
- A role ID is the same as a prompt ID. A “role” is
236
- a specialized prompt that gets pre-pended to
237
- another prompt. It’s purpose is to configure the
238
- LLM into a certain orientation within which to
239
- resolve its primary prompt.
240
-
241
- -v, --verbose
242
- Be Verbose - default is false
243
-
244
- CONFIGURATION HIERARCHY
245
- System Environment Variables (envars) that are all
246
- uppercase and begin with “AIA_” can be used to over-ride
247
- the default configuration settings. For example setting
248
- “export AIA_PROMPTS_DIR=~/Documents/prompts” will
249
- over-ride the default configuration; however, a config
250
- value provided by a command line options will over-ride
251
- an envar setting.
252
-
253
- Configuration values found in a config file will
254
- over-ride all other values set for a config item.
255
-
256
- ”//config” directives found inside a prompt file
257
- over-rides that config item regardless of where the value
258
- was set.
259
-
260
- For example “//config chat? = true” within a prompt will
261
- setup the chat back and forth chat session for that
262
- specific prompt regardless of the command line options or
263
- the envar AIA_CHAT settings
264
-
265
- OpenAI ACCOUNT IS REQUIRED
266
- Additionally, the program requires an OpenAI access key,
267
- which can be specified using one of the following
268
- environment variables:
269
-
270
- • OPENAI_ACCESS_TOKEN
271
-
272
- • OPENAI_API_KEY
273
-
274
- Currently there is not specific standard for name of the
275
- OpenAI key. Some programs use one name, while others use
276
- a different name. Both of the envars listed above mean
277
- the same thing. If you use more than one tool to access
278
- OpenAI resources, you may have to set several envars to
279
- the same key value.
280
-
281
- To acquire an OpenAI access key, first create an account
282
- on the OpenAI platform, where further documentation is
283
- available.
284
-
285
- USAGE NOTES
286
- aia is designed for flexibility, allowing users to pass
287
- prompt ids and context files as arguments. Some options
288
- change the behavior of the output, such as --out_file for
289
- specifying a file or --no-out_file for disabling file
290
- output in favor of standard output (STDPIT).
291
-
292
- The --completion option displays a script that enables
293
- prompt ID auto-completion for bash, zsh, or fish shells.
294
- It’s crucial to integrate the script into the shell’s
295
- runtime to take effect.
296
-
297
- The --dump path/to/file.ext option will write the current
298
- configuration to a file in the format requested by the
299
- file’s extension. The following extensions are
300
- supported: .yml, .yaml and .toml
301
-
302
- PROMPT DIRECTIVES
303
- Within a prompt text file any line that begins with “//”
304
- is considered a prompt directive. There are numerious
305
- prompt directives available. In the discussion above on
306
- the configuration you learned about the “//config”
307
- directive.
308
-
309
- Detail discussion on individual prompt directives is TBD.
310
- Most likely it will be handled in the github wiki
311
- <https://github.com/MadBomber/aia>
312
-
313
- SEE ALSO
314
-
315
- • OpenAI Platform Documentation
316
- <https://platform.openai.com/docs/overview>
317
- for more information on obtaining access tokens
318
- <https://platform.openai.com/account/api-keys>
319
- and working with OpenAI models.
320
-
321
- • mods <https://github.com/charmbracelet/mods>
322
- for more information on mods - AI for the
323
- command line, built for pipelines. LLM based AI
324
- is really good at interpreting the output of
325
- commands and returning the results in CLI
326
- friendly text formats like Markdown. Mods is a
327
- simple tool that makes it super easy to use AI
328
- on the command line and in your pipelines. Mods
329
- works with OpenAI
330
- <https://platform.openai.com/account/api-keys>
331
- and LocalAI
332
- <https://github.com/go-skynet/LocalAI>
333
-
334
- • sgpt <https://github.com/tbckr/sgpt>
335
- (aka shell-gpt) is a powerful command-line
336
- interface (CLI) tool designed for seamless
337
- interaction with OpenAI models directly from
338
- your terminal. Effortlessly run queries,
339
- generate shell commands or code, create images
340
- from text, and more, using simple commands.
341
- Streamline your workflow and enhance
342
- productivity with this powerful and
343
- user-friendly CLI tool.
344
-
345
- • fzf <https://github.com/junegunn/fzf>
346
- fzf is a general-purpose command-line fuzzy
347
- finder. It’s an interactive Unix filter for
348
- command-line that can be used with any list;
349
- files, command history, processes, hostnames,
350
- bookmarks, git commits, etc.
351
-
352
- • ripgrep <https://github.com/BurntSushi/ripgrep>
353
- Search tool like grep and The Silver Searcher.
354
- It is a line-oriented search tool that
355
- recursively searches a directory tree for a
356
- regex pattern. By default, ripgrep will respect
357
- gitignore rules and automatically skip hidden
358
- files/directories and binary files. (To disable
359
- all automatic filtering by default, use rg
360
- -uuu.) ripgrep has first class support on
361
- Windows, macOS and Linux, with binary downloads
362
- available for every release.
363
-
364
- • glow <https://github.com/charmbracelet/glow>
365
- Render markdown on the CLI
366
-
367
- AUTHOR
368
- Dewayne VanHoozer <dvanhoozer@gmail.com>
369
-
370
- AIA v0.5.10 aia(1)
371
87
  ```
372
88
 
373
89
  ## Configuration Using Envars
@@ -452,9 +168,28 @@ Downstream processing directives were added to the `prompt_manager` gem used by
452
168
 
453
169
  There is no space between the "//" and the command.
454
170
 
171
+ ### Parameter and Shell Substitution in Directives
172
+
173
+ When you combine prompt directives with prompt parameters and shell envar substitutions you can get some powerful compositional prompts.
174
+
175
+ Here is an example of a pure generic directive.
176
+
177
+ ```
178
+ //[DIRECTIVE_NAME] [DIRECTIVE_PARAMS]
179
+ ```
180
+
181
+ When the prompt runs, you will be asked to provide a value for each of the parameters. You could answer "shell" for the directive name and "calc 22/7" if you wanted a bad approximation of PI.
182
+
183
+ Try this prompt file:
184
+ ```
185
+ //shell calc [FORMULA]
186
+
187
+ What does that number mean to you?
188
+ ```
189
+
455
190
  ### `aia` Specific Directive Commands
456
191
 
457
- At this time `aia` only has one directive command `//config`
192
+ At this time `aia` only has a few directives which are detailed below.
458
193
 
459
194
  #### //config
460
195
 
@@ -479,6 +214,64 @@ A configuration item such as `--out_file` or `--model` has an associated value o
479
214
  //config backend = mods
480
215
  ```
481
216
 
217
+ BTW: the "=" is completely options. Its actuall ignored as is ":=" if you were to choose that as your assignment operator. Also the number of spaces between the item and the value is complete arbitrary. I like to line things up so this syntax is just as valie:
218
+
219
+ ```
220
+ //config model gpt-3.5-turbo
221
+ //config out_file temp.md
222
+ //config backend mods
223
+ //config chat? true
224
+ //config terse? true
225
+ //config model gpt-4
226
+ ```
227
+
228
+ NOTE: if you specify the same config item name more than once within the prompt file, its the last one which will be set when the prompt is finally process through the LLM. For example in the example above `gpt-4` will be the model used. Being first does not count in this case.
229
+
230
+ #### //include
231
+
232
+ Example:
233
+ ```
234
+ //include path_to_file
235
+ ```
236
+
237
+ The `path_to_file` can be either absolute or relative. If it is relative, it is achored at the PWD. If the `path_to_file` includes envars, the `--shell` CLI option must be used to replace the envar in the directive with its actual value.
238
+
239
+ The file that is included will have any comments or directives excluded. It is expected that the file will be a text file so that its content can be pre-pended to the existing prompt; however, if the file is a source code file (ex: file.rb) the source code will be included HOWEVER any comment line or line that starts with "//" will be excluded.
240
+
241
+ TODO: Consider adding a command line option `--include_dir` to specify the place from which relative files are to come.
242
+
243
+ #### //ruby
244
+ Example:
245
+ ```
246
+ //ruby any_code_that_returns_an_instance_of_String
247
+ ```
248
+
249
+ This directive is in addition to ERB. At this point the `//ruby` directive is limited by the current binding which is within the `AIA::Directives#ruby` method. As such it is not likely to see much use.
250
+
251
+ However, sinces it implemented as a simple `eval(code)` then there is a potential for use like this:
252
+ ```
253
+ //ruby load(some_ruby_file); execute_some_method
254
+ ```
255
+
256
+ Each execution of a `//ruby` directive will be a fresh execution of the `AIA::Directives#ruby` method so you cannot carry local variables from one invocation to another; however, you could do something with instance variables or global variables. You might even add something to the `AIA.config` object to be pasted on to the next invocation of the directive within the context of the same prompt.
257
+
258
+ #### //shell
259
+ Example:
260
+ ```
261
+ //shell some_shell_command
262
+ ```
263
+
264
+ It is expected that the shell command will return some text to STDOUT which will be pre-pending to the existing prompt text within the prompt file.
265
+
266
+ There are no limitations on what the shell command can be. For example if you wanted to bypass the stripping of comments and directives from a file you could do something like this:
267
+ ```
268
+ //shell cat path_to_file
269
+ ```
270
+
271
+ Which does basically the same thing as the `//include` directive, except it uses the entire content of the file. For relative file paths the same thing applies. The file's path will be relative to the PWD.
272
+
273
+
274
+
482
275
  ### Backend Directive Commands
483
276
 
484
277
  See the source code for the directives supported by the backends which at this time are configuration-based as well.
@@ -486,7 +279,7 @@ See the source code for the directives supported by the backends which at this t
486
279
  - [mods](lib/aia/tools/mods.rb)
487
280
  - [sgpt](lib/aia/tools/sgpt.rb)
488
281
 
489
- FOr example `mods` has a configuration item `topp` which can be set by a directive in a prompt text file directly.
282
+ For example `mods` has a configuration item `topp` which can be set by a directive in a prompt text file directly.
490
283
 
491
284
  ```
492
285
  //topp 1.5
data/lib/aia/clause.rb ADDED
@@ -0,0 +1,7 @@
1
+ # aia/lib/aia/clause.rb
2
+
3
+ module AIA
4
+ module Clause
5
+ Terse = 'Be terse in your response.'
6
+ end
7
+ end
@@ -14,20 +14,24 @@ class AIA::Directives
14
14
  def execute_my_directives
15
15
  return if AIA.config.directives.nil? || AIA.config.directives.empty?
16
16
 
17
- not_mine = []
17
+ result = ""
18
+ not_mine = []
18
19
 
19
20
  AIA.config.directives.each do |entry|
20
21
  directive = entry[0].to_sym
21
22
  parameters = entry[1]
22
23
 
23
24
  if respond_to? directive
24
- send(directive, parameters)
25
+ output = send(directive, parameters)
26
+ result << "#{output}\n" unless output.nil?
25
27
  else
26
28
  not_mine << entry
27
29
  end
28
30
  end
29
31
 
30
32
  AIA.config.directives = not_mine
33
+
34
+ result.empty? ? nil : result
31
35
  end
32
36
 
33
37
 
@@ -60,5 +64,40 @@ class AIA::Directives
60
64
  AIA.config[item] = "STDOUT" == value ? STDOUT : value
61
65
  end
62
66
  end
67
+
68
+ nil
69
+ end
70
+
71
+
72
+ # when path_to_file is relative it will be
73
+ # relative to the PWD.
74
+ #
75
+ # TODO: Consider an AIA_INCLUDE_DIR --include_dir
76
+ # option to be used for all relative include paths
77
+ #
78
+ def include(path_to_file)
79
+ path = Pathname.new path_to_file
80
+ if path.exist? && path.readable?
81
+ content = path.readlines.reject do |a_line|
82
+ a_line.strip.start_with?(AIA::Prompt::COMMENT_SIGNAL) ||
83
+ a_line.strip.start_with?(AIA::Prompt::DIRECTIVE_SIGNAL)
84
+ end.join("\n")
85
+ else
86
+ abort "ERROR: could not include #{path_to_file}"
87
+ end
88
+
89
+ content
90
+ end
91
+
92
+
93
+ def shell(command)
94
+ `#{command}`
95
+ end
96
+
97
+
98
+ def ruby(code)
99
+ output = eval(code)
100
+
101
+ output.is_a?(String) ? output : nil
63
102
  end
64
103
  end
data/lib/aia/main.rb CHANGED
@@ -20,11 +20,12 @@ class AIA::Main
20
20
  include AIA::DynamicContent
21
21
  include AIA::UserQuery
22
22
 
23
- attr_accessor :logger, :tools, :backend
23
+ attr_accessor :logger, :tools, :backend, :directive_output
24
24
 
25
25
  attr_reader :spinner
26
26
 
27
- def initialize(args= ARGV)
27
+ def initialize(args= ARGV)
28
+ @directive_output = ""
28
29
  AIA::Tools.load_tools
29
30
 
30
31
  AIA::Cli.new(args)
@@ -71,7 +72,7 @@ class AIA::Main
71
72
 
72
73
 
73
74
  def call
74
- @directives_processor.execute_my_directives
75
+ directive_output = @directives_processor.execute_my_directives
75
76
 
76
77
  if AIA.config.chat?
77
78
  AIA.config.out_file = STDOUT
@@ -103,6 +104,8 @@ class AIA::Main
103
104
 
104
105
  the_prompt = @prompt.to_s
105
106
 
107
+ the_prompt.prepend(directive_output + "\n") unless directive_output.nil? || directive_output.empty?
108
+
106
109
  if AIA.config.terse?
107
110
  the_prompt.prepend "Be terse in your response. "
108
111
  end
@@ -186,7 +189,9 @@ class AIA::Main
186
189
  directive = parts.shift
187
190
  parameters = parts.join(' ')
188
191
  AIA.config.directives << [directive, parameters]
189
- @directives_processor.execute_my_directives
192
+ directive_output = @directives_processor.execute_my_directives
193
+ else
194
+ directive_output = ""
190
195
  end
191
196
 
192
197
  result
@@ -202,7 +207,16 @@ class AIA::Main
202
207
  the_prompt_text = render_erb(the_prompt_text) if AIA.config.erb?
203
208
  the_prompt_text = render_env(the_prompt_text) if AIA.config.shell?
204
209
 
205
- unless handle_directives(the_prompt_text)
210
+ if handle_directives(the_prompt_text)
211
+ unless directive_output.nil?
212
+ the_prompt_text = insert_terse_phrase(the_prompt_text)
213
+ the_prompt_text << directive_output
214
+ result = get_and_display_result(the_prompt_text)
215
+
216
+ log_the_follow_up(the_prompt_text, result)
217
+ speak result
218
+ end
219
+ else
206
220
  the_prompt_text = insert_terse_phrase(the_prompt_text)
207
221
  result = get_and_display_result(the_prompt_text)
208
222
 
data/lib/aia/prompt.rb CHANGED
@@ -23,7 +23,9 @@ class AIA::Prompt
23
23
  def to_s = ''
24
24
  end
25
25
 
26
- KW_HISTORY_MAX = 5
26
+ KW_HISTORY_MAX = 5
27
+ COMMENT_SIGNAL = '#'
28
+ DIRECTIVE_SIGNAL = "//"
27
29
 
28
30
  attr_reader :prompt
29
31
 
data/lib/aia/tools.rb CHANGED
@@ -48,5 +48,41 @@ class AIA::Tools
48
48
  require file
49
49
  end
50
50
  end
51
+
52
+
53
+ def validate_tools
54
+ raise "NotImplemented"
55
+ end
56
+
57
+
58
+ def setup_backend
59
+ AIA.config.tools.backend = find_and_initialize_backend
60
+ end
61
+
62
+
63
+ private
64
+
65
+ def find_and_initialize_backend
66
+ found = AIA::Tools.search_for(name: AIA.config.backend, role: :backend)
67
+ abort_no_backend_error if found.empty?
68
+ abort_too_many_backends_error(found) if found.size > 1
69
+
70
+ backend_klass = found.first.klass
71
+ abort "Backend not found: #{AIA.config.backend}" unless backend_klass
72
+
73
+ backend_klass.new(
74
+ text: "",
75
+ files: []
76
+ )
77
+ end
78
+
79
+ def abort_no_backend_error
80
+ abort "There are no :backend tools named #{AIA.config.backend}"
81
+ end
82
+
83
+ def abort_too_many_backends_error(found)
84
+ abort "There are #{found.size} :backend tools with the name #{AIA.config.backend}"
85
+ end
86
+
51
87
  end
52
88
  end
data/lib/aia.rb CHANGED
@@ -20,6 +20,7 @@ tramp_require('debug_me') {
20
20
  }
21
21
 
22
22
  require 'hashie'
23
+ require 'os'
23
24
  require 'pathname'
24
25
  require 'reline'
25
26
  require 'shellwords'
@@ -37,6 +38,7 @@ require 'prompt_manager'
37
38
  require 'prompt_manager/storage/file_system_adapter'
38
39
 
39
40
  require_relative "aia/version"
41
+ require_relative "aia/clause"
40
42
  require_relative "aia/main"
41
43
  require_relative "core_ext/string_wrap"
42
44
 
@@ -54,6 +56,12 @@ module AIA
54
56
 
55
57
  AIA::Main.new(args).call
56
58
  end
59
+
60
+
61
+ def speak(what)
62
+ return unless AIA.config.speak?
63
+ system "say #{Shellwords.escape(what)}" if OS.osx?
64
+ end
57
65
  end
58
66
  end
59
67
 
data/man/aia.1 CHANGED
@@ -1,6 +1,6 @@
1
1
  .\" Generated by kramdown-man 1.0.1
2
2
  .\" https://github.com/postmodern/kramdown-man#readme
3
- .TH aia 1 "v0.5.10" AIA "User Manuals"
3
+ .TH aia 1 "v0.5.11" AIA "User Manuals"
4
4
  .SH NAME
5
5
  .PP
6
6
  aia \- command\-line interface for an AI assistant
@@ -129,6 +129,18 @@ Detail discussion on individual prompt directives is TBD\. Most likely it will
129
129
  .UR https:\[sl]\[sl]github\.com\[sl]MadBomber\[sl]aia
130
130
  .UE
131
131
  \.
132
+ .PP
133
+ Some directives are:
134
+ .RS
135
+ .IP \(bu 2
136
+ \[sl]\[sl]config item value
137
+ .IP \(bu 2
138
+ \[sl]\[sl]include path\[ru]to\[ru]file
139
+ .IP \(bu 2
140
+ \[sl]\[sl]ruby ruby\[ru]code
141
+ .IP \(bu 2
142
+ \[sl]\[sl]shell shell\[ru]command
143
+ .RE
132
144
  .SH SEE ALSO
133
145
  .RS
134
146
  .IP \(bu 2
data/man/aia.1.md CHANGED
@@ -1,4 +1,4 @@
1
- # aia 1 "v0.5.10" AIA "User Manuals"
1
+ # aia 1 "v0.5.11" AIA "User Manuals"
2
2
 
3
3
  ## NAME
4
4
 
@@ -134,6 +134,14 @@ Within a prompt text file any line that begins with "//" is considered a prompt
134
134
 
135
135
  Detail discussion on individual prompt directives is TBD. Most likely it will be handled in the [github wiki](https://github.com/MadBomber/aia).
136
136
 
137
+ Some directives are:
138
+
139
+ - //config item value
140
+ - //include path_to_file
141
+ - //ruby ruby_code
142
+ - //shell shell_command
143
+
144
+
137
145
  ## SEE ALSO
138
146
 
139
147
  - [OpenAI Platform Documentation](https://platform.openai.com/docs/overview) for more information on [obtaining access tokens](https://platform.openai.com/account/api-keys) and working with OpenAI models.
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.10
4
+ version: 0.5.11
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-02-04 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: prompt_manager
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -207,17 +221,17 @@ dependencies:
207
221
  - !ruby/object:Gem::Version
208
222
  version: '0'
209
223
  description: |
210
- `aia` - the AI Assistant - is a command-line (CLI) tool for
211
- interfacing with generative AI (gen-AI/GPT) backends. Its designed
212
- to provide developers with the ability to issue prompts, receive
213
- AI-generated responses, and incorporate additional context from files
214
- such as Ruby source code. It supports configuration and customization
215
- for different environments, includes options for output formats like
216
- markdown rendering or spoken responses, and allows dynamic content
217
- generation within prompts such as shell integration and embedded
218
- Ruby. With `aia`, users benefit from a simplified setup process and
219
- an extendable interaction model with AI, suitable for a range of
220
- command-line tasks.
224
+ A command-line AI Assistante (aia) that provides pre-compositional
225
+ template prompt management to various backend gen-AI processes.
226
+ Complete shell integration allows a prompt to access system
227
+ environment variables and execut shell commands as part of the
228
+ prompt content. In addition full embedded Ruby support is provided
229
+ given even more dynamic prompt conditional content. It is a
230
+ generalized power house that rivals specialized gen-AI tools. aia
231
+ currently supports "mods" and "sgpt" CLI tools. aia uses "ripgrep"
232
+ and "fzf" CLI utilities to search for and select prompt files to
233
+ send to the backend gen-AI tool along with supported context
234
+ files.
221
235
  email:
222
236
  - dvanhoozer@gmail.com
223
237
  executables:
@@ -241,6 +255,7 @@ files:
241
255
  - lib/aia/aia_completion.bash
242
256
  - lib/aia/aia_completion.fish
243
257
  - lib/aia/aia_completion.zsh
258
+ - lib/aia/clause.rb
244
259
  - lib/aia/cli.rb
245
260
  - lib/aia/config.rb
246
261
  - lib/aia/directives.rb
@@ -287,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
302
  - !ruby/object:Gem::Version
288
303
  version: '0'
289
304
  requirements: []
290
- rubygems_version: 3.5.5
305
+ rubygems_version: 3.5.6
291
306
  signing_key:
292
307
  specification_version: 4
293
308
  summary: AI Assistant (aia) a command-line (CLI) utility