Class: Roast::Workflow::BaseWorkflow
- Inherits:
-
Object
- Object
- Roast::Workflow::BaseWorkflow
- Includes:
- Raix::ChatCompletion
- Defined in:
- lib/roast/workflow/base_workflow.rb
Instance Attribute Summary collapse
-
#concise ⇒ Object
Returns the value of attribute concise.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#context_path ⇒ Object
Returns the value of attribute context_path.
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output ⇒ Object
Returns the value of attribute output.
-
#output_file ⇒ Object
Returns the value of attribute output_file.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#session_name ⇒ Object
Returns the value of attribute session_name.
-
#session_timestamp ⇒ Object
Returns the value of attribute session_timestamp.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #append_to_final_output(message) ⇒ Object
-
#chat_completion(**kwargs) ⇒ Object
Override chat_completion to add instrumentation.
- #final_output ⇒ Object
-
#initialize(file = nil, name: nil, context_path: nil, resource: nil, session_name: nil, configuration: nil) ⇒ BaseWorkflow
constructor
A new instance of BaseWorkflow.
Constructor Details
#initialize(file = nil, name: nil, context_path: nil, resource: nil, session_name: nil, configuration: nil) ⇒ BaseWorkflow
Returns a new instance of BaseWorkflow.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/roast/workflow/base_workflow.rb', line 27 def initialize(file = nil, name: nil, context_path: nil, resource: nil, session_name: nil, configuration: nil) @file = file @name = name || self.class.name.underscore.split("/").last @context_path = context_path || determine_context_path @final_output = [] @output = ActiveSupport::HashWithIndifferentAccess.new @resource = resource || Roast::Resources.for(file) @session_name = session_name || @name @session_timestamp = nil @configuration = configuration transcript << { system: read_sidecar_prompt } Roast::Tools.setup_interrupt_handler(transcript) Roast::Tools.setup_exit_handler(self) end |
Instance Attribute Details
#concise ⇒ Object
Returns the value of attribute concise.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def concise @concise end |
#configuration ⇒ Object
Returns the value of attribute configuration.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def configuration @configuration end |
#context_path ⇒ Object
Returns the value of attribute context_path.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def context_path @context_path end |
#file ⇒ Object
Returns the value of attribute file.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def name @name end |
#output ⇒ Object
Returns the value of attribute output.
15 16 17 |
# File 'lib/roast/workflow/base_workflow.rb', line 15 def output @output end |
#output_file ⇒ Object
Returns the value of attribute output_file.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def output_file @output_file end |
#resource ⇒ Object
Returns the value of attribute resource.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def resource @resource end |
#session_name ⇒ Object
Returns the value of attribute session_name.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def session_name @session_name end |
#session_timestamp ⇒ Object
Returns the value of attribute session_timestamp.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def @session_timestamp end |
#verbose ⇒ Object
Returns the value of attribute verbose.
16 17 18 |
# File 'lib/roast/workflow/base_workflow.rb', line 16 def verbose @verbose end |
Instance Method Details
#append_to_final_output(message) ⇒ Object
51 52 53 |
# File 'lib/roast/workflow/base_workflow.rb', line 51 def append_to_final_output() @final_output << end |
#chat_completion(**kwargs) ⇒ Object
Override chat_completion to add instrumentation
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/roast/workflow/base_workflow.rb', line 69 def chat_completion(**kwargs) start_time = Time.now model = kwargs[:openai] || "default" ActiveSupport::Notifications.instrument("roast.chat_completion.start", { model: model, parameters: kwargs.except(:openai), }) result = super(**kwargs) execution_time = Time.now - start_time ActiveSupport::Notifications.instrument("roast.chat_completion.complete", { success: true, model: model, parameters: kwargs.except(:openai), execution_time: execution_time, response_size: result.to_s.length, }) result rescue => e execution_time = Time.now - start_time ActiveSupport::Notifications.instrument("roast.chat_completion.error", { error: e.class.name, message: e., model: model, parameters: kwargs.except(:openai), execution_time: execution_time, }) raise end |
#final_output ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/roast/workflow/base_workflow.rb', line 55 def final_output return @final_output if @final_output.is_a?(String) return "" if @final_output.nil? # Handle array case (expected normal case) if @final_output.respond_to?(:join) @final_output.join("\n\n") else # Handle any other unexpected type by converting to string @final_output.to_s end end |