Class: Langchain::LLM::AnthropicResponse
Instance Attribute Summary
Attributes inherited from BaseResponse
#context, #raw_response
Instance Method Summary
collapse
#created_at, #embedding, #embeddings, #initialize
Instance Method Details
#chat_completion ⇒ Object
13
14
15
16
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 13
def chat_completion
chat_completion = chat_completions.find { |h| h["type"] == "text" }
chat_completion&.dig("text")
end
|
#chat_completions ⇒ Object
23
24
25
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 23
def chat_completions
raw_response.dig("content")
end
|
#completion ⇒ Object
9
10
11
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 9
def completion
completions.first
end
|
#completion_tokens ⇒ Object
47
48
49
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 47
def completion_tokens
raw_response.dig("usage", "output_tokens").to_i
end
|
#completions ⇒ Object
27
28
29
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 27
def completions
[raw_response.dig("completion")]
end
|
#log_id ⇒ Object
39
40
41
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 39
def log_id
raw_response.dig("log_id")
end
|
#model ⇒ Object
5
6
7
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 5
def model
raw_response.dig("model")
end
|
#prompt_tokens ⇒ Object
43
44
45
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 43
def prompt_tokens
raw_response.dig("usage", "input_tokens").to_i
end
|
#role ⇒ Object
55
56
57
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 55
def role
raw_response.dig("role")
end
|
#stop ⇒ Object
35
36
37
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 35
def stop
raw_response.dig("stop")
end
|
#stop_reason ⇒ Object
31
32
33
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 31
def stop_reason
raw_response.dig("stop_reason")
end
|
18
19
20
21
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 18
def tool_calls
tool_call = chat_completions.find { |h| h["type"] == "tool_use" }
tool_call ? [tool_call] : []
end
|
#total_tokens ⇒ Object
51
52
53
|
# File 'lib/langchain/llm/response/anthropic_response.rb', line 51
def total_tokens
prompt_tokens + completion_tokens
end
|