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.
19 20 21 22 23 24 25 |
# File 'lib/llm_gateway/prompt.rb', line 19 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.
7 8 9 |
# File 'lib/llm_gateway/prompt.rb', line 7 def cache_key @cache_key end |
#cache_retention ⇒ Object
Returns the value of attribute cache_retention.
7 8 9 |
# File 'lib/llm_gateway/prompt.rb', line 7 def cache_retention @cache_retention end |
Class Method Details
.after_execute(*methods, &block) ⇒ Object
14 15 16 17 |
# File 'lib/llm_gateway/prompt.rb', line 14 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
9 10 11 12 |
# File 'lib/llm_gateway/prompt.rb', line 9 def self.before_execute(*methods, &block) self.before_execute_callbacks += methods self.before_execute_callbacks += [ block ] if block_given? end |
.find_tool(name) ⇒ Object
52 53 54 |
# File 'lib/llm_gateway/prompt.rb', line 52 def self.find_tool(name) tools.find { |tool| tool.tool_name == name } end |
.tools ⇒ Object
48 49 50 |
# File 'lib/llm_gateway/prompt.rb', line 48 def self.tools const_defined?(:TOOLS, false) ? self::TOOLS : [] end |
Instance Method Details
#run(provider: nil, model: nil, reasoning: nil, **options, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/llm_gateway/prompt.rb', line 27 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
41 42 43 44 45 46 |
# File 'lib/llm_gateway/prompt.rb', line 41 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
60 61 62 |
# File 'lib/llm_gateway/prompt.rb', line 60 def system_prompt nil end |
#tools ⇒ Object
56 57 58 |
# File 'lib/llm_gateway/prompt.rb', line 56 def tools self.class.tools.map(&:definition) end |