Class: Legion::Data::Models::LLM::Message

Inherits:
Object
  • Object
show all
Includes:
ModelHelpers
Defined in:
lib/legion/data/models/llm/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModelHelpers

#before_create

Class Method Details

.incident_flow_from(message_or_id) ⇒ Object



35
36
37
38
# File 'lib/legion/data/models/llm/message.rb', line 35

def incident_flow_from(message_or_id)
  message = message_or_id.is_a?(self) ? message_or_id : self[message_or_id]
  message&.incident_flow
end

Instance Method Details

#incident_flowObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/data/models/llm/message.rb', line 41

def incident_flow
  requests = incident_flow_requests
  responses = incident_flow_responses(requests)
  route_attempts = RouteAttempt.where(message_inference_request_id: requests.map(&:id))
                               .order(:message_inference_request_id, :attempt_no, :id)
                               .all
  tool_calls = incident_flow_tool_calls(responses)
  tool_call_attempts = ToolCallAttempt.where(tool_call_id: tool_calls.map(&:id))
                                      .order(:tool_call_id, :attempt_no, :id)
                                      .all

  {
    message:            self,
    conversation:       conversation,
    requests:           requests,
    route_attempts:     route_attempts,
    responses:          responses,
    response_messages:  responses.filter_map(&:response_message),
    tool_calls:         tool_calls,
    tool_call_attempts: tool_call_attempts,
    result_messages:    incident_flow_result_messages(responses, tool_calls)
  }
end