Skip to content

Commit 51c32e7

Browse files
committed
Fix issue where OpenAI can return "tool_calls":null in it's json
tool_call can be null when return from openAI assistant. changing the order so it does not run into the null issue
1 parent 9a711fd commit 51c32e7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/langchain/assistant.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def handle_user_or_tool_message
309309
end
310310

311311
def set_state_for(response:)
312-
if response.tool_calls.any?
312+
if response.tool_calls&.any?
313313
:in_progress
314314
elsif response.chat_completion
315315
:completed

lib/langchain/assistant/llm/adapters/openai.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def build_chat_params(
4040
# @param tool_call_id [String] The tool call ID
4141
# @return [Messages::OpenAIMessage] The OpenAI message
4242
def build_message(role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil)
43-
Messages::OpenAIMessage.new(role: role, content: content, image_url: image_url, tool_calls: tool_calls, tool_call_id: tool_call_id)
43+
Messages::OpenAIMessage.new(role: role, content: content, image_url: image_url, tool_calls: tool_calls || [], tool_call_id: tool_call_id)
4444
end
4545

4646
# Extract the tool call information from the OpenAI tool call hash

0 commit comments

Comments
 (0)