Class: Langchain::LLM::AI21Response

Inherits:
BaseResponse show all
Defined in:
lib/langchain/llm/response/ai21_response.rb

Instance Attribute Summary

Attributes inherited from BaseResponse

#context, #model, #raw_response

Instance Method Summary collapse

Methods inherited from BaseResponse

#chat_completions, #created_at, #embedding, #embeddings, #initialize

Constructor Details

This class inherits a constructor from Langchain::LLM::BaseResponse

Instance Method Details

#chat_completionObject



13
14
15
# File 'lib/langchain/llm/response/ai21_response.rb', line 13

def chat_completion
  raw_response.dig(:choices, 0, :message, :content)
end

#completionObject



9
10
11
# File 'lib/langchain/llm/response/ai21_response.rb', line 9

def completion
  completions.dig(0, :data, :text)
end

#completion_tokensObject



21
22
23
# File 'lib/langchain/llm/response/ai21_response.rb', line 21

def completion_tokens
  raw_response.dig(:usage, :completion_tokens).to_i
end

#completionsObject



5
6
7
# File 'lib/langchain/llm/response/ai21_response.rb', line 5

def completions
  raw_response.dig(:completions)
end

#prompt_tokensObject



17
18
19
# File 'lib/langchain/llm/response/ai21_response.rb', line 17

def prompt_tokens
  raw_response.dig(:usage, :prompt_tokens).to_i
end

#roleObject



29
30
31
# File 'lib/langchain/llm/response/ai21_response.rb', line 29

def role
  raw_response.dig(:choices, 0, :message, :role)
end

#total_tokensObject



25
26
27
# File 'lib/langchain/llm/response/ai21_response.rb', line 25

def total_tokens
  raw_response.dig(:usage, :total_tokens).to_i
end