Module: LLM::Contract::Completion Abstract
- Extended by:
- LLM::Contract
- Included in:
- Anthropic::ResponseAdapter::Completion, Bedrock::ResponseAdapter::Completion, Google::ResponseAdapter::Completion, Ollama::ResponseAdapter::Completion, OpenAI::ResponseAdapter::Completion, OpenAI::ResponseAdapter::Responds
- Defined in:
- lib/llm/contract/completion.rb
Overview
Defines the interface all completion responses must implement
Constant Summary
Constants included from LLM::Contract
Instance Method Summary collapse
-
#cache_read_tokens ⇒ Integer
Returns the number of cached input tokens, or 0 when the provider does not report cache usage.
-
#cache_write_tokens ⇒ Integer
Returns the number of cache creation input tokens, or 0 when the provider does not report cache creation usage.
-
#content ⇒ String
Returns the LLM response.
-
#content! ⇒ Hash
Returns the LLM response after parsing it as JSON.
-
#input_audio_tokens ⇒ Integer
Returns the number of input audio tokens, or 0 when the provider does not report input audio usage.
-
#input_image_tokens ⇒ Integer
Returns the number of input image tokens, or 0 when the provider does not report input image usage.
-
#input_tokens ⇒ Integer
Returns the number of input tokens.
-
#messages ⇒ Array<LLM::Messsage>
(also: #choices)
Returns one or more messages.
-
#model ⇒ String
Returns the model name.
-
#output_audio_tokens ⇒ Integer
Returns the number of output audio tokens, or 0 when the provider does not report output audio usage.
-
#output_tokens ⇒ Integer
Returns the number of output tokens.
-
#reasoning_content ⇒ String?
Returns the reasoning content when the provider exposes it.
-
#reasoning_tokens ⇒ Integer
Returns the number of reasoning tokens.
-
#total_tokens ⇒ Integer
Returns the total number of tokens.
-
#usage ⇒ LLM::Usage
Returns usage information.
Methods included from LLM::Contract
Instance Method Details
#cache_read_tokens ⇒ Integer
Returns the number of cached input tokens, or 0 when the provider does not report cache usage
67 68 69 |
# File 'lib/llm/contract/completion.rb', line 67 def cache_read_tokens 0 end |
#cache_write_tokens ⇒ Integer
Returns the number of cache creation input tokens, or 0 when the provider does not report cache creation usage
75 76 77 |
# File 'lib/llm/contract/completion.rb', line 75 def cache_write_tokens 0 end |
#content ⇒ String
Returns the LLM response
89 90 91 |
# File 'lib/llm/contract/completion.rb', line 89 def content .find(&:assistant?).content end |
#content! ⇒ Hash
Returns the LLM response after parsing it as JSON
103 104 105 |
# File 'lib/llm/contract/completion.rb', line 103 def content! LLM.json.load(content) end |
#input_audio_tokens ⇒ Integer
Returns the number of input audio tokens, or 0 when the provider does not report input audio usage
43 44 45 |
# File 'lib/llm/contract/completion.rb', line 43 def input_audio_tokens 0 end |
#input_image_tokens ⇒ Integer
Returns the number of input image tokens, or 0 when the provider does not report input image usage
59 60 61 |
# File 'lib/llm/contract/completion.rb', line 59 def input_image_tokens 0 end |
#input_tokens ⇒ Integer
Returns the number of input tokens
21 22 23 |
# File 'lib/llm/contract/completion.rb', line 21 def input_tokens raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#messages ⇒ Array<LLM::Messsage> Also known as: choices
Returns one or more messages
13 14 15 |
# File 'lib/llm/contract/completion.rb', line 13 def raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#model ⇒ String
Returns the model name
127 128 129 |
# File 'lib/llm/contract/completion.rb', line 127 def model raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#output_audio_tokens ⇒ Integer
Returns the number of output audio tokens, or 0 when the provider does not report output audio usage
51 52 53 |
# File 'lib/llm/contract/completion.rb', line 51 def output_audio_tokens 0 end |
#output_tokens ⇒ Integer
Returns the number of output tokens
28 29 30 |
# File 'lib/llm/contract/completion.rb', line 28 def output_tokens raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#reasoning_content ⇒ String?
Returns the reasoning content when the provider exposes it
96 97 98 |
# File 'lib/llm/contract/completion.rb', line 96 def reasoning_content .find(&:assistant?)&.reasoning_content end |
#reasoning_tokens ⇒ Integer
Returns the number of reasoning tokens
35 36 37 |
# File 'lib/llm/contract/completion.rb', line 35 def reasoning_tokens raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#total_tokens ⇒ Integer
Returns the total number of tokens
82 83 84 |
# File 'lib/llm/contract/completion.rb', line 82 def total_tokens raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#usage ⇒ LLM::Usage
Returns usage information
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/llm/contract/completion.rb', line 110 def usage LLM::Usage.new( input_tokens:, output_tokens:, reasoning_tokens:, input_audio_tokens:, output_audio_tokens:, input_image_tokens:, cache_read_tokens:, cache_write_tokens:, total_tokens: ) end |