aia 0.3.3 → 0.3.19

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: 0d2d934f517983c9854654eeb01d9b5ca6a08c92cb531b315a8b223e6e2ffd23
4
- data.tar.gz: cd5ac0f18c2a290205c717c2d9e1e2e43ffe0a51f5aac400d3a1fce6137db4c5
3
+ metadata.gz: 505546a036010eb8b0360f7fbfbb4c6494c311e98969c8095fa091882815aac2
4
+ data.tar.gz: 6f9323e50879c3b51a5ead99c29b1b41fc377dc1957283edb13e03bb30c866db
5
5
  SHA512:
6
- metadata.gz: 04c859d26173c65d577cd9a49c4333f5c104d69b37205523a1f2249f284de38e1af06ec1870cea9774858e9688eb67639135fe2500b3550693f33ba621eada79
7
- data.tar.gz: 808e69fc41eaba3396ebfb7157063e43709034a5009fcc06fb01c0055a2b371ef128962bea32a2cae8efc0e8ee0b8d8aeb5f4f180e5e4754176bfc70fecf17a0
6
+ metadata.gz: 23926f77a010a023fd1fbbde152f83cfacd75f003bb2e060d4e2b4ca0cd7aecac6631b0520c5e3c6d56cbde31914f158f520f15bfa239a1a72bf682c5ea79032
7
+ data.tar.gz: 9d76ab35f70a13a4320d9fb4ee5f3fd47e4039c95e99fc02ce858977e179d1891d44fb08cf7cfc17975e6828dbe28d01d9d778d949c371e898e847e7fa865020
data/.semver ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 3
4
+ :patch: 19
5
+ :special: ''
6
+ :metadata: ''
data/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
1
  ## [Unreleased]
2
+ ## [0.3.19] 2023-12-26
3
+ - major code refactoring.
4
+ - supports config files \*.yml, \*.yaml and \*.toml
5
+ - usage implemented as a man page. --help will display the man page/
6
+ - added "--dump <yml|yaml|toml>" to send current configuration to STDOUT
7
+ - added "--completion <bash|fish|zsh>" to send a a completion function for the indicated shell to STDOUT
8
+ - added system environment variable (envar) over-rides of default config values uppercase environment variables prefixed with "AIA_" + config item name for example AIA_PROMPTS_DIR and AIA_MODEL. All config items can be over-ridden by their cooresponding envars.
9
+ - config value hierarchy is:
10
+ 1. values from config file over-rides ...
11
+ 2. command line values over-rides ...
12
+ 3. envar values over-rides ...
13
+ 4. default values
2
14
 
3
15
  ## [0.3.0] = 2023-11-23
4
16
 
data/README.md CHANGED
@@ -6,8 +6,7 @@ Uses the gem "prompt_manager" to manage the prompts sent to the `mods` command-l
6
6
 
7
7
  **Most Recent Change**
8
8
 
