Module: LLM::OpenAI::ResponseAdapter::Completion
- Includes:
- Contract::Completion
- Defined in:
- lib/llm/providers/openai/response_adapter/completion.rb
Constant Summary
Constants included from Contract
Instance Method Summary collapse
-
#content ⇒ String
Returns the LLM response.
-
#content! ⇒ Hash
Returns the LLM response after parsing it as JSON.
-
#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_tokens ⇒ Integer
Returns the number of output tokens.
-
#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
#content ⇒ String
Returns the LLM response
62 63 64 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 62 def content super end |
#content! ⇒ Hash
Returns the LLM response after parsing it as JSON
68 69 70 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 68 def content! super end |
#input_tokens ⇒ Integer
Returns the number of input tokens
23 24 25 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 23 def input_tokens body.usage&.prompt_tokens || 0 end |
#messages ⇒ Array<LLM::Messsage> Also known as: choices
Returns one or more messages
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 7 def body.choices.map.with_index do |choice, index| = choice. extra = { index:, response: self, logprobs: choice.logprobs, tool_calls: adapt_tool_calls(.tool_calls), original_tool_calls: .tool_calls } LLM::Message.new(.role, .content, extra) end end |
#model ⇒ String
Returns the model name
56 57 58 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 56 def model body.model end |
#output_tokens ⇒ Integer
Returns the number of output tokens
29 30 31 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 29 def output_tokens body.usage&.completion_tokens || 0 end |
#reasoning_tokens ⇒ Integer
Returns the number of reasoning tokens
35 36 37 38 39 40 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 35 def reasoning_tokens body .usage &.completion_tokens_details &.reasoning_tokens || 0 end |
#total_tokens ⇒ Integer
Returns the total number of tokens
44 45 46 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 44 def total_tokens body.usage&.total_tokens || 0 end |
#usage ⇒ LLM::Usage
Returns usage information
50 51 52 |
# File 'lib/llm/providers/openai/response_adapter/completion.rb', line 50 def usage super end |