Module: Ollama::Agent::Messages

Defined in:
lib/ollama/agent/messages.rb

Overview

Small helpers for building chat message hashes.

Class Method Summary collapse

Class Method Details

.assistant(content, tool_calls: nil) ⇒ Object



15
16
17
18
19
# File 'lib/ollama/agent/messages.rb', line 15

def self.assistant(content, tool_calls: nil)
  msg = { role: "assistant", content: content.to_s }
  msg[:tool_calls] = tool_calls if tool_calls
  msg
end

.system(content) ⇒ Object



7
8
9
# File 'lib/ollama/agent/messages.rb', line 7

def self.system(content)
  { role: "system", content: content.to_s }
end

.tool(content:, name: nil, tool_call_id: nil) ⇒ Object

Tool results are sent back as role: "tool". Some APIs require tool_call_id to associate results with calls.



23
24
25
26
27
28
# File 'lib/ollama/agent/messages.rb', line 23

def self.tool(content:, name: nil, tool_call_id: nil)
  msg = { role: "tool", content: content.to_s }
  msg[:name] = name if name
  msg[:tool_call_id] = tool_call_id if tool_call_id
  msg
end

.user(content) ⇒ Object



11
12
13
# File 'lib/ollama/agent/messages.rb', line 11

def self.user(content)
  { role: "user", content: content.to_s }
end