prompt_manager 0.4.1 → 0.4.2

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: 91badda19121014eee4d6c28b1cb882347d951af971d9afb021b00e558cb3fdc
4
- data.tar.gz: 500c401e8ced2be25adacaf374a6e18e73c42ec811e7bb632155de9d5626370c
3
+ metadata.gz: 6c566743ba6741a0787db6ea680e77676ab18282013e3475cad1c30b85b9ce1b
4
+ data.tar.gz: 1e9e57eecaf97d05799d6b173b1ce90518dc02abeeddbd50eed90c34c376509f
5
5
  SHA512:
6
- metadata.gz: 89c274000ee45ddb047eb33ab232d0e300fab51be512b1181e6d9d9dbf6abe5213013229bfd0450e948b78b09aa00aab882131ed066c7529e27c5865b8251647
7
- data.tar.gz: 4fc94add6f43ab7b0f289849e68c3c6c9f35ca24a90983a459cd2ea9043de03b8b2f9ed6701a3a614be7efecd1fc5557ab0fb0d252e84dc628d38f9f80d2d9ba
6
+ metadata.gz: e1bcda6797d895b4dd78baf6c6c6cd2b83e2f06bb3446f9112795a6d216eb9450af9f1c2d0b3f762d4f21ee40a1257fec8610eadec33f7f19dabf078e7a859bf
7
+ data.tar.gz: f69ed112a2b22801dc830d87b11f0a231755141fa4eccded5ee2dc8019343cf6cf61705af560fed211866869940029bbde88cca7c821423da245593839515e03
data/.irbrc ADDED
@@ -0,0 +1,14 @@
1
+ require_relative 'lib/prompt_manager'
2
+ require_relative 'lib/prompt_manager/storage/file_system_adapter'
3
+
4
+ HERE = Pathname.new __dir__
5
+
6
+ PromptManager::Storage::FileSystemAdapter.config do |config|
7
+ config.prompts_dir = HERE + 'examples/prompts_dir'
8
+ # config.search_proc = nil # default
9
+ # config.prompt_extension = '.txt' # default
10
+ # config.parms+_extension = '.json' # default
11
+ end
12
+
13
+ PromptManager::Prompt.storage_adapter = PromptManager::Storage::FileSystemAdapter.new
14
+
data/CHANGELOG.md CHANGED
@@ -1,27 +1,34 @@
1
- ## [0.4.1] = 2023-12-29
1
+ ## Unreleased
2
+
3
+ ## Released
4
+
5
+ ### [0.4.2] = 2024-10-26
6
+ - Added configurable parameter_regex to customize keyword pattern
7
+
8
+ ### [0.4.1] = 2023-12-29
2
9
  - Changed @directives from Hash to an Array
3
10
  - Fixed keywords not being substituted in directives
4
11
 
5
- ## [0.4.0] = 2023-12-19
12
+ ### [0.4.0] = 2023-12-19
6
13
  - Add "//directives param(s)" with keywords just like the prompt text.
7
14
 
8
- ## [0.3.3] = 2023-12-01
15
+ ### [0.3.3] = 2023-12-01
9
16
  - Added example of using the `search_proc` config parameter with the FileSystemAdapter.
10
17
 
11
- ## [0.3.2] = 2023-12-01
18
+ ### [0.3.2] = 2023-12-01
12
19
 
13
20
  - The ActiveRecordAdapter is passing its unit tests
14
21
  - Dropped the concept of an sqlite3 adapter since active record can be used to access sqlite3 databases as well as the big boys.
15
22
 
16
- ## [0.3.0] = 2023-11-28
23
+ ### [0.3.0] = 2023-11-28
17
24
 
