Class: Langchain::LLM::AnthropicResponse

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

Instance Attribute Summary

Attributes inherited from BaseResponse

#context, #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/anthropic_response.rb', line 13

def chat_completion
  raw_response.dig("content", 0, "text")
end

#completionObject



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

def completion
  completions.first
end

#completion_tokensObject



37
38
39
# File 'lib/langchain/llm/response/anthropic_response.rb', line 37

def completion_tokens
  raw_response.dig("usage", "output_tokens").to_i
end

#completionsObject



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

def completions
  [raw_response.dig("completion")]
end

#log_idObject



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

def log_id
  raw_response.dig("log_id")
end

#modelObject



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

def model
  raw_response.dig("model")
end

#prompt_tokensObject



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

def prompt_tokens
  raw_response.dig("usage", "input_tokens").to_i
end

#roleObject



45
46
47
# File 'lib/langchain/llm/response/anthropic_response.rb', line 45

def role
  raw_response.dig("role")
end

#stopObject



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

def stop
  raw_response.dig("stop")
end

#stop_reasonObject



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

def stop_reason
  raw_response.dig("stop_reason")
end

#total_tokensObject



41
42
43
# File 'lib/langchain/llm/response/anthropic_response.rb', line 41

def total_tokens
  prompt_tokens + completion_tokens
end