9
- v0.3.0 - Matching version to [prompt_manager](https://github.com/prompt_manager) This version allows for the user of history in the entery of values to prompt keywords. KW_HISTORY_MAX is set at 5. Changed CLI enteraction to use historical selection and editing of prior keyword values.
10
-
9
+ v0.3.19 - Major code refactoring. Now supports conf giles in YAML or TOML format. Supports system environment variable (envar) over-rides of default config values using envar's with keys that have the prefix "AIA_" followed by a config item name in all upper case.
11
10
 
12
11
  <!-- Tocer[start]: Auto-generated, don't remove. -->
13
12
 
@@ -15,8 +14,9 @@ v0.3.0 - Matching version to [prompt_manager](https://github.com/prompt_manager)
15
14
 
16
15
  - [Installation](#installation)
17
16
  - [Usage](#usage)
18
- - [System Environment Variables (envars)](#system-environment-variables-envars)
17
+ - [System Environment Variables (envar)](#system-environment-variables-envar)
19
18
  - [External CLI Tools Used](#external-cli-tools-used)
19
+ - [Shell Completion](#shell-completion)
20
20
  - [Development](#development)
21
21
  - [Contributing](#contributing)
22
22
  - [License](#license)
@@ -47,83 +47,190 @@ TODO: don't forget to mention have access token (API keys) setup as envars for t
47
47
 
48
48
  ## Usage
49
49
 
50
+ 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.
51
+
50
52
  ```text
51
53
  $ aia --help
52
54
 
53
- aia v0.0.5
55
+ aia(1) User Manuals aia(1)
54
56
 
55
- Usage: aia [options] prompt_id [context_file]* [-- external_options+]
57
+ NAME
58
+ aia - command-line interface for an AI assistant
56
59
 
57
- Options
58
- -------
60
+ SYNOPSIS
61
+ aia [options]* PROMPT_ID [CONTEXT_FILE]* [-- EXTERNAL_OPTIONS+]
59
62
 
60
- Edit the Prompt File -e --edit
61
- default: false
63
+ DESCRIPTION
64
+ The aia command-line tool is an interface for interacting with an AI
65
+ model backend, providing a simple way to send prompts and receive
66
+ responses. The CLI supports various options to customize the
67
+ interaction, load a configuration file, edit prompts, set debugging
68
+ levels, and more.
62
69
 
63
- Turn On Debugging -d --debug
64
- default: false
70
+ ARGUMENTS
71
+ PROMPT_ID
72
+ This is a required argument.
65
73
 
66
- Be Verbose -v --verbose
67
- default: false
74
+ CONTEXT_FILES
75
+ This is an optional argument. One or more files can be added to
76
+ the prompt as context for the backend gen-AI tool to process.
68
77
 
69
- Print Version --version
70
- default: false
78
+ EXTERNAL_OPTIONS
79
+ External options are optional. Anything that follow “ -- “ will
80
+ be sent to the backend gen-AI tool. For example “-- -C -m
81
+ gpt4-128k” will send the options “-C -m gpt4-128k” to the
82
+ backend gen-AI tool. aia will not validate these external
83
+ options before sending them to the backend gen-AI tool.
71
84
 
72
- Show Usage -h --help
73
- default: false
85
+ OPTIONS
86
+ -c, --config PATH_TO_CONFIG_FILE
87
+ Load Config File - default: nil
74
88
 
75
- Use Fuzzy Matching --fuzzy
76
- default: false
89
+ --dump FORMAT
77
90
 
78
- Out FILENAME -o --output --no-output
79
- default: ./temp.md
91
+ -e, --edit
92
+ Edit the Prompt File - default: false
80
93
 
81
- Log FILEPATH -l --log --no-log
82
- default: $HOME/.prompts/_prompts.log
94
+ -d, --debug
95
+ Turn On Debugging - default: false
83
96
 
84
- Format with Markdown -m --markdown --no-markdown --md --no-md
85
- default: true
86
- ```
97
+ -v, --verbose
98
+ Be Verbose - default: false
87
99
 
88
- Turn on `verbose` with `help` to see more usage information that includes system environment variables and external CLI tools that are used.
100
+ --version
101
+ Print Version - default: false
89
102
 
90
- ```text
91
- $ aia --help --verbose
92
- ```
103
+ -h, --help
104
+ Show Usage - default: false
93
105
 
94
- ## System Environment Variables (envars)
106
+ -s, --search TERM
107
+ Search for prompts contain TERM - default: nil
95
108
 
96
- From the verbose help text ...
109
+ -f, --fuzzy`
110
+ Use Fuzzy Matching when searching for a prompt - default: false
97
111
 
98
- ```text
112
+ --completion SHELL_NAME
113
+
114
+ -o, --[no]-output PATH_TO_OUTPUT_FILE
115
+ Out FILENAME - default: ./temp.md
116
+
117
+ -l, --[no]-log PATH_TO_LOG_FILE
118
+ Log FILEPATH - default: $HOME/.prompts/prompts.log
119
+
120
+ -m, --[no]-markdown
121
+ Format with Markdown - default: true
122
+
123
+ --model NAME
124
+ Name of the LLM model to use - default: gpt-4-1106-preview
125
+
126
+ -p, --prompts PATH_TO_DIRECTORY
127
+ Directory containing the prompt files - default: ~/.prompts
128
+
129
+ -b, --[no]-backend LLM TOOL
130
+ Specify the backend prompt resolver - default: :mods
131
+
132
+ ENVIRONMENT
133
+ The aia CLI uses the following environment variables:
134
+
135
+ • AIA_PROMPTS_DIR: Path to the directory containing prompts
136
+ files - default: $HOME/.prompts_dir
137
+
138
+ • AIA_BACKEND: The AI command-line program used - default: mods
139
+
140
+ • EDITOR: The text editor used by the edit option - default:
141
+ edit
99
142
 
100
- System Environment Variables Used
101
- ---------------------------------
143
+ AIA_MODEL: The AI model specification - default:
144
+ gpt-4-1106-preview
102
145
 
103
- The OUTPUT and PROMPT_LOG envars can be overridden
104
- by cooresponding options on the command line.
146
+ • AIA_OUTPUT: The default filename for output - default:
147
+ ./temp.md
105
148
 
106
- Name Default Value
107
- -------------- -------------------------
108
- PROMPTS_DIR $HOME/.prompts_dir
109
- AI_CLI_PROGRAM mods
110
- EDITOR edit
111
- MODS_MODEL gpt-4-1106-preview
112
- OUTPUT ./temp.md
113
- PROMPT_LOG $PROMPTS_DIR/_prompts.log
149
+ AIA_PROMPT_LOG: The default filepath for the prompts log -
150
+ default: $HOME/.prompts/_prompts.log
114
151
 
115
- These two are required for access the OpenAI
116
- services. The have the same value but different
117
- programs use different envar names.
152
+ Additionally, the program requires an OpenAI access key, which can be
153
+ specified using one of the following environment variables:
118
154
 
119
- To get an OpenAI access key/token (same thing)
120
- you must first create an account at OpenAI.
121
- Here is the link: https://platform.openai.com/docs/overview
155
+ OPENAI_ACCESS_TOKEN
156
+
157
+ OPENAI_API_KEY
158
+
159
+ Currently there is not specific standard for name of the OpenAI key.
160
+ Some programs use one name, while others use a different name. Both of
161
+ the envars listed above mean the same thing. If you use more than one
162
+ tool to access OpenAI resources, you may have to set several envars to
163
+ the same key value.
164
+
165
+ To acquire an OpenAI access key, first create an account on the OpenAI
166
+ platform, where further documentation is available.
167
+
168
+ USAGE NOTES
169
+ aia is designed for flexibility, allowing users to pass prompt ids and
170
+ context files as arguments. Some options change the behavior of the
171
+ output, such as --output for specifying a file or --no-output for
172
+ disabling file output in favor of standard output.
173
+
174
+ The --completion option displays a script that enables prompt ID
175
+ auto-completion for bash, zsh, or fish shells. It’s crucial to
176
+ integrate the script into the shell’s runtime to take effect.
177
+
178
+ SEE ALSO
179
+
180
+ • OpenAI Platform Documentation
181
+ <https://platform.openai.com/docs/overview>
182
+ for more information on obtaining access tokens
183
+ <https://platform.openai.com/account/api-keys>
184
+ and working with OpenAI models.
185
+
186
+ • mods <https://github.com/charmbracelet/mods>
187
+ for more information on mods - AI for the command line, built
188
+ for pipelines. LLM based AI is really good at interpreting
189
+ the output of commands and returning the results in CLI
190
+ friendly text formats like Markdown. Mods is a simple tool
191
+ that makes it super easy to use AI on the command line and in
192
+ your pipelines. Mods works with OpenAI
193
+ <https://platform.openai.com/account/api-keys>
194
+ and LocalAI <https://github.com/go-skynet/LocalAI>
195
+
196
+ • sgpt <https://github.com/tbckr/sgpt>
197
+ (aka shell-gpt) is a powerful command-line interface (CLI)
198
+ tool designed for seamless interaction with OpenAI models
199
+ directly from your terminal. Effortlessly run queries,
200
+ generate shell commands or code, create images from text, and
201
+ more, using simple commands. Streamline your workflow and
202
+ enhance productivity with this powerful and user-friendly CLI
203
+ tool.
204
+
205
+ AUTHOR
206
+ Dewayne VanHoozer <dvanhoozer@gmail.com>
207
+
208
+ AIA 2024-01-01 aia(1)
122
209
 
123
- OPENAI_ACCESS_TOKEN
124
- OPENAI_API_KEY
125
210
  ```
126
211
 
212
+ ## System Environment Variables (envar)
213
+
214
+ The `aia` configuration defaults can be over-ridden by envars with the prefix "AIA_" followed by the config item name also in uppercase.
215
+
216
+ | Config Item | Default Value | envar key |
217
+ | ------------- | ------------- | --------- |
218
+ | backend | mods | AIA_BACKEND |
219
+ | config_file | nil | AIA_CONFIG_FILE |
220
+ | debug | false | AIA_DEBUG |
221
+ | edit | false | AIA_EDIT |
222
+ | extra | '' | AIA_EXTRA |
223
+ | fuzzy | false | AIA_FUZZY |
224
+ | log_file | ~/.prompts/_prompts.log | AIA_LOG_FILE |
225
+ | markdown | true | AIA_MARKDOWN |
226
+ | model | gpt-4-1106-preview | AIA_MODEL |
227
+ | output_file | temp.md | AIA_OUTPUT_FILE |
228
+ | prompts_dir | ~/.prompts | AIA_PROMPTS_DIR |
229
+ | VERBOSE | FALSE | AIA_VERBOSE |
230
+
231
+
232
+ See the `@options` hash in the `cli.rb` file for a complete list. There are some config items that do not necessarily make sense for use as an envar over-ride. For example if you set `export AIA_DUMP=yaml` then `aia` would dump a config file in HAML format and exit every time it is ran until you finally did `unset AIA_DUMP`
233
+
127
234
  ## External CLI Tools Used
128
235
 
129
236
  From the verbose help text ...
@@ -156,10 +263,13 @@ export EDITOR="subl -w"
156
263
 
157
264
  ## Shell Completion
158
265
 
159
- One of the executables with this gem is `aia_completion.sh` which contains a completion script for hte `aia` such that you specify the first few characters of a prompt ID on the command line and the shell will complete the rest of the ID for you. It works with the `bash` shell but do not know whether it works with the other shells.
266
+ You can setup a completion function in your shell that will complete on the prompt_id saved in your `prompts_dir` - functions for `bash`, `fish` and `zsh` are available. To get a copy of these functions do this:
267
+
268
+ > `aia --completion bash`
160
269
 
161
- To set the completion you can execute aia_completion.sh` in your `.bashrc` however, the PROMPTS_DIR environment variable must be set in order for prompt ID to work correctly.
270
+ If you're not a fan of "born again" replace `bash` with one of the others.
162
271
 
272
+ Copy the function to a place where it can be installed in your shell's instance. This might be a `.profile` or `.bashrc` file, etc.
163
273
 
164
274
  ## Development
165
275
 
data/Rakefile CHANGED
@@ -8,6 +8,8 @@ end
8
8
 
9
9
  Tocer::Rake::Register.call
10
10
 
11
+ require 'kramdown/man/task'
12
+ Kramdown::Man::Task.new
11
13
 
12
14
  require "bundler/gem_tasks"
13
15
  require "rake/testtask"
data/justfile ADDED
@@ -0,0 +1,167 @@
1
+ # aia/main.just
2
+ #
3
+ # Support man pages with ...
4
+ # gem install kramdown-man
5
+ #
6
+
7
+ RR := env_var('RR')
8
+
9
+ # with ~/.justfile
10
+
11
+ # >>> /Users/dewayne/.justfile
12
+ # ~/.justfile
13
+ # brew install just
14
+ # gem install justprep OR brew install justprep for the Crystal version
15
+ # alias jj='justprep && just'
16
+ #
17
+ # See: https://cheatography.com/linux-china/cheat-sheets/justfile/
18
+ #
19
+
20
+ # high-level just directives
21
+
22
+ set fallback # search up for recipe name if not found locally.
23
+
24
+ set positional-arguments := true
25
+ set allow-duplicate-recipes := true
26
+ set dotenv-load := false
27
+
28
+ # my common variables
29
+
30
+ pwd := env_var('PWD')
31
+
32
+ me := justfile()
33
+ home := env_var('HOME')
34
+ backup_dir := env_var('JUST_BACKUP_DIR')
35
+ backup_file := trim_start_match(me, home)
36
+ my_backup := backup_dir + backup_file
37
+ project := "`basename $RR`"
38
+
39
+
40
+ # List available recipes
41
+ @list:
42
+ echo
43
+ echo "Available Recipes at"
44
+ echo "$PWD"
45
+ echo "are:"
46
+ echo
47
+ just -l --list-prefix 'jj ' --list-heading ''
48
+ echo
49
+ echo "jj <module_name> to see sub-tasks"
50
+ echo
51
+
52
+
53
+ # Show help/usage for "just" command
54
+ @help: list
55
+ just --help
56
+
57
+
58
+ # Backup .envrc & *.just files
59
+ @backup_support_files: _backup_all_just_files _backup_all_envrc_files
60
+
61
+
62
+ # Backup all changed just files to $JUST_BACKUP_DIR
63
+ @_backup_all_just_files:
64
+ backup_just.rb
65
+
66
+
67
+ # backup all changed envrc files to ENVRC_BACKUP_DIR
68
+ @_backup_all_envrc_files:
69
+ backup_envrc.rb
70
+
71
+
72
+ #################################################
73
+ ## Private recipes
74
+
75
+ # Show private recipes
76
+ @show_private: # Show private recipes
77
+ grep -B 1 "^[@]_" {{justfile()}}
78
+
79
+
80
+ # Show the differences between this justfile and is last backup
81
+ @_just_diff_my_backup:
82
+ # echo "me -=> {{me}}"
83
+ # echo "home -=> {{home}}"
84
+ # echo "backup_file -=> {{backup_file}}"
85
+ # echo "my_backup -=> {{my_backup}}"
86
+
87
+ @diff {{me}} {{my_backup}}
88
+
89
+
90
+ # Replace current justfile with most recent backup
91
+ @_just_restore_me_from_backup:
92
+ echo
93
+ echo "Do this because I will not ..."
94
+ echo
95
+ echo "cp -f {{my_backup}} {{me}}"
96
+ echo
97
+
98
+
99
+ # Edit the $JUSTPREP_FILENAME_IN file
100
+ @_just_edit_me:
101
+ $EDITOR {{me}}
102
+ # <<< /Users/dewayne/.justfile
103
+
104
+ # FIXME: justprep module process still has an issue with ~ and $HOME
105
+ # FIXME: justprep does not like more than one space between module name and path.
106
+
107
+ module_repo := "/Users/dewayne/sandbox/git_repos/repo.just"
108
+ module_gem := "/Users/dewayne/sandbox/git_repos/gem.just"
109
+ module_version := "/Users/dewayne/just_modules/version.just"
110
+
111
+
112
+ # Preview man page
113
+ preview_man_page:
114
+ kramdown-man {{RR}}/man/aia.1.md
115
+
116
+
117
+ # View man page
118
+ view_man_page: create_man_page
119
+ man {{RR}}/man/aia.1
120
+
121
+
122
+ # Create man page
123
+ create_man_page:
124
+ rake man
125
+
126
+ ##########################################
127
+
128
+ # Tag the current commit, push it, then bump the version
129
+ tag_push_and_bump: tag push bump
130
+
131
+
132
+ # Create a git tag for the current version
133
+ tag:
134
+ git tag $(semver)
135
+
136
+ # Push the git current working directory and all tags
137
+ push:
138
+ git push
139
+ git push origin --tags
140
+
141
+
142
+ alias inc := bump
143
+
144
+ # Increament version's level: major.minor.patch
145
+ @bump level='patch':
146
+ semver increment {{level}}
147
+ echo "Now working on: $(semver)"
148
+ git add {{RR}}/.semver
149
+
150
+
151
+
152
+ # Module repo
153
+ @repo what='' args='':
154
+ just -d . -f {{module_repo}} {{what}} {{args}}
155
+
156
+
157
+
158
+ # Module gem
159
+ @gem what='' args='':
160
+ just -d . -f {{module_gem}} {{what}} {{args}}
161
+
162
+
163
+
164
+ # Module version
165
+ @version what='' args='':
166
+ just -d . -f {{module_version}} {{what}} {{args}}
167
+