aia 0.4.2 → 0.4.3

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: 24e36e9066b83229df951d172cfb3fd7185cadb433fd992ab37fede8d45b8ea5
4
- data.tar.gz: f7ce893975dfb29dd69d1ec0922f8ea30987f88d1d3dd69f0ca877218c6c54fc
3
+ metadata.gz: 3e8cad3b88bdc76e72dce9b7fa202923ab655f2da811039bf18df52c5fe714ae
4
+ data.tar.gz: 57ae0a1dd04c0fbd237ba8daa3210ae273a8db21e0efe5c154ffbe72c9afd0e5
5
5
  SHA512:
6
- metadata.gz: 0172e7c82b9e346d176df7691e5eb422515e25f4f7ed243cb92cd38419a4e8a18a1df9f5500ac0606c6bb30d48e88662237877aee4667aedf9cd02973a190268
7
- data.tar.gz: c826c22f5b1789ffeeca7982860764527350d3b352cb428a4b1cc6ccc63025fa1c4347ed098477d8d6a0f2f63dfe8fc8187eb9570096698487bf69fe6f8903c0
6
+ metadata.gz: 0cc90b667bd99aae7688231286c58ee3cc7a3ad4a1b4202c531a71113911d24c084f6ccce5d154d57e0059a2a0b3d6d1706f3ee9a5fae5bf229b2604d1982d4d
7
+ data.tar.gz: 18dafdbfdeb257a2597f53070feebcb05f409f101b06ff17fdbe81cc813ebbf335833a0eace414638e437425ca47298b26655768890737cb065e3b15cfbf405e
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 4
4
- :patch: 2
4
+ :patch: 3
5
5
  :special: ''
6
6
  :metadata: ''
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  ## [Unreleased]
2
+ ## [0.4.3] 2023-12-31
3
+ - added --env to process embedded system environment variables and shell commands within a prompt.
4
+ - added --erb to process Embedded RuBy within a prompt because have embedded shell commands will only get you in a trouble. Having ERB will really get you into trouble. Remember the simple prompt is usually the best prompt.
5
+
2
6
  ## [0.4.2] 2023-12-31
3
7
  - added the --role CLI option to pre-pend a "role" prompt to the front of a primary prompt.
4
8
 
data/README.md CHANGED
@@ -6,8 +6,9 @@ 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.4.2 = Added a role option to be prepended to a primary prompt.
10
- v0.4.1 - Added a chat mode. Prompt directives are now supported.
9
+ v0.4.3 - Added the --env and --erb options. Prompts can now be dynamic.
10
+ v0.4.2 - Added a --role option to be prepended to a primary prompt.
11
+ v0.4.1 - Added --chat and --speak options. Prompt directives are now supported.
11
12
 
12
13
  <!-- Tocer[start]: Auto-generated, don't remove. -->
13
14
 
