Module: Terret::LLM

Defined in:
lib/terret/llm.rb

Defined Under Namespace

Classes: AdapterBase, AdapterError, FakeAdapter, Message, MessageStop, Request, RetryableError, Service, StreamError, Text, TextDelta, ToolCall, ToolCallEnd, ToolResult, Usage

Class Method Summary collapse

Class Method Details

.decode_part(hash) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/terret/llm.rb', line 37

def decode_part(hash)
  case hash[:type]
  when "text"        then Text.new(text: hash[:text])
  when "tool_call"   then ToolCall.new(id: hash[:id], name: hash[:name], args: hash[:args])
  when "tool_result" then ToolResult.new(id: hash[:id], content: hash[:content], error: hash[:error])
  else raise ArgumentError, "unknown part tag #{hash[:type].inspect}"
  end
end

.encode_part(part) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/terret/llm.rb', line 28

def encode_part(part)
  case part
  when Text       then { type: "text", text: part.text }
  when ToolCall   then { type: "tool_call", id: part.id, name: part.name, args: part.args }
  when ToolResult then { type: "tool_result", id: part.id, content: part.content, error: part.error }
  else raise ArgumentError, "cannot encode #{part.class} as a message part"
  end
end