Module: LLM::OpenAI::ResponseAdapter::Responds

Includes:
Contract::Completion
Defined in:
lib/llm/providers/openai/response_adapter/responds.rb

Constant Summary

Constants included from Contract

Contract::ContractError

Instance Method Summary collapse

Methods included from Contract

#included

Instance Method Details

#annotationsArray<Hash>

Returns:

  • (Array<Hash>)


20
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 20

def annotations = messages[0].annotations

#contentString

Returns the LLM response

Returns:

  • (String)

    Returns the LLM response



79
80
81
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 79

def content
  super || ""
end

#content!Hash

Returns the LLM response after parsing it as JSON

Returns:

  • (Hash)

    Returns the LLM response after parsing it as JSON



85
86
87
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 85

def content!
  super
end

#input_tokensInteger Also known as: prompt_tokens

Returns the number of input tokens

Returns:

  • (Integer)

    Returns the number of input tokens



24
25
26
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 24

def input_tokens
  body.usage&.input_tokens || 0
end

#messagesArray<LLM::Messsage> Also known as: choices

Returns one or more messages

Returns:

  • (Array<LLM::Messsage>)

    Returns one or more messages



7
8
9
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 7

def messages
  [adapt_message]
end

#modelString

Returns the model name

Returns:

  • (String)

    Returns the model name



59
60
61
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 59

def model
  body.model
end

#output_textString

Returns the aggregated text content from the response outputs.

Returns:

  • (String)


73
74
75
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 73

def output_text
  content
end

#output_tokensInteger Also known as: completion_tokens

Returns the number of output tokens

Returns:

  • (Integer)

    Returns the number of output tokens



31
32
33
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 31

def output_tokens
  body.usage&.output_tokens || 0
end

#reasoning_contentString?

Returns the reasoning content when the provider exposes it

Returns:

  • (String, nil)

    Returns the reasoning content when the provider exposes it



91
92
93
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 91

def reasoning_content
  super
end

#reasoning_tokensInteger

Returns the number of reasoning tokens

Returns:

  • (Integer)


38
39
40
41
42
43
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 38

def reasoning_tokens
  body
    .usage
    &.output_tokens_details
    &.reasoning_tokens || 0
end

#response_idString

Returns:

  • (String)


14
15
16
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 14

def response_id
  respond_to?(:response) ? response["id"] : id
end

#system_fingerprintnil

OpenAI’s Responses API does not expose a system fingerprint.

Returns:

  • (nil)


66
67
68
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 66

def system_fingerprint
  nil
end

#total_tokensInteger

Returns the total number of tokens

Returns:

  • (Integer)

    Returns the total number of tokens



47
48
49
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 47

def total_tokens
  body.usage&.total_tokens || 0
end

#usageLLM::Usage

Returns usage information

Returns:



53
54
55
# File 'lib/llm/providers/openai/response_adapter/responds.rb', line 53

def usage
  super
end