@@ -16,6 +17,8 @@ v0.4.1 - Added a chat mode. Prompt directives are now supported.
16
17
  - [Installation](#installation)
17
18
  - [Usage](#usage)
18
19
  - [System Environment Variables (envar)](#system-environment-variables-envar)
20
+ - [System Environment Variables inside of a Prompt](#system-environment-variables-inside-of-a-prompt)
21
+ - [*E*mbedded *R*u*B*y (ERB)](#embedded-ruby-erb)
19
22
  - [Prompt Directives](#prompt-directives)
20
23
  - [All About ROLES](#all-about-roles)
21
24
  - [Other Ways to Insert Roles into Prompts](#other-ways-to-insert-roles-into-prompts)
@@ -94,6 +97,24 @@ OPTIONS
94
97
 
95
98
  --dump FORMAT
96
99
 
100
+ -e, --edit
101
+ Invokes an editor on the prompt file. You can make changes to the prompt file,
102
+ save it and the newly saved prompt will be processed by the backend.
103
+
104
+ --env This option tells aia to replace references to system environment variables in
105
+ the prompt with the value of the envar. envars are like $HOME and ${HOME} in
106
+ this example their occurance will be replaced by the value of ENV[‘HOME’].
107
+ Also the dynamic shell command in the pattern $(shell command) will be executed
108
+ and its output replaces its pattern. It does not matter if your shell uses
109
+ different patters than BASH since the replacement is being done within a Ruby
110
+ context.
111
+
112
+ --erb If dynamic prompt content using $(...) wasn’t enough here is ERB. Embedded
113
+ RUby. <%= ruby code %> within a prompt will have its ruby code executed and
114
+ the results of that execution will be inserted into the prompt. I’m sure we
115
+ will find a way to truly misuse this capability. Remember, some say that the
116
+ simple prompt is the best prompt.
117
+
97
118
  --model NAME
98
119
  Name of the LLM model to use - default is gpt-4-1106-preview
99
120
 
@@ -253,6 +274,20 @@ See the `@options` hash in the `cli.rb` file for a complete list. There are som
253
274
 
254
275
  In addition to these config items for `aia` the optional command line parameters for the backend prompt processing utilities (mods and sgpt) can also be set using envars with the "AIA_" prefix. For example "export AIA_TOPP=1.0" will set the "--topp 1.0" command line option for the `mods` utility when its used as the backend processor.
255
276
 
277
+ ### System Environment Variables inside of a Prompt
278
+
279
+ The cpmmand line option "--env" instructs `aia` to replace any system environment variable references in the prompt text with the value of the system envornment variable. So patterns like $HOME and ${HOME} in the prompt will be replaced with the value of ENV['HOME'].
280
+
281
+ As an added bonus, dynamic content can be inserted into the prompt using the pattern $(shell command) where the output of the shell command will replace the $(...) pattern.
282
+
283
+ That's enough power to get anyone into deep trouble. Wait there's more coming. Do you want a full programming language in your prompt? Feel like running the prompt through ERB before sending it to the backend? I've been thinking about it. Should be a simple thing to do. Yes it was.
284
+
285
+ ## *E*mbedded *R*u*B*y (ERB)
286
+
287
+ The --erb options now submits the prompt text through the ERB parser for execution before environment variable, keyword and dynamic shell replace take place. With this much dynamic prompt manipulation we should really be able to get into trouble!
288
+
289
+ If you are not a Rubyist and do not know about ERB see this [webpage](https://ruby-doc.org/stdlib-3.0.0/libdoc/erb/rdoc/ERB.html) for some information about the power of embedded Ruby.
290
+
256
291
  ## Prompt Directives
257
292
 
258
293
  Downstream processing directives were added to the `prompt_manager` gem at version 0.4.1. These directives are lines in the prompt text file that begin with "//"
data/lib/aia/cli.rb CHANGED
@@ -126,6 +126,8 @@ class AIA::Cli
126
126
  completion: [nil, "--completion"],
127
127
  #
128
128
  edit?: [false, "-e --edit"],
129
+ env?: [false, "--env"],
130
+ erb?: [false, "--erb"],
129
131
  debug?: [false, "-d --debug"],
130
132
  verbose?: [false, "-v --verbose"],
131
133
  version?: [false, "--version"],
data/lib/aia/prompt.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # lib/aia/prompt.rb
2
2
 
3
3
  require 'reline'
4
+ require 'erb'
4
5
 
5
6
  class AIA::Prompt
6
7
  #
@@ -36,7 +37,11 @@ class AIA::Prompt
36
37
  @prompt.text.prepend @role.text
37
38
  end
38
39
 
39
- process_prompt if build
40
+ if build
41
+ @prompt.text = render_erb(@prompt.text) if AIA.config.erb?
42
+ @prompt.text = replace_env(@prompt.text) if AIA.config.env?
43
+ process_prompt
44
+ end
40
45
  end
41
46
 
42
47
 
@@ -77,6 +82,25 @@ class AIA::Prompt
77
82
  end
78
83
 
79
84
 
85
+ # inserts environmant variables and dynamic content into a prompt
86
+ # replaces patterns like $HOME and ${HOME} with the value of ENV['HOME']
87
+ # replaces patterns like $(shell command) with the output of the shell command
88
+ #
89
+ def replace_env(a_string)
90
+ a_string.gsub(/\$(\w+|\{\w+\})/) do |match|
91
+ ENV[match.tr('$', '').tr('{}', '')]
92
+ end.gsub(/\$\((.*?)\)/) do |match|
93
+ `#{match[2..-2]}`.chomp
94
+ end
95
+ end
96
+
97
+
98
+ # You are just asking for trouble!
99
+ def render_erb(a_string)
100
+ ERB.new(a_string).result(binding)
101
+ end
102
+
103
+
80
104
  def replace_keywords
81
105
  puts
82
106
  puts "ID: #{@prompt.id}"
data/man/aia.1 CHANGED
@@ -29,6 +29,15 @@ begin a chat session with the backend after the initial prompt response; will s
29
29
  .TP
30
30
  \fB\-\-dump\fR \fIFORMAT\fP
31
31
  .TP
32
+ \fB\-e\fR, \fB\-\-edit\fR
33
+ Invokes an editor on the prompt file\. You can make changes to the prompt file, save it and the newly saved prompt will be processed by the backend\.
34
+ .TP
35
+ \fB\-\-env\fR
36
+ This option tells \fBaia\fR to replace references to system environment variables in the prompt with the value of the envar\. envars are like \[Do]HOME and \[Do]\[lC]HOME\[rC] in this example their occurance will be replaced by the value of ENV\[lB]\[oq]HOME\[cq]\[rB]\. Also the dynamic shell command in the pattern \[Do](shell command) will be executed and its output replaces its pattern\. It does not matter if your shell uses different patters than BASH since the replacement is being done within a Ruby context\.
37
+ .TP
38
+ \fB\-\-erb\fR
39
+ If dynamic prompt content using \[Do](\.\.\.) wasn\[cq]t enough here is ERB\. Embedded RUby\. <%\[eq] ruby code %> within a prompt will have its ruby code executed and the results of that execution will be inserted into the prompt\. I\[cq]m sure we will find a way to truly misuse this capability\. Remember, some say that the simple prompt is the best prompt\.
40
+ .TP
32
41
  \fB\-\-model\fR \fINAME\fP
33
42
  Name of the LLM model to use \- default is gpt\-4\-1106\-preview
34
43
  .TP
data/man/aia.1.md CHANGED
@@ -34,6 +34,15 @@ The aia command-line tool is an interface for interacting with an AI model backe
34
34
  `--dump` *FORMAT*
35
35
  : Dump a Config File in [yaml | toml] to STDOUT - default is nil
36
36
 
37
+ `-e`, `--edit`
38
+ : Invokes an editor on the prompt file. You can make changes to the prompt file, save it and the newly saved prompt will be processed by the backend.
39
+
40
+ `--env`
41
+ : This option tells `aia` to replace references to system environment variables in the prompt with the value of the envar. envars are like $HOME and ${HOME} in this example their occurance will be replaced by the value of ENV['HOME']. Also the dynamic shell command in the pattern $(shell command) will be executed and its output replaces its pattern. It does not matter if your shell uses different patters than BASH since the replacement is being done within a Ruby context.
42
+
43
+ `--erb`
44
+ : If dynamic prompt content using $(...) wasn't enough here is ERB. Embedded RUby. <%= ruby code %> within a prompt will have its ruby code executed and the results of that execution will be inserted into the prompt. I'm sure we will find a way to truly misuse this capability. Remember, some say that the simple prompt is the best prompt.
45
+
37
46
  `--model` *NAME*
38
47
  : Name of the LLM model to use - default is gpt-4-1106-preview
39
48
 
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.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-31 00:00:00.000000000 Z
11
+ date: 2024-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie