aia 0.5.18 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/.version +1 -1
  4. data/CHANGELOG.md +39 -5
  5. data/README.md +388 -219
  6. data/Rakefile +16 -5
  7. data/_notes.txt +231 -0
  8. data/bin/aia +3 -2
  9. data/examples/README.md +140 -0
  10. data/examples/headlines +21 -0
  11. data/lib/aia/ai_client_adapter.rb +210 -0
  12. data/lib/aia/chat_processor_service.rb +120 -0
  13. data/lib/aia/config.rb +473 -4
  14. data/lib/aia/context_manager.rb +58 -0
  15. data/lib/aia/directive_processor.rb +267 -0
  16. data/lib/aia/{tools/fzf.rb → fzf.rb} +9 -17
  17. data/lib/aia/history_manager.rb +85 -0
  18. data/lib/aia/prompt_handler.rb +178 -0
  19. data/lib/aia/session.rb +215 -0
  20. data/lib/aia/shell_command_executor.rb +109 -0
  21. data/lib/aia/ui_presenter.rb +110 -0
  22. data/lib/aia/utility.rb +24 -0
  23. data/lib/aia/version.rb +9 -6
  24. data/lib/aia.rb +57 -61
  25. data/lib/extensions/openstruct_merge.rb +44 -0
  26. metadata +29 -43
  27. data/LICENSE.txt +0 -21
  28. data/doc/aia_and_pre_compositional_prompts.md +0 -474
  29. data/lib/aia/clause.rb +0 -7
  30. data/lib/aia/cli.rb +0 -452
  31. data/lib/aia/directives.rb +0 -142
  32. data/lib/aia/dynamic_content.rb +0 -26
  33. data/lib/aia/logging.rb +0 -62
  34. data/lib/aia/main.rb +0 -265
  35. data/lib/aia/prompt.rb +0 -275
  36. data/lib/aia/tools/ai_client_backend.rb +0 -92
  37. data/lib/aia/tools/backend_common.rb +0 -58
  38. data/lib/aia/tools/client.rb +0 -197
  39. data/lib/aia/tools/editor.rb +0 -52
  40. data/lib/aia/tools/glow.rb +0 -90
  41. data/lib/aia/tools/llm.rb +0 -77
  42. data/lib/aia/tools/mods.rb +0 -100
  43. data/lib/aia/tools/sgpt.rb +0 -79
  44. data/lib/aia/tools/subl.rb +0 -68
  45. data/lib/aia/tools/vim.rb +0 -93
  46. data/lib/aia/tools.rb +0 -88
  47. data/lib/aia/user_query.rb +0 -21
  48. data/lib/core_ext/string_wrap.rb +0 -73
  49. data/lib/core_ext/tty-spinner_log.rb +0 -25
  50. data/man/aia.1 +0 -272
  51. data/man/aia.1.md +0 -236
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.18
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ai_client
@@ -25,7 +24,7 @@ dependencies:
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
27
26
  - !ruby/object:Gem::Dependency
28
- name: hashie
27
+ name: amazing_print
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
@@ -81,7 +80,7 @@ dependencies:
81
80
  - !ruby/object:Gem::Version
82
81
  version: '0'
83
82
  - !ruby/object:Gem::Dependency
84
- name: ruby-openai
83
+ name: shellwords
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - ">="
@@ -95,7 +94,7 @@ dependencies:
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
96
  - !ruby/object:Gem::Dependency
98
- name: shellwords
97
+ name: toml-rb
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - ">="
@@ -109,7 +108,7 @@ dependencies:
109
108
  - !ruby/object:Gem::Version
110
109
  version: '0'
111
110
  - !ruby/object:Gem::Dependency
112
- name: toml-rb
111
+ name: tty-screen
113
112
  requirement: !ruby/object:Gem::Requirement
114
113
  requirements:
115
114
  - - ">="
@@ -123,7 +122,7 @@ dependencies:
123
122
  - !ruby/object:Gem::Version
124
123
  version: '0'
125
124
  - !ruby/object:Gem::Dependency
126
- name: tty-screen
125
+ name: tty-spinner
127
126
  requirement: !ruby/object:Gem::Requirement
128
127
  requirements:
129
128
  - - ">="
