Class: CircuitBreaker::Executors::AssistantExecutor
Instance Attribute Summary
Attributes inherited from BaseExecutor
#context, #result
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from DSL
included, #validate_parameters
Constructor Details
Returns a new instance of AssistantExecutor.
11
12
13
14
15
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 11
def initialize(context = {})
super
@memory = LLM::ConversationMemory.new(system_prompt: @context[:system_prompt])
@toolkit = LLM::ToolKit.new
end
|
Class Method Details
.define(&block) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 43
def define(&block)
new.tap do |executor|
executor.instance_eval(&block) if block_given?
executor.validate_parameters
end
end
|
Instance Method Details
72
73
74
75
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 72
def add_tool(tool)
@toolkit.add_tool(tool)
self
end
|
77
78
79
80
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 77
def add_tools(tools)
tools.each { |tool| add_tool(tool) }
self
end
|
#execute ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 88
def execute
input = @context[:input]
return unless input
@memory.add_user_message(input)
conversation_context = prepare_context
response = make_llm_call(conversation_context)
processed_response = process_response(response)
@memory.add_assistant_message(processed_response[:content])
@result = {
input: input,
output: processed_response,
conversation_history: @memory.to_h,
status: 'completed'
}
end
|
#update_context(new_context) ⇒ Object
82
83
84
85
86
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 82
def update_context(new_context)
@context.merge!(new_context)
validate_parameters
self
end
|
#use_model(model_name) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 51
def use_model(model_name)
@context[:model] = model_name
@context[:model_provider] = if model_name.to_s.start_with?('llama', 'codellama', 'mistral', 'dolphin', 'qwen')
'ollama'
else
'openai'
end
self
end
|
#with_parameters(params) ⇒ Object
67
68
69
70
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 67
def with_parameters(params)
@context[:parameters] = (@context[:parameters] || {}).merge(params)
self
end
|
#with_system_prompt(prompt) ⇒ Object
61
62
63
64
65
|
# File 'lib/circuit_breaker/executors/assistant_executor.rb', line 61
def with_system_prompt(prompt)
@context[:system_prompt] = prompt
@memory = LLM::ConversationMemory.new(system_prompt: prompt)
self
end
|