Class: Llmshim::ChatResponse

Inherits:
Struct
  • Object
show all
Defined in:
lib/llmshim/types.rb

Overview

A non-streaming chat completion response (+ChatResponse+ schema).

raw retains the original parsed Hash for forward compatibility.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



54
55
56
# File 'lib/llmshim/types.rb', line 54

def id
  @id
end

#latency_msObject

Returns the value of attribute latency_ms

Returns:

  • (Object)

    the current value of latency_ms



54
55
56
# File 'lib/llmshim/types.rb', line 54

def latency_ms
  @latency_ms
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



54
55
56
# File 'lib/llmshim/types.rb', line 54

def message
  @message
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



54
55
56
# File 'lib/llmshim/types.rb', line 54

def model
  @model
end

#providerObject

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



54
55
56
# File 'lib/llmshim/types.rb', line 54

def provider
  @provider
end

#rawObject

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



54
55
56
# File 'lib/llmshim/types.rb', line 54

def raw
  @raw
end

#reasoningObject

Returns the value of attribute reasoning

Returns:

  • (Object)

    the current value of reasoning



54
55
56
# File 'lib/llmshim/types.rb', line 54

def reasoning
  @reasoning
end

#usageObject

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



54
55
56
# File 'lib/llmshim/types.rb', line 54

def usage
  @usage
end

Class Method Details

.from_hash(hash) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/llmshim/types.rb', line 58

def self.from_hash(hash)
  new(
    id: hash["id"],
    model: hash["model"],
    provider: hash["provider"],
    message: ResponseMessage.from_hash(hash["message"] || {}),
    reasoning: hash["reasoning"],
    usage: Usage.from_hash(hash["usage"]),
    latency_ms: hash["latency_ms"],
    raw: hash
  )
end

Instance Method Details

#contentObject

Shortcut for the assistant text content.



72
73
74
# File 'lib/llmshim/types.rb', line 72

def content
  message&.content
end