@@ -137,7 +136,7 @@ dependencies:
137
136
  - !ruby/object:Gem::Version
138
137
  version: '0'
139
138
  - !ruby/object:Gem::Dependency
140
- name: tty-spinner
139
+ name: versionaire
141
140
  requirement: !ruby/object:Gem::Requirement
142
141
  requirements:
143
142
  - - ">="
@@ -151,13 +150,13 @@ dependencies:
151
150
  - !ruby/object:Gem::Version
152
151
  version: '0'
153
152
  - !ruby/object:Gem::Dependency
154
- name: versionaire
153
+ name: debug_me
155
154
  requirement: !ruby/object:Gem::Requirement
156
155
  requirements:
157
156
  - - ">="
158
157
  - !ruby/object:Gem::Version
159
158
  version: '0'
160
- type: :runtime
159
+ type: :development
161
160
  prerelease: false
162
161
  version_requirements: !ruby/object:Gem::Requirement
163
162
  requirements:
@@ -179,7 +178,7 @@ dependencies:
179
178
  - !ruby/object:Gem::Version
180
179
  version: '0'
181
180
  - !ruby/object:Gem::Dependency
182
- name: amazing_print
181
+ name: minitest-reporters
183
182
  requirement: !ruby/object:Gem::Requirement
184
183
  requirements:
185
184
  - - ">="
@@ -193,7 +192,7 @@ dependencies:
193
192
  - !ruby/object:Gem::Version
194
193
  version: '0'
195
194
  - !ruby/object:Gem::Dependency
196
- name: debug_me
195
+ name: mocha
197
196
  requirement: !ruby/object:Gem::Requirement
198
197
  requirements:
199
198
  - - ">="
@@ -207,7 +206,7 @@ dependencies:
207
206
  - !ruby/object:Gem::Version
208
207
  version: '0'
209
208
  - !ruby/object:Gem::Dependency
210
- name: kramdown-man
209
+ name: rake
211
210
  requirement: !ruby/object:Gem::Requirement
212
211
  requirements:
213
212
  - - ">="
@@ -272,43 +271,32 @@ files:
272
271
  - ".version"
273
272
  - CHANGELOG.md
274
273
  - LICENSE
275
- - LICENSE.txt
276
274
  - README.md
277
275
  - Rakefile
276
+ - _notes.txt
278
277
  - bin/aia
279
- - doc/aia_and_pre_compositional_prompts.md
278
+ - examples/README.md
279
+ - examples/headlines
280
280
  - justfile
281
281
  - lib/aia.rb
282
+ - lib/aia/ai_client_adapter.rb
282
283
  - lib/aia/aia_completion.bash
283
284
  - lib/aia/aia_completion.fish
284
285
  - lib/aia/aia_completion.zsh
285
- - lib/aia/clause.rb
286
- - lib/aia/cli.rb
286
+ - lib/aia/chat_processor_service.rb
287
287
  - lib/aia/config.rb
288
- - lib/aia/directives.rb
289
- - lib/aia/dynamic_content.rb
290
- - lib/aia/logging.rb
291
- - lib/aia/main.rb
292
- - lib/aia/prompt.rb
293
- - lib/aia/tools.rb
294
- - lib/aia/tools/ai_client_backend.rb
295
- - lib/aia/tools/backend_common.rb
296
- - lib/aia/tools/client.rb
297
- - lib/aia/tools/editor.rb
298
- - lib/aia/tools/fzf.rb
299
- - lib/aia/tools/glow.rb
300
- - lib/aia/tools/llm.rb
301
- - lib/aia/tools/mods.rb
302
- - lib/aia/tools/sgpt.rb
303
- - lib/aia/tools/subl.rb
304
- - lib/aia/tools/vim.rb
305
- - lib/aia/user_query.rb
288
+ - lib/aia/context_manager.rb
289
+ - lib/aia/directive_processor.rb
290
+ - lib/aia/fzf.rb
291
+ - lib/aia/history_manager.rb
292
+ - lib/aia/prompt_handler.rb
293
+ - lib/aia/session.rb
294
+ - lib/aia/shell_command_executor.rb
295
+ - lib/aia/ui_presenter.rb
296
+ - lib/aia/utility.rb
306
297
  - lib/aia/version.rb
