prompt_manager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.envrc +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +12 -0
- data/lib/aip.rb +402 -0
- data/lib/prompt_manager/version.rb +5 -0
- data/lib/prompt_manager.rb +8 -0
- data/lib/temp.md +57 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0e3ba20b4c51adf033fc6124346bbb568be751fb3820000773dd51b496c6bc64
|
4
|
+
data.tar.gz: 950e2dd314ac1eec127c6ea3887ddd727fc55b6b5bb5735cac32c175de4135e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1dc004fae9eba3c212014102a89897a0a7301e3157efd6b662e75766e387b057110c58556f918c97dc729edf4968963245d86736a1b8e80795fc7258620eacc2
|
7
|
+
data.tar.gz: ce46bbfa158650fabfa9741f3b3b9ab42e4acf6022d6dedbd62b377f9659dab72d9ed241ba575c489b6fabab6f550af03a5afa4fc9074303b866c96984f3d769
|
data/.envrc
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# PromptManager
|
2
|
+
|
3
|
+
**Under Development**
|
4
|
+
|
5
|
+
Extracting the prompt management functionality fro the aip.rb file into a new gem that will provide a generic management service for other programs.
|
6
|
+
|
7
|
+
## AIP.RB Legacy Summary of Capability
|
8
|
+
|
9
|
+
This is just some source material for later documentation.
|
10
|
+
|
11
|
+
### README for aip.rb
|
12
|
+
|
13
|
+
#### Overview
|
14
|
+
|
15
|
+
The `aip.rb` Ruby script is a command-line interface (CLI) tool designed to leverage generative AI with saved parameterized prompts. It integrates with the `mods` command-line tool that uses a GPT-based model to generate responses based on user-provided prompts. The script offers an array of features that make interacting with AI models more convenient and streamlined.
|
16
|
+
|
17
|
+
#### Features
|
18
|
+
|
19
|
+
- **Prompt Management**
|
20
|
+
- Users can select prompts from a saved collection with the help of command-line searching and filtering.
|
21
|
+
- Prompts can be edited by the user to better fit their specific context or requirement.
|
22
|
+
- Support for reading input from files to provide context for AI generation is included.
|
23
|
+
|
24
|
+
- **AI Integration**
|
25
|
+
- The script interacts with `mods`, a generative AI utilizing GPT-based models, to produce outputs from the prompts.
|
26
|
+
|
27
|
+
- **Output Handling**
|
28
|
+
- Generated content is saved to a specified file for record-keeping and further use.
|
29
|
+
|
30
|
+
- **Activity Logging**
|
31
|
+
- All actions, including prompt usage and AI output, are logged with timestamps for review and auditing purposes.
|
32
|
+
|
33
|
+
#### Dependencies
|
34
|
+
|
35
|
+
The script requires the installation of the following command-line tools:
|
36
|
+
|
37
|
+
- `fzf`: a powerful command-line fuzzy finder.
|
38
|
+
- `mods`: an AI-powered CLI tool for generative AI interactions.
|
39
|
+
- `the_silver_searcher (ag)`: a code-searching tool similar to ack and used for searching prompts.
|
40
|
+
|
41
|
+
#### Usage
|
42
|
+
|
43
|
+
The `aip.rb` script offers a set of command-line options to guide the interaction with AI:
|
44
|
+
|
45
|
+
- `-p, --prompt`: Specify the prompt name to be used.
|
46
|
+
- `-e, --edit`: Open the prompt text for editing before generation.
|
47
|
+
- `-f, --fuzzy`: Allows fuzzy matching for prompt selection.
|
48
|
+
- `-o, --output`: Sets the output file for the generated content.
|
49
|
+
|
50
|
+
Additional flags and options can be passed to the `mods` tool by appending them after a `--` separator.
|
51
|
+
|
52
|
+
#### Installation
|
53
|
+
|
54
|
+
Before using the script, one must ensure the required command-line tools (`fzf`, `mods`, and `the_silver_searcher`) are installed, and the Ruby environment is correctly set up with the necessary gems.
|
55
|
+
|
56
|
+
#### Development Notes
|
57
|
+
|
58
|
+
The author suggests that the script has matured enough to be converted into a Ruby gem for easier distribution and installation.
|
59
|
+
|
60
|
+
#### Getting Help
|
61
|
+
|
62
|
+
For help with using the CLI tool or further understanding the `mods` command, users can refer to the AI CLI Program help section included in the script or by invoking the `--help` flag.
|
63
|
+
|
64
|
+
#### Conclusion
|
65
|
+
|
66
|
+
The `aip.rb` script is designed to offer a user-friendly and flexible approach to integrating generative AI into content creation processes. It streamlines the interactions and management of AI-generated content by providing prompt management, AI integration, and logging capabilities, packaged inside a simple command-line utility.
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
## Installation
|
73
|
+
|
74
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
75
|
+
|
76
|
+
Install the gem and add to the application's Gemfile by executing:
|
77
|
+
|
78
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
79
|
+
|
80
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
81
|
+
|
82
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
83
|
+
|
84
|
+
## Usage
|
85
|
+
|
86
|
+
TODO: Write usage instructions here
|
87
|
+
|
88
|
+
## Development
|
89
|
+
|
90
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
91
|
+
|
92
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/prompt_manager.
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/aip.rb
ADDED
@@ -0,0 +1,402 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# warn_indent: true
|
5
|
+
##########################################################
|
6
|
+
###
|
7
|
+
## File: aip.rb
|
8
|
+
## Desc: Use generative AI with saved parameterized prompts
|
9
|
+
## By: Dewayne VanHoozer (dvanhoozer@gmail.com)
|
10
|
+
##
|
11
|
+
## This program makes use of the gem word_wrap's
|
12
|
+
## CLI tool: ww
|
13
|
+
#
|
14
|
+
|
15
|
+
|
16
|
+
=begin
|
17
|
+
|
18
|
+
brew install fzf mods the_silver_searcher
|
19
|
+
|
20
|
+
fzf Command-line fuzzy finder written in Go
|
21
|
+
|__ https://github.com/junegunn/fzf
|
22
|
+
|
23
|
+
mods AI on the command-line
|
24
|
+
|__ https://github.com/charmbracelet/mods
|
25
|
+
|
26
|
+
the_silver_searcher Code-search similar to ack
|
27
|
+
|__ https://github.com/ggreer/the_silver_searcher
|
28
|
+
|
29
|
+
Program Summary
|
30
|
+
|
31
|
+
The program is a Ruby script that integrates with the `mods` CLI tool, which is built on a GPT-based generative AI model. This script is designed to make use of generative AI through a set of saved, parameterized prompts. Users can easily interact with the following features:
|
32
|
+
|
33
|
+
- **Prompt Selection**: Users have the ability to choose a prompt from a curated list. This selection process is streamlined by allowing users to search and filter prompts using keywords.
|
34
|
+
|
35
|
+
- **Prompt Editing**: There is functionality for a user to modify the text of an existing prompt, tailoring it to better meet their specific needs.
|
36
|
+
|
37
|
+
- **File Input**: The script can read in data from input files, providing the necessary context or information required for the AI to generate relevant content.
|
38
|
+
|
39
|
+
- **AI Integration**: Utilizing the `mods` GPT-based CLI tool, the script takes the chosen edited prompt to guide the AI in generating its output.
|
40
|
+
|
41
|
+
- **Output Management**: After the generative process, the resulting output is saved to a designated file, ensuring that the user has a record of the AI's creations.
|
42
|
+
|
43
|
+
- **Logging**: For tracking and accountability, the program records the details of each session, including the prompt used, the AI-generated output, and the precise timestamp when the generation occurred.
|
44
|
+
|
45
|
+
This robust tool is excellent for users who wish to harness the power of generative AI for creating content, with an efficient and user-friendly system for managing the creation process.
|
46
|
+
|
47
|
+
=end
|
48
|
+
|
49
|
+
#
|
50
|
+
# TODO: I think this script has reached the point where
|
51
|
+
# it is ready to become a proper gem.
|
52
|
+
#
|
53
|
+
|
54
|
+
require 'pathname'
|
55
|
+
HOME = Pathname.new( ENV['HOME'] )
|
56
|
+
|
57
|
+
|
58
|
+
MODS_MODEL = ENV['MODS_MODEL'] || 'gpt-4-1106-preview'
|
59
|
+
|
60
|
+
AI_CLI_PROGRAM = "mods"
|
61
|
+
ai_default_opts = "-m #{MODS_MODEL} --no-limit -f"
|
62
|
+
ai_options = ai_default_opts.dup
|
63
|
+
|
64
|
+
extra_inx = ARGV.index('--')
|
65
|
+
|
66
|
+
if extra_inx
|
67
|
+
ai_options += " " + ARGV[extra_inx+1..].join(' ')
|
68
|
+
ARGV.pop(ARGV.size - extra_inx)
|
69
|
+
end
|
70
|
+
|
71
|
+
AI_COMMAND = "#{AI_CLI_PROGRAM} #{ai_options} "
|
72
|
+
EDITOR = ENV['EDITOR']
|
73
|
+
PROMPT_DIR = HOME + ".prompts"
|
74
|
+
PROMPT_LOG = PROMPT_DIR + "_prompts.log"
|
75
|
+
PROMPT_EXTNAME = ".txt"
|
76
|
+
DEFAULTS_EXTNAME = ".json"
|
77
|
+
# SEARCH_COMMAND = "ag -l"
|
78
|
+
KEYWORD_REGEX = /(\[[A-Z _|]+\])/
|
79
|
+
|
80
|
+
AVAILABLE_PROMPTS = PROMPT_DIR
|
81
|
+
.children
|
82
|
+
.select{|c| PROMPT_EXTNAME == c.extname}
|
83
|
+
.map{|c| c.basename.to_s.split('.')[0]}
|
84
|
+
|
85
|
+
AVAILABLE_PROMPTS_HELP = AVAILABLE_PROMPTS
|
86
|
+
.map{|c| " * " + c}
|
87
|
+
.join("\n")
|
88
|
+
|
89
|
+
require 'amazing_print'
|
90
|
+
require 'json'
|
91
|
+
require 'readline' # TODO: or reline ??
|
92
|
+
require 'word_wrap'
|
93
|
+
require 'word_wrap/core_ext'
|
94
|
+
|
95
|
+
|
96
|
+
require 'debug_me'
|
97
|
+
include DebugMe
|
98
|
+
|
99
|
+
require 'cli_helper'
|
100
|
+
include CliHelper
|
101
|
+
|
102
|
+
configatron.version = '1.1.0'
|
103
|
+
|
104
|
+
AI_CLI_PROGRAM_HELP = `#{AI_CLI_PROGRAM} --help`
|
105
|
+
|
106
|
+
HELP = <<EOHELP
|
107
|
+
AI CLI Program
|
108
|
+
==============
|
109
|
+
|
110
|
+
The AI cli program being used is: #{AI_CLI_PROGRAM}
|
111
|
+
|
112
|
+
The defaul options to #{AI_CLI_PROGRAM} are:
|
113
|
+
"#{ai_default_opts}"
|
114
|
+
|
115
|
+
You can pass additional CLI options to #{AI_CLI_PROGRAM} like this:
|
116
|
+
"#{my_name} my options -- options for #{AI_CLI_PROGRAM}"
|
117
|
+
|
118
|
+
#{AI_CLI_PROGRAM_HELP}
|
119
|
+
|
120
|
+
EOHELP
|
121
|
+
|
122
|
+
cli_helper("Use generative AI with saved parameterized prompts") do |o|
|
123
|
+
|
124
|
+
o.string '-p', '--prompt', 'The prompt name', default: ""
|
125
|
+
o.bool '-e', '--edit', 'Edit the prompt text', default: false
|
126
|
+
o.bool '-f', '--fuzzy', 'Allow fuzzy matching', default: false
|
127
|
+
o.path '-o', '--output', 'The output file', default: Pathname.pwd + "temp.md"
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
AG_COMMAND = "ag --file-search-regex '\.txt$' e"
|
132
|
+
CD_COMMAND = "cd #{PROMPT_DIR}"
|
133
|
+
FIND_COMMAND = "find . -name '*.txt'"
|
134
|
+
|
135
|
+
FZF_OPTIONS = [
|
136
|
+
"--tabstop=2", # 2 soaces for a tab
|
137
|
+
"--header='Prompt contents below'",
|
138
|
+
"--header-first",
|
139
|
+
"--prompt='Search term: '",
|
140
|
+
'--delimiter :',
|
141
|
+
"--preview 'ww {1}'", # ww comes from the word_wrap gem
|
142
|
+
"--preview-window=down:50%:wrap"
|
143
|
+
].join(' ')
|
144
|
+
|
145
|
+
FZF_OPTIONS += "--exact" unless fuzzy?
|
146
|
+
|
147
|
+
FZF_COMMAND = "#{CD_COMMAND} ; #{FIND_COMMAND} | fzf #{FZF_OPTIONS}"
|
148
|
+
AG_FZF_COMMAND = "#{CD_COMMAND} ; #{AG_COMMAND} | fzf #{FZF_OPTIONS}"
|
149
|
+
|
150
|
+
# use `ag` ti build a list of text lines from each prompt
|
151
|
+
# use `fzf` to search through that list to select a prompt file
|
152
|
+
|
153
|
+
def ag_fzf = `#{AG_FZF_COMMAND}`.split(':')&.first&.strip&.gsub('.txt','')
|
154
|
+
|
155
|
+
|
156
|
+
configatron.input_files = get_pathnames_from( configatron.arguments, %w[.rb .txt .md])
|
157
|
+
|
158
|
+
|
159
|
+
# TODO: Make the use of the "-p" flag optional.
|
160
|
+
# I find myself many times forgetting to use it
|
161
|
+
# and this program rejecting it because
|
162
|
+
# "the file does not exist" thinging that it
|
163
|
+
# was an input file file rather than a prompt
|
164
|
+
# name.
|
165
|
+
|
166
|
+
if configatron.prompt.empty?
|
167
|
+
configatron.prompt = ag_fzf
|
168
|
+
end
|
169
|
+
|
170
|
+
unless edit?
|
171
|
+
if configatron.prompt.nil? || configatron.prompt.empty?
|
172
|
+
error "No prompt provided"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
abort_if_errors
|
177
|
+
|
178
|
+
configatron.prompt_path = PROMPT_DIR + (configatron.prompt + PROMPT_EXTNAME)
|
179
|
+
configatron.defaults_path = PROMPT_DIR + (configatron.prompt + DEFAULTS_EXTNAME)
|
180
|
+
|
181
|
+
if !configatron.prompt_path.exist? && !edit?
|
182
|
+
error "This prompt does not exist: #{configatron.prompt}\n"
|
183
|
+
end
|
184
|
+
|
185
|
+
configatron.prompt_path = PROMPT_DIR + (configatron.prompt + PROMPT_EXTNAME)
|
186
|
+
configatron.defaults_path = PROMPT_DIR + (configatron.prompt + DEFAULTS_EXTNAME)
|
187
|
+
|
188
|
+
abort_if_errors
|
189
|
+
|
190
|
+
if edit?
|
191
|
+
unless configatron.prompt_path.exist?
|
192
|
+
configatron.prompt_path.write <<~PROMPT
|
193
|
+
# #{configatron.prompt_path.relative_path_from(HOME)}
|
194
|
+
# DESC:
|
195
|
+
|
196
|
+
PROMPT
|
197
|
+
end
|
198
|
+
|
199
|
+
`#{EDITOR} #{configatron.prompt_path}`
|
200
|
+
end
|
201
|
+
|
202
|
+
######################################################
|
203
|
+
# Local methods
|
204
|
+
|
205
|
+
def extract_raw_prompt
|
206
|
+
array_of_strings = ignore_after_end
|
207
|
+
print_header_comment(array_of_strings)
|
208
|
+
|
209
|
+
array_of_strings.reject do |a_line|
|
210
|
+
a_line.chomp.strip.start_with?('#')
|
211
|
+
end
|
212
|
+
.join("\n")
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
def ignore_after_end
|
217
|
+
array_of_strings = configatron.prompt_path.readlines
|
218
|
+
.map{|a_line| a_line.chomp.strip}
|
219
|
+
|
220
|
+
x = array_of_strings.index("__END__")
|
221
|
+
|
222
|
+
unless x.nil?
|
223
|
+
array_of_strings = array_of_strings[..x-1]
|
224
|
+
end
|
225
|
+
|
226
|
+
array_of_strings
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
def print_header_comment(array_of_strings)
|
231
|
+
print "\n\n" if verbose?
|
232
|
+
|
233
|
+
x = 0
|
234
|
+
|
235
|
+
while array_of_strings[x].start_with?('#') do
|
236
|
+
puts array_of_strings[x]
|
237
|
+
x += 1
|
238
|
+
end
|
239
|
+
|
240
|
+
print "\n\n" if x>0 && verbose?
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
# Returns an Array of keywords or phrases that look like:
|
245
|
+
# [KEYWORD]
|
246
|
+
# [KEYWORD|KEYWORD]
|
247
|
+
# [KEY PHRASE]
|
248
|
+
# [KEY PHRASE | KEY PHRASE | KEY_WORD]
|
249
|
+
#
|
250
|
+
def extract_keywords_from(prompt_raw)
|
251
|
+
prompt_raw.scan(KEYWORD_REGEX).flatten.uniq
|
252
|
+
end
|
253
|
+
|
254
|
+
# get the replacements for the keywords
|
255
|
+
def replacements_for(keywords)
|
256
|
+
replacements = load_default_replacements
|
257
|
+
|
258
|
+
keywords.each do |kw|
|
259
|
+
default = replacements[kw]
|
260
|
+
print "#{kw} (#{default}) ? "
|
261
|
+
a_string = Readline.readline("\n> ", false)
|
262
|
+
replacements[kw] = a_string unless a_string.empty?
|
263
|
+
end
|
264
|
+
|
265
|
+
save_default_replacements(replacements)
|
266
|
+
|
267
|
+
replacements
|
268
|
+
end
|
269
|
+
|
270
|
+
|
271
|
+
def load_default_replacements
|
272
|
+
if configatron.defaults_path.exist?
|
273
|
+
JSON.parse(configatron.defaults_path.read)
|
274
|
+
else
|
275
|
+
{}
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
def save_default_replacements(a_hash)
|
281
|
+
return if a_hash.empty?
|
282
|
+
defaults = a_hash.to_json
|
283
|
+
configatron.defaults_path.write defaults
|
284
|
+
end
|
285
|
+
|
286
|
+
# substitute the replacements for the keywords
|
287
|
+
def replace_keywords_with replacements, prompt_raw
|
288
|
+
prompt = prompt_raw.dup
|
289
|
+
|
290
|
+
replacements.each_pair do |keyword, replacement|
|
291
|
+
prompt.gsub!(keyword, replacement)
|
292
|
+
end
|
293
|
+
|
294
|
+
prompt
|
295
|
+
end
|
296
|
+
|
297
|
+
|
298
|
+
def log(prompt_path, prompt_raw, answer)
|
299
|
+
f = File.open(PROMPT_LOG, "ab")
|
300
|
+
|
301
|
+
f.write <<~EOS
|
302
|
+
=======================================
|
303
|
+
== #{Time.now}
|
304
|
+
== #{prompt_path}
|
305
|
+
|
306
|
+
PROMPT: #{prompt_raw}
|
307
|
+
|
308
|
+
RESULT:
|
309
|
+
#{answer}
|
310
|
+
|
311
|
+
EOS
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
######################################################
|
316
|
+
# Main
|
317
|
+
|
318
|
+
at_exit do
|
319
|
+
puts
|
320
|
+
puts "Done."
|
321
|
+
puts
|
322
|
+
end
|
323
|
+
|
324
|
+
ap configatron.to_h if debug?
|
325
|
+
|
326
|
+
configatron.prompt_raw = extract_raw_prompt
|
327
|
+
|
328
|
+
puts
|
329
|
+
puts "PROMPT:"
|
330
|
+
puts configatron.prompt_raw.wrap
|
331
|
+
puts
|
332
|
+
|
333
|
+
|
334
|
+
keywords = extract_keywords_from configatron.prompt_raw
|
335
|
+
replacements = replacements_for keywords
|
336
|
+
|
337
|
+
prompt = replace_keywords_with replacements, configatron.prompt_raw
|
338
|
+
ptompt = %Q{prompt}
|
339
|
+
|
340
|
+
command = AI_COMMAND + '"' + prompt + '"'
|
341
|
+
|
342
|
+
configatron.input_files.each do |input_file|
|
343
|
+
command += " < #{input_file}"
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
print "\n\n" if verbose? && !keywords.empty?
|
348
|
+
|
349
|
+
if verbose?
|
350
|
+
puts "="*42
|
351
|
+
puts command
|
352
|
+
puts "="*42
|
353
|
+
print "\n\n"
|
354
|
+
end
|
355
|
+
|
356
|
+
result = `#{command}`
|
357
|
+
|
358
|
+
configatron.output.write result
|
359
|
+
|
360
|
+
log configatron.prompt_path, prompt, result
|
361
|
+
|
362
|
+
|
363
|
+
__END__
|
364
|
+
|
365
|
+
To specify a history and autocomplete options with the readline method in Ruby using the readline gem, you can follow these steps:
|
366
|
+
|
367
|
+
1. **History** - To enable history functionality, create a Readline::HISTORY object:
|
368
|
+
```ruby
|
369
|
+
history = Readline::HISTORY
|
370
|
+
```
|
371
|
+
You can then use the `history` object to add and manipulate history entries.
|
372
|
+
|
373
|
+
2. **Autocomplete** - To enable autocomplete functionality, you need to provide a completion proc to `Readline.completion_proc`:
|
374
|
+
```ruby
|
375
|
+
Readline.completion_proc = proc { |input| ... }
|
376
|
+
```
|
377
|
+
You should replace `...` with the logic for determining the autocomplete options based on the input.
|
378
|
+
|
379
|
+
For example, you can define a method that provides autocomplete options based on a predefined array:
|
380
|
+
```ruby
|
381
|
+
def autocomplete_options(input)
|
382
|
+
available_options = ['apple', 'banana', 'cherry']
|
383
|
+
available_options.grep(/^#{Regexp.escape(input)}/)
|
384
|
+
end
|
385
|
+
|
386
|
+
Readline.completion_proc = proc { |input| autocomplete_options(input) }
|
387
|
+
```
|
388
|
+
|
389
|
+
In this example, the `autocomplete_options` method takes the user's input and uses the `grep` method to filter the available options based on the input prefix.
|
390
|
+
|
391
|
+
Remember to require the readline gem before using these features:
|
392
|
+
```ruby
|
393
|
+
require 'readline'
|
394
|
+
```
|
395
|
+
|
396
|
+
With the above steps in place, you can use the readline method in your code, and the specified history and autocomplete options will be available.
|
397
|
+
|
398
|
+
Note: Keep in mind that autocomplete options will only appear when tab is pressed while entering input.
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
data/lib/temp.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
### README for aip.rb Ruby Script
|
2
|
+
|
3
|
+
#### Overview
|
4
|
+
|
5
|
+
The `aip.rb` Ruby script is a command-line interface (CLI) tool designed to leverage generative AI with saved parameterized prompts. It integrates with the `mods` command-line tool that uses a GPT-based model to generate responses based on user-provided prompts. The script offers an array of features that make interacting with AI models more convenient and streamlined.
|
6
|
+
|
7
|
+
#### Features
|
8
|
+
|
9
|
+
- **Prompt Management**
|
10
|
+
- Users can select prompts from a saved collection with the help of command-line searching and filtering.
|
11
|
+
- Prompts can be edited by the user to better fit their specific context or requirement.
|
12
|
+
- Support for reading input from files to provide context for AI generation is included.
|
13
|
+
|
14
|
+
- **AI Integration**
|
15
|
+
- The script interacts with `mods`, a generative AI utilizing GPT-based models, to produce outputs from the prompts.
|
16
|
+
|
17
|
+
- **Output Handling**
|
18
|
+
- Generated content is saved to a specified file for record-keeping and further use.
|
19
|
+
|
20
|
+
- **Activity Logging**
|
21
|
+
- All actions, including prompt usage and AI output, are logged with timestamps for review and auditing purposes.
|
22
|
+
|
23
|
+
#### Dependencies
|
24
|
+
|
25
|
+
The script requires the installation of the following command-line tools:
|
26
|
+
|
27
|
+
- `fzf`: a powerful command-line fuzzy finder.
|
28
|
+
- `mods`: an AI-powered CLI tool for generative AI interactions.
|
29
|
+
- `the_silver_searcher (ag)`: a code-searching tool similar to ack and used for searching prompts.
|
30
|
+
|
31
|
+
#### Usage
|
32
|
+
|
33
|
+
The `aip.rb` script offers a set of command-line options to guide the interaction with AI:
|
34
|
+
|
35
|
+
- `-p, --prompt`: Specify the prompt name to be used.
|
36
|
+
- `-e, --edit`: Open the prompt text for editing before generation.
|
37
|
+
- `-f, --fuzzy`: Allows fuzzy matching for prompt selection.
|
38
|
+
- `-o, --output`: Sets the output file for the generated content.
|
39
|
+
|
40
|
+
Additional flags and options can be passed to the `mods` tool by appending them after a `--` separator.
|
41
|
+
|
42
|
+
#### Installation
|
43
|
+
|
44
|
+
Before using the script, one must ensure the required command-line tools (`fzf`, `mods`, and `the_silver_searcher`) are installed, and the Ruby environment is correctly set up with the necessary gems.
|
45
|
+
|
46
|
+
#### Development Notes
|
47
|
+
|
48
|
+
The author suggests that the script has matured enough to be converted into a Ruby gem for easier distribution and installation.
|
49
|
+
|
50
|
+
#### Getting Help
|
51
|
+
|
52
|
+
For help with using the CLI tool or further understanding the `mods` command, users can refer to the AI CLI Program help section included in the script or by invoking the `--help` flag.
|
53
|
+
|
54
|
+
#### Conclusion
|
55
|
+
|
56
|
+
The `aip.rb` script is designed to offer a user-friendly and flexible approach to integrating generative AI into content creation processes. It streamlines the interactions and management of AI-generated content by providing prompt management, AI integration, and logging capabilities, packaged inside a simple command-line utility.
|
57
|
+
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prompt_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dewayne VanHoozer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Manage parameterized prompt text for use with GPT/LLM
|
14
|
+
email:
|
15
|
+
- dvanhoozer@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".envrc"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- LICENSE
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/aip.rb
|
27
|
+
- lib/prompt_manager.rb
|
28
|
+
- lib/prompt_manager/version.rb
|
29
|
+
- lib/temp.md
|
30
|
+
homepage: https://github.com/MadBomber/prompt_manager
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
allowed_push_host: https://rubygems.org
|
35
|
+
homepage_uri: https://github.com/MadBomber/prompt_manager
|
36
|
+
source_code_uri: https://github.com/MadBomber/prompt_manager
|
37
|
+
changelog_uri: https://github.com/MadBomber/prompt_manager
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.2.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.5.0.dev
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Manage prompts for use with chatGPT LLMs
|
57
|
+
test_files: []
|