Class: AssistantMessage

Inherits:
ApplicationRecord show all
Defined in:
app/models/assistant_message.rb

Overview

== Schema Information

Table name: assistant_messages
Database name: primary

id :bigint not null, primary key
cache_creation_tokens :integer
cached_tokens :integer
content :text
content_raw :json
input_tokens :integer
output_tokens :integer
role :string not null
thinking_signature :text
thinking_text :text
thinking_tokens :integer
created_at :datetime not null
updated_at :datetime not null
assistant_conversation_id :bigint not null
assistant_tool_call_id :bigint
llm_model_id :bigint
sender_id :bigint

Indexes

index_assistant_messages_on_assistant_conversation_id (assistant_conversation_id)
index_assistant_messages_on_assistant_tool_call_id (assistant_tool_call_id)
index_assistant_messages_on_llm_model_id (llm_model_id)
index_assistant_messages_on_role (role)
index_assistant_messages_on_sender_id (sender_id)

Foreign Keys

fk_rails_... (assistant_conversation_id => assistant_conversations.id)
fk_rails_... (assistant_tool_call_id => assistant_tool_calls.id)
fk_rails_... (llm_model_id => llm_models.id)

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#assistant_conversationObject (readonly)



51
# File 'app/models/assistant_message.rb', line 51

validates :assistant_conversation, presence: true

#roleObject (readonly)



50
# File 'app/models/assistant_message.rb', line 50

validates :role, presence: true

Class Method Details

.assistant_messagesActiveRecord::Relation<AssistantMessage>

A relation of AssistantMessages that are assistant messages. Active Record Scope

Returns:

See Also:



63
# File 'app/models/assistant_message.rb', line 63

scope :assistant_messages, -> { where(role: 'assistant') }

.by_senderActiveRecord::Relation<AssistantMessage>

A relation of AssistantMessages that are by sender. Active Record Scope

Returns:

See Also:



66
# File 'app/models/assistant_message.rb', line 66

scope :by_sender, ->(party_id) { where(sender_id: party_id) }

.system_messagesActiveRecord::Relation<AssistantMessage>

A relation of AssistantMessages that are system messages. Active Record Scope

Returns:

See Also:



64
# File 'app/models/assistant_message.rb', line 64

scope :system_messages, -> { where(role: 'system') }

.user_messagesActiveRecord::Relation<AssistantMessage>

A relation of AssistantMessages that are user messages. Active Record Scope

Returns:

See Also:



62
# File 'app/models/assistant_message.rb', line 62

scope :user_messages, -> { where(role: 'user') }

.with_thinkingActiveRecord::Relation<AssistantMessage>

A relation of AssistantMessages that are with thinking. Active Record Scope

Returns:

See Also:



65
# File 'app/models/assistant_message.rb', line 65

scope :with_thinking, -> { where.not(thinking_text: nil) }

Instance Method Details

#senderParty

Returns:

See Also:



48
# File 'app/models/assistant_message.rb', line 48

belongs_to :sender, class_name: 'Party', optional: true