Class: Langchain::LLM::CohereResponse

Inherits:
BaseResponse show all
Defined in:
lib/langchain/llm/response/cohere_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, #initialize, #total_tokens

Constructor Details

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

Instance Method Details

#chat_completionObject



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

def chat_completion
  raw_response.dig("text")
end

#completionObject



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

def completion
  completions&.dig(0, "text")
end

#completion_tokensObject



33
34
35
# File 'lib/langchain/llm/response/cohere_response.rb', line 33

def completion_tokens
  raw_response.dig("meta", "billed_units", "output_tokens")
end

#completionsObject



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

def completions
  raw_response.dig("generations")
end

#embeddingObject



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

def embedding
  embeddings.first
end

#embeddingsObject



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

def embeddings
  raw_response.dig("embeddings")
end

#prompt_tokensObject



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

def prompt_tokens
  raw_response.dig("meta", "billed_units", "input_tokens")
end

#roleObject



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

def role
  raw_response.dig("chat_history").last["role"]
end