Module: RubyLLM::Sequel::MessageMethods

Defined in:
lib/ruby_llm/sequel/message_methods.rb

Instance Method Summary collapse

Instance Method Details

#to_llmObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_llm/sequel/message_methods.rb', line 6

def to_llm
  cached = columns.include?(:cached_tokens) ? self[:cached_tokens] : nil
  cache_creation = columns.include?(:cache_creation_tokens) ? self[:cache_creation_tokens] : nil
  thinking_tokens_val = columns.include?(:thinking_tokens) ? self[:thinking_tokens] : nil

  ::RubyLLM::Message.new(
    role: role.to_sym,
    content: extract_content,
    thinking: extract_thinking,
    tool_calls: extract_tool_calls,
    tool_call_id: extract_tool_call_id,
    input_tokens: input_tokens,
    output_tokens: output_tokens,
    cached_tokens: cached,
    cache_creation_tokens: cache_creation,
    thinking_tokens: thinking_tokens_val,
    model_id: model_association&.model_id
  )
end

#tool_call?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby_llm/sequel/message_methods.rb', line 26

def tool_call?
  role == 'assistant' && tool_calls_association.any?
end

#tool_result?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ruby_llm/sequel/message_methods.rb', line 30

def tool_result?
  role == 'tool' && !tool_call_id.nil?
end