-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple.rb
executable file
·159 lines (103 loc) · 3.41 KB
/
simple.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env ruby
# encoding: utf-8
# frozen_string_literal: true
# warn_indent: true
##########################################################
###
## File: simple.rb
## Desc: Simple demo of the PromptManager and FileStorageAdapter
## By: Dewayne VanHoozer ([email protected])
##
#
require 'prompt_manager'
require 'prompt_manager/storage/file_system_adapter'
require 'amazing_print'
require 'pathname'
HERE = Pathname.new( __dir__ )
PROMPTS_DIR = HERE + "prompts_dir"
######################################################
# Main
at_exit do
puts
puts "Done."
puts
end
# Configure the Storage Adapter to use
PromptManager::Storage::FileSystemAdapter.config do |config|
config.prompts_dir = PROMPTS_DIR
# config.search_proc = nil # default
# config.prompt_extension = '.txt' # default
# config.parms+_extension = '.json' # default
end
PromptManager::Prompt.storage_adapter = PromptManager::Storage::FileSystemAdapter.new
# Get a prompt
todo = PromptManager::Prompt.get(id: 'todo')
# This sequence simulates presenting each of the previously
# used values for each keyword to the user to accept or
# edit.
# ap todo.keywords
# This is a new keyword that was added after the current
# todo.json file was created. Simulate the user setting
# its value.
todo.parameters["[KEYWORD_AKA_TODO]"] = "TODO"
# When the parameter values change, the prompt must
# must be rebuilt using the build method.
todo.build
puts <<~EOS
Raw Text from Prompt File
includes all lines
=========================
EOS
puts todo.text
puts <<~EOS
Last Set of Parameters Used
Includes those recently added
=============================
EOS
ap todo.parameters
puts <<~EOS
Prompt Ready to Send to gen-AI
==============================
EOS
puts todo.to_s
puts <<~EOS
When using the FileSystemAdapter for prompt storage you can have within
the prompts_dir you can have many sub-directories. These sub-directories
act like categories. The prompt ID is composed for the sub-directory name,
a "/" character and then the normal prompt ID. For example "toy/8-ball"
EOS
magic = PromptManager::Prompt.get( id: 'toy/8-ball' )
puts "The magic PROMPT is:"
puts magic
puts
puts "Remember if you want to see the full text of the prompt file:"
puts magic.text
puts "="*64
puts <<~EOS
The FileSystemAdapter also adds two new methods to the Prompt class:
list - provides an Array of pompt IDs
path(prompt_id) - Returns a Pathname object to the prompt file
EOS
puts "List of prompts available"
puts "========================="
puts PromptManager::Prompt.list
puts <<~EOS
And the path to the "toy/8-ball" prompt file is:
#{magic.path}
Use "your_prompt.path" for when you want to do something with the
the prompt file like send it to a text editor.
Your can also use the class method if you supply a prompt_id
like this:
EOS
puts PromptManager::Prompt.path('toy/8-ball')
puts
puts "Default Search for Prompts"
puts "=========================="
print "Search Proc Class: "
puts PromptManager::Prompt.storage_adapter.search_proc.class
search_term = "txt" # some comment lines show the file name example: todo.txt
puts "Search for '#{search_term}' ..."
prompt_ids = PromptManager::Prompt.search search_term
# NOTE: prompt+ids is an Array of prompt IDs even if there is only one entry.
# or and empty array if there are no prompts have the search term.
puts "Found: #{prompt_ids}"