Module: LLM::Anthropic::ResponseAdapter::Completion

Includes:
Contract::Completion
Defined in:
lib/llm/providers/anthropic/response_adapter/completion.rb

Constant Summary

Constants included from Contract

Contract::ContractError

Instance Method Summary collapse

Methods included from Contract

#included

Instance Method Details

#cache_read_tokensInteger

Returns the number of cached input tokens, or 0 when the provider does not report cache usage

Returns:

  • (Integer)

    Returns the number of cached input tokens, or 0 when the provider does not report cache usage



50
51
52
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 50

def cache_read_tokens
  body.usage&.cache_read_input_tokens || 0
end

#cache_write_tokensInteger

Returns the number of cache creation input tokens, or 0 when the provider does not report cache creation usage

Returns:

  • (Integer)

    Returns the number of cache creation input tokens, or 0 when the provider does not report cache creation usage



56
57
58
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 56

def cache_write_tokens
  body.usage&.cache_creation_input_tokens || 0
end

#contentString

Returns the LLM response

Returns:

  • (String)

    Returns the LLM response



80
81
82
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 80

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



92
93
94
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 92

def content!
  super
end

#input_audio_tokensInteger

Returns the number of input audio tokens, or 0 when the provider does not report input audio usage

Returns:

  • (Integer)

    Returns the number of input audio tokens, or 0 when the provider does not report input audio usage



32
33
34
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 32

def input_audio_tokens
  super
end

#input_image_tokensInteger

Returns the number of input image tokens, or 0 when the provider does not report input image usage

Returns:

  • (Integer)

    Returns the number of input image tokens, or 0 when the provider does not report input image usage



44
45
46
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 44

def input_image_tokens
  super
end

#input_tokensInteger

Returns the number of input tokens

Returns:

  • (Integer)

    Returns the number of input tokens



14
15
16
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 14

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/anthropic/response_adapter/completion.rb', line 7

def messages
  adapt_choices
end

#modelString

Returns the model name

Returns:

  • (String)

    Returns the model name



74
75
76
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 74

def model
  body.model
end

#output_audio_tokensInteger

Returns the number of output audio tokens, or 0 when the provider does not report output audio usage

Returns:

  • (Integer)

    Returns the number of output audio tokens, or 0 when the provider does not report output audio usage



38
39
40
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 38

def output_audio_tokens
  super
end

#output_tokensInteger

Returns the number of output tokens

Returns:

  • (Integer)

    Returns the number of output tokens



20
21
22
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 20

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



86
87
88
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 86

def reasoning_content
  super
end

#reasoning_tokensInteger

Returns the number of reasoning tokens

Returns:

  • (Integer)


26
27
28
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 26

def reasoning_tokens
  0
end

#total_tokensInteger

Returns the total number of tokens

Returns:

  • (Integer)

    Returns the total number of tokens



62
63
64
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 62

def total_tokens
  input_tokens + output_tokens
end

#usageLLM::Usage

Returns usage information

Returns:



68
69
70
# File 'lib/llm/providers/anthropic/response_adapter/completion.rb', line 68

def usage
  super
end