307
- - lib/core_ext/string_wrap.rb
308
- - lib/core_ext/tty-spinner_log.rb
298
+ - lib/extensions/openstruct_merge.rb
309
299
  - main.just
310
- - man/aia.1
311
- - man/aia.1.md
312
300
  homepage: https://github.com/MadBomber/aia
313
301
  licenses:
314
302
  - MIT
@@ -317,7 +305,6 @@ metadata:
317
305
  homepage_uri: https://github.com/MadBomber/aia
318
306
  source_code_uri: https://github.com/MadBomber/aia
319
307
  changelog_uri: https://github.com/MadBomber/aia
320
- post_install_message:
321
308
  rdoc_options: []
322
309
  require_paths:
323
310
  - lib
@@ -332,8 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
332
319
  - !ruby/object:Gem::Version
333
320
  version: '0'
334
321
  requirements: []
335
- rubygems_version: 3.5.22
336
- signing_key:
322
+ rubygems_version: 3.6.8
337
323
  specification_version: 4
338
324
  summary: AI Assistant (aia) a command-line (CLI) utility
339
325
  test_files: []
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023 Dewayne VanHoozer
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,474 +0,0 @@
1
- ## AIA and Pre-compositional AI Prompts
2
-
3
- Pre-compositional templating of prompts using `AIA` endows prompt engineers with a significant level of power typically reserved for specialized gen-AI applications. `AIA` is a versatile command-line utility, with capabilities limited only by the imagination behind the prompts you create.
4
-
5
- A pre-compositional prompt acts as a foundational template, which can be expanded into a fully fleshed-out prompt. This prompt is then handed off to a generative AI processor to transform into a response that meets your specific requirements.
6
-
7
- <!-- Tocer[start]: Auto-generated, don't remove. -->
8
-
9
- ## Table of Contents
10
-
11
- - [Introduction](#introduction)
12
- - [Large Language Models (LLM)](#large-language-models-llm)
13
- - [Running AIA](#running-aia)
14
- - [Set Up a Prompts Directory](#set-up-a-prompts-directory)
15
- - [AIA Supports Parameterized Prompts](#aia-supports-parameterized-prompts)
16
- - [Create a Parameterized Prompt](#create-a-parameterized-prompt)
17
- - [The Next Parts](#the-next-parts)
18
- - [Comments](#comments)
19
- - [Line Comments](#line-comments)
20
- - [End of File Block Comment](#end-of-file-block-comment)
21
- - [Directives](#directives)
22
- - [The `config` Directive](#the-config-directive)
23
- - [Parameter Substitution in Directives](#parameter-substitution-in-directives)
24
- - [Shell Integration](#shell-integration)
25
- - [Accessing System Environment Variables](#accessing-system-environment-variables)
26
- - [Contextual System Environment Variables](#contextual-system-environment-variables)
27
- - [Invoking Shell Commands](#invoking-shell-commands)
28
- - [Harnessing Ruby's Capabilities](#harnessing-rubys-capabilities)
29
- - [The Concept of Binding](#the-concept-of-binding)
30
- - [ERB Syntax at a Glance](#erb-syntax-at-a-glance)
31
- - [Conditional Logic](#conditional-logic)
32
- - [Accessing Current Data](#accessing-current-data)
33
- - [Summary of AIA Command-Line Tool](#summary-of-aia-command-line-tool)
34
-
35
- <!-- Tocer[finish]: Auto-generated, don't remove. -->
36
-
37
-
38
-
39
- ## Introduction
40
-
41
- The pre-compositional prompt management as utilized by the `AIA` (AI Assistant) command-line utility are a powerful extension to using the GPT technology in the terminal. If terminal programs and command-line interfaces (CLIs) aren't part of your workflow, then the current version of `AIA` may not be suitable for you.
42
-
43
- `AIA` requires a Ruby environment. To install and run `AIA` you must have Ruby installed on your system. If you are not sure if your system has Ruby installed do this in your terminal to find out:
44
-
45
- ```shell
46
- ruby --version
47
- ```
48
-
49
- To install Ruby on your machine, follow the official [Ruby installation guide](https://www.ruby-lang.org/en/documentation/installation/).
50
-
51
- With Ruby installed, you can set up `AIA` through your terminal with this command:
52
-
53
- ```shell
54
- gem install aia
55
- ```
56
-
57
- For the full potential of `AIA`, these CLI utilities are also needed:
58
-
59
- ```shell
60
- brew install ripgrep fzf mods
61
- ```
62
-
63
- For operating systems other than macOS, such as Linux or Windows, use their respective package managers (`apt`, `yum`, `dnf`, `scoop`, `choco`, etc.) to install the following tools:
64
-
65
- - `ripgrep`: An advanced search tool akin to `grep`.
66
- - `fzf`: A versatile command-line fuzzy finder.
67
- - `mods`: An AI-enhanced command-line tool for processing the outputs of other commands.
68
-
69
- ### Large Language Models (LLM)
70
-
71
- LLMs and GPTs (Generative Pre-trained Transformers) have sparked a revolution in AI by predicting text, word, sentence, pixel, and sound sequences that fit patterns initiated by a user prompt. This revolution started when computer scientist realized that syntactic approaches to language translations were ineffective in creating good translations. A statistical approach was created in which the probabilities of one set of language characters or phrases meant the same as another languages characters or phrases.
72
-
73
- For example after analysing a large number of documents about the American government the phrase "The White" is most likely followed by "House." Its not magic. Its not thinking. Its statistics or magic if you believe that matematics is magic.
74
-
75
- ### Running AIA
76
-
77
- Executing the command:
78
-
79
- ```shell
80
- aia
81
- ```
82
-
83
- will prompt:
84
-
85
- ```shell
86
- Please provide a prompt ID.
87
- ```
88
-
89
- `AIA` requires a prompt ID to function. A prompt ID corresponds to the base name of a text file in your `prompts_dir` directory. To define your prompts directory, you can set an environment variable (`AIA_PROMPTS_DIR`) or specify the path directly as a command-line option. To see all of the `AIA` command-line options do:
90
-
91
- ```shell
92
- aia --help
93
- ```
94
-
95
- ### Set Up a Prompts Directory
96
-
97
- The easiest way to tell `AIA` where the prompts directory is located is using the system environment variable $AIA_PROMPTS_DIR
98
-
99
- ```shell
100
- export AIA_PROMPTS_DIR=~/my_prompts
101
- mkdir $AIA_PROMPTS_DIR
102
- ```
103
-
104
- ## AIA Supports Parameterized Prompts
105
-
106
- `AIA`'s first layer of pre-compositional prompt management is parameterization -— where placeholders within a prompt are replaced with user-defined values. By default, `AIA` considers any uppercase sequence within square brackets as a placeholder.
107
-
108
- Examples of placeholders include:
109
-
110
- - `[KEYWORD]`
111
- - `[USER_ROLE]`
112
- - `[COMPUTER_LANGUAGE]`
113
-
114
- When using `AIA` with a sample prompt:
115
-
116
- ```shell
117
- As a [ROLE], I want to [DO_SOMETHING].
118
- ```
119
-
120
- `AIA` will ask for substitutions for each placeholder (keyword/parameter), saving your responses with the prompt file for future use. The last-used value for each placeholder is the default for subsequent uses of that specific prompt.
121
-
122
- ### Create a Parameterized Prompt
123
-
124
- Let's create a simple yet flexible prompt file:
125
-
126
- ```shell
127
- echo "[DO_WHAT]" > $AIA_PROMPTS_DIR/ad_hoc.txt
128
- ```
129
-
130
- The associated "Prompt ID" is "ad_hoc" -— the basename of the file sans the ".txt" extension. Using the "ad_hoc" prompt ID:
131
-
132
- ```shell
133
- aia ad_hoc
134
- ```
135
-
136
- results in an interaction to specify a value for `[DO_WHAT]`. For instance, entering "tell me a joke" to replace "[DO_WHAT]" will generate a response but whether its a funny joke or a dad joke is completely up to the electrons that controll the statistics of the LLM. :)
137
-
138
- ### The Next Parts
139
-
140
- Subsequent sections in this series cover:
141
-
142
- - **Comments and Directives**: Lines starting with "#" are comments and ignored during processing. Lines starting with "//" are directives and are executed (e.g., "//config chat? = true" to set interactive chat mode for the prompt.)
143
-
144
- - **Shell Integration**: Access to system environment variables and dynamic shell commands using the `--shell` option.
145
-
146
- - **Embedded RuBy (ERB)**: For expert users, the option `--erb` allows Ruby code to be embedded in prompts (`<%= ruby_code %>`), offering unparalleled flexibility in prompt composition. This is one way to embed current data into prompts for LLMs which do not have access to current real-time data.
147
-
148
- > A pre-compositional prompt essentially serves as a template that expands into a full prompt, which is then processed by a generative AI to yield a tailored response.
149
- >
150
- > To recap, a prompt ID corresponds to the basename of a text file in a prompts directory. The simplest way to inform `AIA` of your prompts directory is through the environment variable `$AIA_PROMPTS_DIR`. For a prompt ID `ad_hoc`, `AIA` will read the prompt from `$AIA_PROMPTS_DIR/ad_hoc.txt`.
151
- >
152
- > NOTE: If you're on MacOS or another system where file extensions aren't visible in the terminal by default, consider adjusting your system settings to display file extensions.
153
-
154
- ## Comments
155
-
156
- AI prompts can be thought of as programs that an AI processes to generate responses. Sometimes you get the desired outcome, and other times you don't. Iteration often precedes success, and you may later forget the rationale behind your original construction. Non-processable comments serve as documentation.
157
-
158
- Comments can also shed light on the expected values for specific keywords or parameters.
159
-
160
- Both comments and prompt content are fully searchable.
161
-
162
- ### Line Comments
163
-
164
- A line beginning with the `#` character is treated as a line comment and is disregarded during prompt processing. Line comments are useful for providing metadata such as the file path, prompt description, author, or other identifying details.
165
-
166
- Since line comments are searchable, they can also provide auxiliary context relevant to the prompt.
167
-
168
- Below is an example of a `multi_step` prompt file with line comments:
169
-
170
- ```shell
171
- # ~/prompts/multi_step.txt
172
- # Description: A template for multi-step prompts
173
-
174
- # Provide the LLM with the response format
175
- [STEP_1]
176
-
177
- # Define the role for the LLM
178
- [STEP_2]
179
-
180
- # Specify the task for the LLM
181
- [STEP_3]
182
- ```
183
-
184
- ### End of File Block Comment
185
-
186
- For content that doesn't fit into line comments, an end-of-file (EOF) comment block can be denoted as follows:
187
-
188
- ```shell
189
- __END__
190
- ```
191
-
192
- This indicates to `AIA` that no more prompt text follows.
193
-
194
- Example EOF block comment in a prompt file:
195
-
196
- ```shell
197
- Tell me some dad jokes.
198
-
199
- __END__
200
-
201
- 1. I'm reading a book on anti-gravity. It's impossible to put down.
202
- 2. Did you hear about the restaurant on the moon? Great food, but no atmosphere.
203
- 3. What do you call fake spaghetti? An impasta.
204
- ```
205
-
206
- ## Directives
207
-
208
- A directive is a line-specific action within the context of a prompt. It begins with the characters `//`. Here's the basic syntax of a directive:
209
-
210
- ```shell
211
- //directive parameters
212
- ```
213
-
214
- There should be no space between the `//` and the directive name, which is followed by at least one space before its parameters.
215
-
216
- ### The `config` Directive
217
-
218
- Directives commonly adjust the configuration settings of a prompt. For example, to enter an interactive chat session without always using the `--chat` option, include a directive in the prompt file, as seen in `$AIA_PROMPTS_DIR/chat.txt`:
219
-
220
- ```shell
221
- //config chat? = true
222
- //config terse? = true
223
-
224
- [WHAT IS ON YOUR MIND]
225
- ```
226
-
227
- The first directive simulates the `--chat` command line option, while the second imitates `--terse`.
228
-
229
- To start a chat session using this prompt, simply execute:
230
-
231
- ```shell
232
- aia chat
233
- ```
234
-
235
- You can modify any configuration items in a prompt, including the AI model, the response's output file, or the fine-tuned control parameters like temperature and `topp`. Its also possible to direct the prompt to a backend processor other than the default. (Current `AIA` supports two backend processors `mods` and `sgpt`. `mods` is the default because of its significant flexibility.)
236
-
237
- Additional directive commands were introduced in `AIA` v0.4.1, but might be deprecated due to the integration of embedded shell commands and Ruby sequences.
238
-
239
- ### Parameter Substitution in Directives
240
-
241
- As discussed in Part 1, parameters in prompts are interchangeable. This is also true for directives:
242
-
243
- ```shell
244
- //config terse? = [TERSE_YES_OR_NO]
245
- ```
246
-
247
- While one could opt to use the `--terse` command line toggle directly, employing a directive allows the prompt to adapt between verbosity levels.
248
-
249
- Parameter substitutions apply uniformly to directives, just like any other part of the prompt.
250
-
251
- ## Shell Integration
252
-
253
- The `--shell` option permits shell integration, facilitating access to system environment variables (envars) and the execution of embedded shell commands within prompts.
254
-
255
- ### Accessing System Environment Variables
256
-
257
- Incorporating envars within prompts is somewhat akin to parameter usage. With parameters, however, users are asked to provide the values for substitution. Conversely, when an envar is used, its value is automatically fetched from the shell and embedded.
258
-
259
- Envars may be indicated by one of two patterns:
260
-
261
- - `$UPPERCASE_WORD`
262
- - `${UPPERCASE_WORD}`
263
-
264
- For instance, consider the following prompts:
265
-
266
- ```shell
267
- As a $ROLE ...
268
- ```
269
-
270
- versus
271
-
272
- ```shell
273
- As a [ROLE] ...
274
- ```
275
-
276
- In the first example, the shell supplies the `$ROLE` value, whereas the second prompt implies interaction with the user to define `[ROLE]`.
277
-
278
- In scenarios where multiple prompts utilize the same `ROLE`, it is practical to set an envar to circumvent the interactive step:
279
-
280
- ```shell
281
- export ROLE="expert Ruby on Rails software developer"
282
- aia example1 --shell -o response1.md
283
- aia example2 --shell -o response2.md
284
- # ...
285
- ```
286
-
287
- #### Contextual System Environment Variables
288
-
289
- With tools like `direnv`, you can set environment variables specific to your current directory tree context. On MacOS, `direnv` can be installed via `brew install direnv`. There value only exists so long as you are working with the directory tree covered by the `.envrc` file the `direnv` uses to define its envars.
290
-
291
- Imagine working in two project directory trees with different roles. In a `src` directory, your role is that of a software developer, whereas in a `doc` directory, you perform as a documentation specialist.
292
-
293
- For the `src` directory, your `.envrc` file could be:
294
-
295
- ```shell
296
- export ROLE="Crystal software developer"
297
- ```
298
-
299
- Meanwhile, within the `doc` directory, `.envrc` might contain:
300
-
301
- ```shell
302
- export ROLE="editorial assistant with experience writing documentation"
303
- ```
304
-
305
- Now, consider this prompt, suitable for use in both contexts:
306
-
307
- ```shell
308
- # ~/.prompts/review.txt
309
-
310
- As a $ROLE, review the following file and suggest improvements.
311
- ```
312
-
313
- Depending on the active directory, invoking the prompt in `src` yields suggestions tailored for Crystal source code, whereas in `doc`, it provides advice based on markdown-formatted documentation.
314
-
315
- ### Invoking Shell Commands
316
-
317
- Additionally, the `--shell` option enables `AIA` to execute shell commands embedded in the prompt. The result of the shell command is then injected directly into the spot where the command is placed in the text file.
318
-
319
- Here's the pattern for embedding a shell command:
320
-
321
- ```shell
322
- $(...)
323
- ```
324
-
325
- Whatever lies between the parentheses is executed as a shell command, ranging from the straightforward to the complex, depending on the desired outcome. Any output directed to `STDOUT` will be incorporated into the prompt text where specified.
326
-
327
- For a practical example, consider this prompt which is intended for scrutinizing a system log file:
328
-
329
- ```shell
330
- # ~/.prompts/summarize_log.txt
331
- # Description: Examine a system log file for issues
332
-
333
- As an experienced system administrator and senior DevOps engineer on the $(uname -v) platform, please review the following log entries and summarize any potential issues, providing recommendations for mitigation: $(tail -n $LOG_ENTRIES $LOG_FILE)
334
- ```
335
-
336
-
337
-
338
- > A pre-compositional prompt serves as a foundational template. It's expanded into a fully-fledged prompt, ready to be handed off to a generative AI processor. The end goal is a response tailored to your specific requirements.
339
-
340
-
341
- ## Harnessing Ruby's Capabilities
342
-
343
- The `AIA` command-line option `--erb` ebables the execution of embedded Ruby code within a prompt text file.
344
-
345
- Ruby ERB (Embedded Ruby) is a system designed for interweaving Ruby code with text documents. This is especially useful for content that requires dynamic generation such as text files that undergo computation or data incorporation.
346
-
347
- ERB boasts numerous powerful features:
348
-
349
- 1. **Ruby Code Embedding**: Insert and execute any valid Ruby code inside a text document. Whether it's performing calculations or invoking methods, ERB's capabilities are far-reaching.
350
-
351
- 2. **Safe Evaluation**: ERB templates can be evaluated within a `binding` that exposes only select variables and methods. This precaution is crucial when dealing with untrusted template content.
352
-
353
- 3. **Control Structures**: Adopt Ruby control structures such as loops and conditionals within ERB, allowing conditional content inclusion.
354
-
355
- 4. **User-Friendly**: The ERB syntax is straightforward and blends seamlessly with usual text, providing a smooth experience for those familiar with HTML and similar languages.
356
-
357
- 5. **Included in Ruby's Standard Library**: ERB comes bundled with Ruby, negating the need for extra installations where Ruby is present.
358
-
359
- 6. **Industry Standard**: As the default engine for many Ruby frameworks, including Rails for views, ERB's reliability and support are well-established.
360
-
361
- 7. **Error Reporting**: ERB pinpoints errors with detailed stack traces, pointing out the exact line in the template to facilitate debugging.
362
-
363
- 8. **Commentary**: Integrate comments into an ERB template that remain hidden from the final output, parallel to Ruby comment syntax and the line comments used by `ai` which aids in documentation.
364
-
365
- ### The Concept of Binding
366
-
367
- In Ruby — and ERB by extension — the 'binding' refers to the execution context, the sphere where Ruby objects bind to values. It's the scope within which Ruby objects are accessible; objects outside the binding remain out of reach.
368
-
369
- With the `--erb` option in `AIA`, the binding for Ruby code in a prompt text file is confined to the file itself. You can define anything from scalar values to arrays and hashes, as well as methods or any other Ruby object type you might need. There is great freedom, yet the binding keeps a firm boundary — if an object is undefined within the prompt text, it remains inaccessible.
370
-
371
- For a detailed exploration of the ERB syntax, refer to [this comprehensive guide](https://www.puppet.com/docs/puppet/latest/lang_template_erb.html).
372
-
373
- ### ERB Syntax at a Glance
374
-
375
- Ruby code embedding with ERB offers two main patterns:
376
-
377
- - `<% ruby code %>` for code execution only.
378
- - `<%= ruby code %>` for code execution with output.
379
-
380
- Both patterns support multi-line Ruby code; you're not constrained to a single line.
381
-
382
- Using the first pattern, `<% ... %>`, you define Ruby objects within the binding — setting variable values, declaring methods, and so forth — without generating any output to the prompt text. After execution the ERB block is removed from the prompt text.
383
-
384
- The second pattern, `<%= ... %>`, includes an equals sign '=' that signals the output of the ERB block to be inserted into the prompt text. Like the first, the ERB block is removed but its output remains as part of the prompt text.
385
-
386
- ```ruby
387
- <$ name = "Ruby" %>
388
- Say hello to <%= name %> in three different languages.
389
- ```
390
-
391
- In the first line the Ruby variable `name` was added to the binding as a Sring type with the value of "Ruby" so that in the second line the value of that variable could be accessed as used within the prompt text.
392
-
393
-
394
- ### Conditional Logic
395
-
396
- ERB empowers you to create conditional prompts based on the available binding.
397
-
398
- ```ruby
399
- <% "Ruby" == name %>
400
- Review these files: $(ls -1 *.rb) for duplicate code blocks.
401
- M% else %>
402
- Review the grammar and spelling in these files $(ls -1 *.md)
403
- <% end %>
404
- ```
405
-
406
- ### Accessing Current Data
407
-
408
- By nature, large language models (LLMs) have a historical cut-off for training data. Only recently, generative AI tools granting real-time data access have been introduced. With ERB, you can complement LLM data by integrating up-to-date information directly into your prompts.
409
-
410
- ```ruby
411
- <%
412
- require 'alphavantagerb'
413
- stock_info = Alphavantage::Stock.new(
414
- symbol: 'AAPL',
415
- key: "your api key").quote
416
- current_price = stock_info.price
417
- change = stock_info.change
418
- change_percent = stock_info.change_percent
419
- %>
420
-
421
- The latest stock information for Apple Inc. (AAPL) is as follows:
422
- - Current Price: <%= current_price %>
423
- - Change: <%= change %>
424
- - Change (%): <%= change_percent %>
425
-
426
- Generate a brief analysis of the stock performance based on this information.
427
- ```
428
-
429
- This script illustrates how the ERB binding can extend to include external Ruby objects, though external libraries must be explicitly required within the ERB's binding.
430
-
431
- ## Summary of AIA Command-Line Tool
432
-
433
- The AIA tool is a command-line interface designed to enable users to interact with an AI assistant, specifically with an AI model backend. It allows users to submit prompts, load context for AI processing, and receive responses from the AI model. The CLI tool is versatile and offers a range of options and configurations.
434
-
435
- Key features of the AIA tool based on the user manual:
436
-
437
- - **Command Syntax**: `aia [options]* PROMPT_ID [CONTEXT_FILE]* [-- EXTERNAL_OPTIONS+]`
438
- - **Core Function**: Sends prompts to and receives responses from an AI backend.
439
- - **Prompt ID**: A required argument that identifies the prompt to be processed.
440
- - **Context Files**: Optional files that provide additional context for prompt processing.
441
- - **External Options**: Additional backend-specific options can be passed after " -- ".
442
-
443
- **Options Available**:
444
- - Chat sessions (`--chat`) and turning off standard output for backend-only interaction.
445
- - Shell completion scripts for various shell types (`--completion`).
446
- - Configuration dumping (`--dump`).
447
- - Environment variable substitution (`--shell`) and embedded Ruby execution (`--erb`).
448
- - Model name specification (`--model`), and text-to-speech output (`--speak`).
449
- - Terse response directive (`--terse`), checking for updates (`--version`), and backend specification (`-b`).
450
- - Config files loading (`-c`), debugging mode activation (`-d`), prompt file editing (`-e`).
451
- - Fuzzy matching for prompts search (`-f`), help display (`-h`), logging (`-l`).
452
- - Markdown formatting (`-m`), output file specification (`-o`), and prompt directory setting (`-p`).
453
- - Role ID to configure the AI's approach (`-r`), verbose output (`-v`).
454
-
455
- **Configuration Hierarchy**:
456
- - Environment variables prefixed with "AIA_" can alter default settings.
457
- - Command-line options have precedence over environment variables.
458
- - Config file settings and prompt directives within files can override other configurations.
459
-
460
- **OpenAI Account Requirement**:
461
- - Users must have an OpenAI access token specified through environment variables (`OPENAI_ACCESS_TOKEN` or `OPENAI_API_KEY`).
462
-
463
- **Usage and Integration**:
464
- - The tool is designed to be flexible, with the ability to customize output behavior and integrate auto-completion scripts into the shell environment.
465
- - Configuration formats like YAML and TOML can be outputted using `--dump`.
466
-
467
- **Prompt Directives**:
468
- - Lines beginning with "//" in a prompt text file serve as directives, influencing behavior and configurations.
469
-
470
- **Additional Information and Third-Party Tools**:
471
- - The manual references additional documentation for OpenAI token access, as well as third-party CLI tools like `mods` and `sgpt` that integrate with AI services.
472
-
473
- Through this tool, users have the ability to create highly customized interactions with an AI backend, using a command-line environment for efficient and programmable access to AI processing capabilities.
474
-
data/lib/aia/clause.rb DELETED
@@ -1,7 +0,0 @@
1
- # aia/lib/aia/clause.rb
2
-
3
- module AIA
4
- module Clause
5
- Terse = 'Be terse in your response.'
6
- end
7
- end