Class: Langchain::LLM::OpenAIResponse
Instance Attribute Summary
Attributes inherited from BaseResponse
#context, #raw_response
Instance Method Summary
collapse
#initialize
Instance Method Details
#chat_completion ⇒ Object
23
24
25
|
# File 'lib/langchain/llm/response/openai_response.rb', line 23
def chat_completion
completion
end
|
#chat_completions ⇒ Object
43
44
45
|
# File 'lib/langchain/llm/response/openai_response.rb', line 43
def chat_completions
raw_response.dig("choices")
end
|
#completion ⇒ Object
15
16
17
|
# File 'lib/langchain/llm/response/openai_response.rb', line 15
def completion
completions&.dig(0, "message", "content")
end
|
#completion_tokens ⇒ Object
55
56
57
|
# File 'lib/langchain/llm/response/openai_response.rb', line 55
def completion_tokens
raw_response.dig("usage", "completion_tokens")
end
|
#completions ⇒ Object
39
40
41
|
# File 'lib/langchain/llm/response/openai_response.rb', line 39
def completions
raw_response.dig("choices")
end
|
#created_at ⇒ Object
9
10
11
12
13
|
# File 'lib/langchain/llm/response/openai_response.rb', line 9
def created_at
if raw_response.dig("created")
Time.at(raw_response.dig("created"))
end
end
|
#embedding ⇒ Object
35
36
37
|
# File 'lib/langchain/llm/response/openai_response.rb', line 35
def embedding
embeddings&.first
end
|
#embeddings ⇒ Object
47
48
49
|
# File 'lib/langchain/llm/response/openai_response.rb', line 47
def embeddings
raw_response.dig("data")&.map { |datum| datum.dig("embedding") }
end
|
#model ⇒ Object
5
6
7
|
# File 'lib/langchain/llm/response/openai_response.rb', line 5
def model
raw_response["model"]
end
|
#prompt_tokens ⇒ Object
51
52
53
|
# File 'lib/langchain/llm/response/openai_response.rb', line 51
def prompt_tokens
raw_response.dig("usage", "prompt_tokens")
end
|
#role ⇒ Object
19
20
21
|
# File 'lib/langchain/llm/response/openai_response.rb', line 19
def role
completions&.dig(0, "message", "role")
end
|
27
28
29
30
31
32
33
|
# File 'lib/langchain/llm/response/openai_response.rb', line 27
def tool_calls
if chat_completions.dig(0, "message").has_key?("tool_calls")
chat_completions.dig(0, "message", "tool_calls")
else
[]
end
end
|
#total_tokens ⇒ Object
59
60
61
|
# File 'lib/langchain/llm/response/openai_response.rb', line 59
def total_tokens
raw_response.dig("usage", "total_tokens")
end
|