Class: LlmClassifier::Knowledge
- Inherits:
-
Object
- Object
- LlmClassifier::Knowledge
show all
- Defined in:
- lib/llm_classifier/knowledge.rb
Overview
Domain knowledge container that converts structured data into LLM prompts
Instance Method Summary
collapse
Constructor Details
6
7
8
|
# File 'lib/llm_classifier/knowledge.rb', line 6
def initialize
@entries = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/llm_classifier/knowledge.rb', line 10
def method_missing(name, *args, &)
if args.any?
@entries[name] = args.first
elsif @entries.key?(name)
@entries[name]
else
super
end
end
|
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
20
21
22
|
# File 'lib/llm_classifier/knowledge.rb', line 20
def respond_to_missing?(name, include_private = false)
@entries.key?(name) || super
end
|
#to_h ⇒ Object
40
41
42
|
# File 'lib/llm_classifier/knowledge.rb', line 40
def to_h
@entries.dup
end
|
#to_prompt ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/llm_classifier/knowledge.rb', line 24
def to_prompt
return "" if @entries.empty?
sections = @entries.map do |key, value|
formatted_key = key.to_s.tr("_", " ").upcase
formatted_value = case value
when Array then value.join(", ")
when Hash then value.map { |k, v| "#{k}: #{v}" }.join("\n ")
else value.to_s
end
"#{formatted_key}:\n#{formatted_value}"
end
"DOMAIN KNOWLEDGE:\n\n#{sections.join("\n\n")}"
end
|