prompt_manager 0.4.0 → 0.4.1

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: 60ae8d4c5f669935906248aa0e5ffc628e6ef0fbcc28eb31c889eb85b200d370
4
- data.tar.gz: 44e51b38634667930b5524232cefd63fe0dab3ef334500714361680009186bfd
3
+ metadata.gz: 91badda19121014eee4d6c28b1cb882347d951af971d9afb021b00e558cb3fdc
4
+ data.tar.gz: 500c401e8ced2be25adacaf374a6e18e73c42ec811e7bb632155de9d5626370c
5
5
  SHA512:
6
- metadata.gz: 634cc2d1cfdedaf1ca5f5a232334b7e8ccbad25dbb48e669daddf831e43eb45f03367f2921561cdb8ddcf1675ea48f1dcf8cc40defb479aa1eced3bb493442f9
7
- data.tar.gz: f04cc92a7ac3c286fb3958eaa44358c402899a121e89ca41aa7bddd30c41bd704bed55dd57775340c622671d0fbf36eef48171ffc3d290f220d6306622486ef3
6
+ metadata.gz: 89c274000ee45ddb047eb33ab232d0e300fab51be512b1181e6d9d9dbf6abe5213013229bfd0450e948b78b09aa00aab882131ed066c7529e27c5865b8251647
7
+ data.tar.gz: 4fc94add6f43ab7b0f289849e68c3c6c9f35ca24a90983a459cd2ea9043de03b8b2f9ed6701a3a614be7efecd1fc5557ab0fb0d252e84dc628d38f9f80d2d9ba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.4.1] = 2023-12-29
2
+ - Changed @directives from Hash to an Array
3
+ - Fixed keywords not being substituted in directives
4
+
1
5
  ## [0.4.0] = 2023-12-19
2
6
  - Add "//directives param(s)" with keywords just like the prompt text.
3
7
 
