Class: LlmGateway::Prompt
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
Returns the value of attribute cache_key.
-
#cache_retention ⇒ Object
Returns the value of attribute cache_retention.
Class Method Summary collapse
- .after_execute(*methods, &block) ⇒ Object
- .before_execute(*methods, &block) ⇒ Object
- .find_tool(name) ⇒ Object
- .tools ⇒ Object
Instance Method Summary collapse
-
#initialize(provider: nil, model: nil, reasoning: nil, cache_key: nil, cache_retention: nil) ⇒ Prompt
constructor
A new instance of Prompt.
- #run(provider: nil, model: nil, reasoning: nil, **options, &block) ⇒ Object
- #stream(input = prompt, provider: nil, model: nil, reasoning: nil, **options, &block) ⇒ Object
- #system_prompt ⇒ Object
- #tools ⇒ Object
Constructor Details
#initialize(provider: nil, model: nil, reasoning: nil, cache_key: nil, cache_retention: nil) ⇒ Prompt
Returns a new instance of Prompt.
22 23 24 25 26 27 28 |
# File 'lib/llm_gateway/prompt.rb', line 22 def initialize(provider: nil, model: nil, reasoning: nil, cache_key: nil, cache_retention: nil) @provider = provider || self.class.provider @model = model || self.class.model @reasoning = reasoning || self.class.reasoning @cache_key = cache_key @cache_retention = cache_retention end |
Instance Attribute Details
#cache_key ⇒ Object
Returns the value of attribute cache_key.
10 11 12 |
# File 'lib/llm_gateway/prompt.rb', line 10 def cache_key @cache_key end |
#cache_retention ⇒ Object
Returns the value of attribute cache_retention.
10 11 12 |
# File 'lib/llm_gateway/prompt.rb', line 10 def cache_retention @cache_retention end |
Class Method Details
.after_execute(*methods, &block) ⇒ Object
17 18 19 20 |
# File 'lib/llm_gateway/prompt.rb', line 17 def self.after_execute(*methods, &block) self.after_execute_callbacks += methods self.after_execute_callbacks += [ block ] if block_given? end |
.before_execute(*methods, &block) ⇒ Object
12 13 14 15 |
# File 'lib/llm_gateway/prompt.rb', line 12 def self.before_execute(*methods, &block) self.before_execute_callbacks += methods self.before_execute_callbacks += [ block ] if block_given? end |
.find_tool(name) ⇒ Object
55 56 57 |
# File 'lib/llm_gateway/prompt.rb', line 55 def self.find_tool(name) tools.find { |tool| tool.tool_name == name } end |
.tools ⇒ Object
51 52 53 |
# File 'lib/llm_gateway/prompt.rb', line 51 def self.tools const_defined?(:TOOLS, false) ? self::TOOLS : [] end |
Instance Method Details
#run(provider: nil, model: nil, reasoning: nil, **options, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/llm_gateway/prompt.rb', line 30 def run(provider: nil, model: nil, reasoning: nil, **, &block) # Resolve the prompt once so dynamic or expensive prompt builders are not # evaluated multiple times during a single run. input = prompt run_callbacks(:before_execute, input) response = run_tool_loop(input, provider: resolved_provider(provider), model: model, reasoning: reasoning, **, &block) run_callbacks(:after_execute, response) response end |
#stream(input = prompt, provider: nil, model: nil, reasoning: nil, **options, &block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/llm_gateway/prompt.rb', line 44 def stream(input = prompt, provider: nil, model: nil, reasoning: nil, **, &block) stream_provider = resolved_provider(provider) = (model: model, reasoning: reasoning).merge() stream_provider.stream(input, **, &block) end |
#system_prompt ⇒ Object
63 64 65 |
# File 'lib/llm_gateway/prompt.rb', line 63 def system_prompt nil end |
#tools ⇒ Object
59 60 61 |
# File 'lib/llm_gateway/prompt.rb', line 59 def tools self.class.tools.map(&:definition) end |