18
25
  - **Breaking change** The value of the parameters Hash for a keyword is now an Array instead of a single value. The last value in the Array is always the most recent value used for the given keyword. This was done to support the use of a Readline::History object editing in the [aia](https://github.com/MadBomber/aia) CLI tool
19
26
 
20
- ## [0.2.0] - 2023-11-21
27
+ ### [0.2.0] - 2023-11-21
21
28
 
22
29
  - **Breaking change to FileSystemAdapter config process**
23
30
  - added list and path as extra methods in FileSystemAdapter
24
31
 
25
- ## [0.1.0] - 2023-11-16
32
+ ### [0.1.0] - 2023-11-16
26
33
 
27
34
  - Initial release using the FileSystemAdapter
data/README.md CHANGED
@@ -70,10 +70,16 @@ The prompt_manager uses a regular expression to identify these keywords within t
70
70
 
71
71
  #### What does a keyword look like?
72
72
 
73
- The current hard-coded REGEX for a [KEYWORD] identifies any all [UPPERCASE_TEXT] enclosed in square brackets as a keyword. [KEYWORDS CAN ALSO HAVE SPACES] as well as the underscore character.
73
+ By default, any text matching `[UPPERCASE_TEXT]` enclosed in square brackets is treated as a keyword. [KEYWORDS CAN ALSO HAVE SPACES] as well as the underscore character.
74
74
 
75
- This is just the initial convention adopted by prompt_manager. It is intended that this REGEX be configurable so that the prompt_manager can be used with other conventions.
75
+ You can customize the keyword pattern by setting a different regular expression:
76
76
 
77
+ ```ruby
78
+ # Use {{param}} style instead of [PARAM]
79
+ PromptManager::Prompt.parameter_regex = /(\{\{[A-Za-z_]+\}\})/
80
+ ```
81
+
82
+ The regex must include capturing parentheses () to extract the keyword. The default regex is `/(\[[A-Z _|]+\])/`.
77
83
  #### All about directives
78
84
 
79
85
  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.
data/Rakefile CHANGED
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  Tocer::Rake::Register.call
10
10
 
11
-
12
11
  require "bundler/gem_tasks"
13
12
  require "rake/testtask"
14
13
 
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # frozen_string_literal: true
4
+ # warn_indent: true
5
+ ##########################################################
6
+ ###
7
+ ## File: directives.rb
8
+ ## Desc: Demo of the PromptManager and FileStorageAdapter
9
+ ## By: Dewayne VanHoozer (dvanhoozer@gmail.com)
10
+ ##
11
+ #
12
+
13
+ param1 = "param_one"
14
+ param2 = "param_two"
15
+
16
+
17
+ class MyDirectives
18
+ def self.good_directive(*args)
19
+ puts "inside #{__method__} with these parameters:"
20
+ puts args.join(",\n")
21
+ end
22
+ end
23
+
24
+ def concept_break = print "\n------------------------\n\n\n"
25
+
26
+ require_relative '../lib/prompt_manager'
27
+ require_relative '../lib/prompt_manager/storage/file_system_adapter'
28
+
29
+ require 'amazing_print'
30
+ require 'pathname'
31
+
32
+ require 'debug_me'
33
+ include DebugMe
34
+
35
+ HERE = Pathname.new( __dir__ )
36
+ PROMPTS_DIR = HERE + "prompts_dir"
37
+
38
+
39
+ ######################################################
40
+ # Main
41
+
42
+ at_exit do
43
+ puts
44
+ puts "Done."
45
+ puts
46
+ end
47
+
48
+ # Configure the Storage Adapter to use
49
+ PromptManager::Storage::FileSystemAdapter.config do |config|
50
+ config.prompts_dir = PROMPTS_DIR
51
+ # config.search_proc = nil # default
52
+ # config.prompt_extension = '.txt' # default
53
+ # config.parms+_extension = '.json' # default
54
+ end
55
+
56
+ PromptManager::Prompt.storage_adapter = PromptManager::Storage::FileSystemAdapter.new
57
+
58
+ # Use {parameter name} brackets to define a parameter
59
+ PromptManager::Prompt.parameter_regex = /\{[A-Za-z _|]+\}/
60
+
61
+ # Retrieve a prompt
62
+ prompt = PromptManager::Prompt.get(id: 'directive_example')
63
+
64
+ # Shows prompt without comments or directives
65
+ # It still has its parameter placeholders
66
+ puts prompt
67
+ concept_break
68
+
69
+ puts "Directives in the prompt:"
70
+ ap prompt.directives
71
+
72
+ puts "Processing directives ..."
73
+ prompt.directives.each do |entry|
74
+ if MyDirectives.respond_to? entry.first.to_sym
75
+ ruby = "MyDirectives.#{entry.first}(#{entry.last.gsub(' ', ',')})"
76
+ eval "#{ruby}"
77
+ else
78
+ puts "ERROR: there is no method: #{entry.first}"
79
+ end
80
+ end
81
+
82
+ concept_break
83
+
84
+
85
+
86
+ puts "Parameters in the prompt:"
87
+ ap prompt.parameters
88
+ puts "-"*16
89
+
90
+ puts "keywords:"
91
+ ap prompt.keywords
92
+ concept_break
93
+
94
+ prompt.parameters['{language}'] << 'French'
95
+
96
+ puts "After Substitution"
97
+ puts prompt
98
+
@@ -0,0 +1,14 @@
1
+ # directive_example.txt
2
+ # Desc: Shows how directives work
3
+
4
+ //good_directive param1 param2
5
+ //bad_directive param3 param4
6
+
7
+ say hello to me in {language} as well as English.
8
+
9
+ # The default parameter is delimited by square brackets
10
+ # and is all uppercase
11
+
12
+ write a [PROGRAMMING LANGUAGE] program that predicts the lottery.
13
+
14
+
@@ -10,9 +10,6 @@
10
10
  ##
11
11
  #
12
12
 
13
- require 'debug_me'
14
- include DebugMe
15
-
16
13
  require 'prompt_manager'
17
14
  require 'prompt_manager/storage/file_system_adapter'
18
15
 
@@ -21,11 +21,12 @@
21
21
  class PromptManager::Prompt
22
22
  COMMENT_SIGNAL = '#' # lines beginning with this are a comment
23
23
  DIRECTIVE_SIGNAL = '//' # Like the old IBM JCL
24
- PARAMETER_REGEX = /(\[[A-Z _|]+\])/
24
+ DEFAULT_PARAMETER_REGEX = /(\[[A-Z _|]+\])/
25
25
  @storage_adapter = nil
26
+ @parameter_regex = DEFAULT_PARAMETER_REGEX
26
27
 
27
28
  class << self
28
- attr_accessor :storage_adapter
29
+ attr_accessor :storage_adapter, :parameter_regex
29
30
 
30
31
  alias_method :get, :new
31
32
 
@@ -123,7 +124,7 @@ class PromptManager::Prompt
123
124
  # the comments.
124
125
  #
125
126
  def build
126
- @prompt = text.gsub(PARAMETER_REGEX) do |match|
127
+ @prompt = text.gsub(self.class.parameter_regex) do |match|
127
128
  param_name = match
128
129
  Array(parameters[param_name]).last || match
129
130
  end
@@ -142,7 +143,7 @@ class PromptManager::Prompt
142
143
  private
143
144
 
144
145
  def update_keywords
145
- @keywords = @text.scan(PARAMETER_REGEX).flatten.uniq
146
+ @keywords = @text.scan(self.class.parameter_regex).flatten.uniq
146
147
  @keywords.each do |kw|
147
148
  @parameters[kw] = [] unless @parameters.has_key?(kw)
148
149
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PromptManager
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
@@ -2,6 +2,8 @@
2
2
  #
3
3
  # frozen_string_literal: true
4
4
 
5
+ require 'ostruct'
6
+
5
7
  require_relative "prompt_manager/version"
6
8
  require_relative "prompt_manager/storage"
7
9
  require_relative "prompt_manager/prompt"
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.1
4
+ version: 0.4.2
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-29 00:00:00.000000000 Z
11
+ date: 2024-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ostruct
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: tocer
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +94,36 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description: "Manage the parameterized prompts (text) used in generative AI (aka chatGPT,
84
- \nOpenAI, et.al.) using storage adapters such as FileSystemAdapter, \nSqliteAdapter
126
+ \nOpenAI, et.al.) using storage adapters such as FileSystemAdapter, \nSqliteAdapter,
85
127
  and ActiveRecordAdapter.\n"
86
128
  email:
87
129
  - dvanhoozer@gmail.com
@@ -90,11 +132,14 @@ extensions: []
90
132
  extra_rdoc_files: []
91
133
  files:
92
134
  - ".envrc"
135
+ - ".irbrc"
93
136
  - CHANGELOG.md
94
137
  - LICENSE
95
138
  - LICENSE.txt
96
139
  - README.md
97
140
  - Rakefile
141
+ - examples/directives.rb
142
+ - examples/prompts_dir/directive_example.txt
98
143
  - examples/prompts_dir/todo.json
99
144
  - examples/prompts_dir/todo.txt
100
145
  - examples/prompts_dir/toy/8-ball.txt
@@ -130,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
175
  - !ruby/object:Gem::Version
131
176
  version: '0'
132
177
  requirements: []
133
- rubygems_version: 3.5.3
178
+ rubygems_version: 3.5.22
134
179
  signing_key:
135
180
  specification_version: 4
136
181
  summary: Manage prompts for use with gen-AI processes