Module: LLM::OpenAI::Response::Completion

Defined in:
lib/llm/providers/openai/response/completion.rb

Instance Method Summary collapse

Instance Method Details

#choicesObject Also known as: messages



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/llm/providers/openai/response/completion.rb', line 5

def choices
  body.choices.map.with_index do |choice, index|
    choice = LLM::Object.from_hash(choice)
    message = choice.message
    extra = {
      index:, response: self,
      logprobs: choice.logprobs,
      tool_calls: format_tool_calls(message.tool_calls),
      original_tool_calls: message.tool_calls
    }
    LLM::Message.new(message.role, message.content, extra)
  end
end

#modelObject



20
# File 'lib/llm/providers/openai/response/completion.rb', line 20

def model = body.model

#prompt_tokensObject



21
# File 'lib/llm/providers/openai/response/completion.rb', line 21

def prompt_tokens = body.usage&.prompt_tokens

#completion_tokensObject



22
# File 'lib/llm/providers/openai/response/completion.rb', line 22

def completion_tokens = body.usage&.completion_tokens

#total_tokensObject



23
# File 'lib/llm/providers/openai/response/completion.rb', line 23

def total_tokens = body.usage&.total_tokens