Class: Aidp::PromptOptimization::TemplateFragment
- Inherits:
-
Object
- Object
- Aidp::PromptOptimization::TemplateFragment
- Defined in:
- lib/aidp/prompt_optimization/template_indexer.rb
Overview
Represents a template fragment
Each template is a complete markdown file that can be included or excluded from prompts based on relevance
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#estimated_tokens ⇒ Integer
Estimate token count (rough approximation: 1 token ≈ 4 chars).
-
#initialize(id:, name:, category:, file_path:, content:, tags: []) ⇒ TemplateFragment
constructor
A new instance of TemplateFragment.
- #inspect ⇒ Object
-
#matches_any_tag?(query_tags) ⇒ Boolean
Check if template matches any of the given tags.
-
#size ⇒ Integer
Get the size of the template in characters.
-
#summary ⇒ Hash
Get a summary of the template.
- #to_s ⇒ Object
Constructor Details
#initialize(id:, name:, category:, file_path:, content:, tags: []) ⇒ TemplateFragment
Returns a new instance of TemplateFragment.
195 196 197 198 199 200 201 202 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 195 def initialize(id:, name:, category:, file_path:, content:, tags: []) @id = id @name = name @category = category @file_path = file_path @content = content @tags = end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
193 194 195 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 193 def category @category end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
193 194 195 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 193 def content @content end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
193 194 195 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 193 def file_path @file_path end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
193 194 195 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 193 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
193 194 195 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 193 def name @name end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
193 194 195 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 193 def @tags end |
Instance Method Details
#estimated_tokens ⇒ Integer
Estimate token count (rough approximation: 1 token ≈ 4 chars)
223 224 225 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 223 def estimated_tokens (size / 4.0).ceil end |
#inspect ⇒ Object
245 246 247 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 245 def inspect "#<TemplateFragment id=#{@id} name=\"#{@name}\" category=#{@category} tags=#{@tags}>" end |
#matches_any_tag?(query_tags) ⇒ Boolean
Check if template matches any of the given tags
208 209 210 211 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 208 def matches_any_tag?() = .map(&:downcase) @tags.any? { |tag| .include?(tag.downcase) } end |
#size ⇒ Integer
Get the size of the template in characters
216 217 218 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 216 def size @content.length end |
#summary ⇒ Hash
Get a summary of the template
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 230 def summary { id: @id, name: @name, category: @category, tags: @tags, size: size, estimated_tokens: estimated_tokens } end |
#to_s ⇒ Object
241 242 243 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 241 def to_s "TemplateFragment<#{@id}>" end |