Class: RubyLLM::Providers::Gemini::Chat::MessageFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/providers/gemini/chat.rb

Overview

formats a message

Instance Method Summary collapse

Constructor Details

#initialize(messages, format_role:, format_parts:, format_tool_result:) ⇒ MessageFormatter

Returns a new instance of MessageFormatter.



176
177
178
179
180
181
182
183
# File 'lib/ruby_llm/providers/gemini/chat.rb', line 176

def initialize(messages, format_role:, format_parts:, format_tool_result:)
  @messages = messages
  @index = 0
  @tool_call_names = {}
  @format_role = format_role
  @format_parts = format_parts
  @format_tool_result = format_tool_result
end

Instance Method Details

#formatObject



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/ruby_llm/providers/gemini/chat.rb', line 185

def format
  formatted = []

  while current_message
    if tool_message?(current_message)
      tool_parts, next_index = collect_tool_parts
      formatted << build_tool_response(tool_parts)
      @index = next_index
    else
      remember_tool_calls if current_message.tool_call?
      formatted << build_standard_message(current_message)
      @index += 1
    end
  end

  formatted
end