data/README.md CHANGED
@@ -15,6 +15,10 @@ Manage the parameterized prompts (text) used in generative AI (aka chatGPT, Open
15
15
  - [Generative AI (gen-AI)](#generative-ai-gen-ai)
16
16
  - [What does a keyword look like?](#what-does-a-keyword-look-like)
17
17
  - [All about directives](#all-about-directives)
18
+ - [Example Prompt with Directives](#example-prompt-with-directives)
19
+ - [Accessing Directives](#accessing-directives)
20
+ - [Dynamic Directives](#dynamic-directives)
21
+ - [Executing Directives](#executing-directives)
18
22
  - [Comments Are Ignored](#comments-are-ignored)
19
23
  - [Storage Adapters](#storage-adapters)
20
24
  - [FileSystemAdapter](#filesystemadapter)
@@ -74,9 +78,11 @@ This is just the initial convention adopted by prompt_manager. It is intended th
74
78
 
75
79
  A directive is a line in the prompt text that starts with the two characters '//' - slash slash - just like in the old days of IBM JCL - Job Control Language. A prompt can have zero or more directives. Directives can have parameters and can make use of keywords.
76
80
 
77
- The `prompt_manager` only collections directives. It extracts keywords from directive lines and provides the substitution of those keywords with other text just like it does for the prompt. Remember a directive is part of the prompt.
81
+ The `prompt_manager` only collects directives. It extracts keywords from directive lines and provides the substitution of those keywords with other text just like it does for the prompt.
78
82
 
79
- Here is an example problem with comments, directives and keywords:
83
+ ##### Example Prompt with Directives
84
+
85
+ Here is an example prompt text file with comments, directives and keywords:
80
86
 
81
87
  ```
82
88
  # prompts/sing_a_song.txt
@@ -90,12 +96,14 @@ __END__
90
96
  Computers will never replace Frank Sinatra
91
97
  ```
92
98
 
99
+ ##### Accessing Directives
100
+
93
101
  Getting directives from a prompt is as easy as getting the kewyords:
94
102
 
95
103
  ```ruby
96
104
  prompt = PromptManager::Prompt.new(...)
97
105
  prompt.keywords #=> an Array
98
- prompt.directives #=> a Hash
106
+ prompt.directives #=> an Array of entries like: ['directive', 'parameters']
99
107
 
100
108
  # to_s builds the prompt by substituting
101
109
  # values for keywords amd removing comments.
@@ -104,9 +112,33 @@ prompt.directives #=> a Hash
104
112
  puts prompt.to_s
105
113
  ```
106
114
 
107
- The Hash returned by the `prompt.directives` method has as its key the directive name (without the double-slash). Its also case-sensitive. So any typo made in editing the prompt with regard to the case of the directive's name will impact the backend processing of the prompt.
115
+ The entries in the Array returned by the `prompt.directives` method is in the order that the directives were defined within the prompt. Each entry has two elements:
116
+
117
+ - directive name (without the // characters)
118
+ - parameter string for the directive
119
+
120
+ ##### Dynamic Directives
121
+
122
+ Since directies are collected after the keywords in the prompt have been substituted for their values, it is possible to have dynamically generated directives as part of a prompt. For example:
123
+
124
+ ```
125
+ //[COMMAND] [OPTIONS]
126
+ # or
127
+ [SOMETHING]
128
+ ```
129
+ ... where [COMMAND] gets replaced by some directive name. [SOMETHING] could be replaced by "//directive options"
130
+
131
+ ##### Executing Directives
132
+
133
+ The `prompt_manager` gem only collects directives. Executing those directives is left up to some down stream process. Here are some ideas on how directives could be used in prompt downstream process:
134
+
135
+ - "//model gpt-5" could be used to set the LLM model to be used for a specific prompt.
136
+ - "//backend mods" could be used to set the backend prompt processor on the command line to be the `mods` utility.
137
+ - "//include path_to_file" could be used to add the contents of a file to the prompt.
138
+ - "//chat" could be used to send the prompts and then start up a chat session about the prompt and its response.
139
+
140
+ Its all up to how your application wants to support directives or not.
108
141
 
109
- The value for each key is a String exactly as entered in the prompt file.
110
142
 
111
143
  #### Comments Are Ignored
112
144
 
@@ -6,14 +6,17 @@
6
6
  # comment removal. It communicates with a storage system through a storage
7
7
  # adapter.
8
8
  #
9
- # Directives can be anything required by the backend
10
- # prompt processing functionality. Directives are
11
- # available along with the prompt text w/o comments.
12
- # Keywords can be used in the directives.
9
+ # Directives are collected into an Array where each entry is an Array
10
+ # of two elements. The first is the directive name as a String. The
11
+ # second is a string of parameters used by the directive.
12
+ #
13
+ # Directives are collected from the prompt after keyword
14
+ # substitution has occured. This means that directives within a
15
+ # prompt can be dynamic.
13
16
  #
14
- # It is expected that the backend prompt processes will
15
- # act on and remove the directives before passing the
16
- # prompt text on through the LLM.
17
+ # PromptManager does not execute directives. They
18
+ # are made available to be passed on to down stream
19
+ # process.
17
20
 
18
21
  class PromptManager::Prompt
19
22
  COMMENT_SIGNAL = '#' # lines beginning with this are a comment
@@ -58,7 +61,7 @@ class PromptManager::Prompt
58
61
 
59
62
  # SMELL: Does the db (aka storage adapter) really need
60
63
  # to be accessible by the main program?
61
- attr_accessor :db, :id, :text, :parameters
64
+ attr_accessor :db, :id, :text, :parameters, :directives
62
65
 
63
66
 
64
67
  # Retrieve the specific prompt ID from the Storage system.
@@ -76,10 +79,9 @@ class PromptManager::Prompt
76
79
  @text = @record[:text]
77
80
  @parameters = @record[:parameters]
78
81
  @keywords = [] # Array of String
79
- @directives = {} # Hash with directive as key, parameters as value
82
+ @directives = [] # Array of arrays. directive is first entry, rest are parameters
80
83
 
81
84
  update_keywords
82
- update_directives
83
85
 
84
86
  build
85
87
  end
@@ -125,7 +127,8 @@ class PromptManager::Prompt
125
127
  param_name = match
126
128
  Array(parameters[param_name]).last || match
127
129
  end
128
-
130
+
131
+ save_directives(@prompt)
129
132
  remove_comments
130
133
  end
131
134
 
@@ -135,11 +138,6 @@ class PromptManager::Prompt
135
138
  end
136
139
 
137
140
 
138
- def directives
139
- update_directives
140
- end
141
-
142
-
143
141
  ######################################
144
142
  private
145
143
 
@@ -153,14 +151,16 @@ class PromptManager::Prompt
153
151
  end
154
152
 
155
153
 
156
- def update_directives
157
- @text.split("\n").each do |a_line|
154
+ def save_directives(keyword_substituted_string)
155
+ @directives = []
156
+
157
+ keyword_substituted_string.split("\n").each do |a_line|
158
158
  line = a_line.strip
159
159
  next unless line.start_with?(DIRECTIVE_SIGNAL)
160
160
 
161
- parts = line.split(' ')
162
- directive = parts.shift()[DIRECTIVE_SIGNAL.length..] # drop the directive signal
163
- @directives[directive] = parts.join(' ')
161
+ parts = line.split(' ')
162
+ directive = parts.shift[DIRECTIVE_SIGNAL.length..] # drop the directive signal
163
+ @directives << [directive, parts.join(' ')]
164
164
  end
165
165
 
166
166
  @directives
@@ -171,7 +171,8 @@ class PromptManager::Prompt
171
171
  lines = @prompt
172
172
  .split("\n")
173
173
  .reject{|a_line|
174
- a_line.strip.start_with?(COMMENT_SIGNAL)
174
+ a_line.strip.start_with?(COMMENT_SIGNAL) ||
175
+ a_line.strip.start_with?(DIRECTIVE_SIGNAL)
175
176
  }
176
177
 
177
178
  # Remove empty lines at the start of the prompt
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PromptManager
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prompt_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
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-19 00:00:00.000000000 Z
11
+ date: 2023-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  requirements: []
133
- rubygems_version: 3.5.1
133
+ rubygems_version: 3.5.3
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Manage prompts for use with gen-AI processes