Module: LLM::Ollama::ResponseAdapter::Completion
- Includes:
- Contract::Completion
- Defined in:
- lib/llm/providers/ollama/response_adapter/completion.rb
Constant Summary
Constants included from Contract
Instance Method Summary collapse
-
#body ⇒ LLM::Object
Returns the response body, parsing NDJSON when the transport returned a raw string (non-streaming path).
-
#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! ⇒ LLM::Object
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 Contract
Instance Method Details
#body ⇒ LLM::Object
Returns the response body, parsing NDJSON when the transport returned a raw string (non-streaming path).
16 17 18 19 20 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 16 def body raw = super return raw unless String === raw parse_ndjson(raw) end |
#cache_read_tokens ⇒ Integer
Returns the number of cached input tokens, or 0 when the provider does not report cache usage
60 61 62 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 60 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
66 67 68 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 66 def cache_write_tokens 0 end |
#content ⇒ String
Returns the LLM response
90 91 92 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 90 def content super end |
#content! ⇒ LLM::Object
Returns the LLM response after parsing it as JSON
102 103 104 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 102 def content! super end |
#input_audio_tokens ⇒ Integer
Returns the number of input audio tokens, or 0 when the provider does not report input audio usage
42 43 44 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 42 def input_audio_tokens super end |
#input_image_tokens ⇒ Integer
Returns the number of input image tokens, or 0 when the provider does not report input image usage
54 55 56 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 54 def input_image_tokens super end |
#input_tokens ⇒ Integer
Returns the number of input tokens
24 25 26 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 24 def input_tokens body.prompt_eval_count || 0 end |
#messages ⇒ Array<LLM::Messsage> Also known as: choices
Returns one or more messages
7 8 9 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 7 def adapt_choices end |
#model ⇒ String
Returns the model name
84 85 86 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 84 def model body.model end |
#output_audio_tokens ⇒ Integer
Returns the number of output audio tokens, or 0 when the provider does not report output audio usage
48 49 50 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 48 def output_audio_tokens super end |
#output_tokens ⇒ Integer
Returns the number of output tokens
30 31 32 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 30 def output_tokens body.eval_count || 0 end |
#reasoning_content ⇒ String?
Returns the reasoning content when the provider exposes it
96 97 98 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 96 def reasoning_content super end |
#reasoning_tokens ⇒ Integer
Returns the number of reasoning tokens
36 37 38 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 36 def reasoning_tokens 0 end |
#total_tokens ⇒ Integer
Returns the total number of tokens
72 73 74 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 72 def total_tokens input_tokens + output_tokens end |
#usage ⇒ LLM::Usage
Returns usage information
78 79 80 |
# File 'lib/llm/providers/ollama/response_adapter/completion.rb', line 78 def usage super end |