From ab0b7feb4b15ef4ef0d4ccf90e5eeb5a52f4bc0c Mon Sep 17 00:00:00 2001 From: paxiaatucsdedu Date: Wed, 10 Dec 2025 15:01:43 -0800 Subject: [PATCH 1/3] Fix NullPointerException for empty message content Adds a check for empty message content before processing in GenericProvider, returning a default text when content is missing. --- libs/oci/langchain_oci/chat_models/oci_generative_ai.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/oci/langchain_oci/chat_models/oci_generative_ai.py b/libs/oci/langchain_oci/chat_models/oci_generative_ai.py index 30ea719..154fc57 100644 --- a/libs/oci/langchain_oci/chat_models/oci_generative_ai.py +++ b/libs/oci/langchain_oci/chat_models/oci_generative_ai.py @@ -815,7 +815,12 @@ def messages_to_oci_params( message.tool_calls or message.additional_kwargs.get("tool_calls") ): # Process content and tool calls for assistant messages - content = self._process_message_content(message.content) + if message.content: + content = self._process_message_content(message.content) + # Issue 78 fix: Check if original content is empty BEFORE processing + # to prevent NullPointerException in OCI backend + else: + content = [self.oci_chat_message_text_content(text=".")] tool_calls = [] for tool_call in message.tool_calls: tool_calls.append( From 4988ee4b34cf5103e0cf78f65e2c0337b34935ce Mon Sep 17 00:00:00 2001 From: paxiaatucsdedu Date: Wed, 17 Dec 2025 13:34:31 -0800 Subject: [PATCH 2/3] Fix tool_call id assignment in ToolCall creation Refactors the logic for assigning the id field when creating a ToolCall object to ensure an id is always set, generating a new UUID if necessary. --- libs/oci/langchain_oci/chat_models/oci_generative_ai.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/oci/langchain_oci/chat_models/oci_generative_ai.py b/libs/oci/langchain_oci/chat_models/oci_generative_ai.py index 154fc57..945a5be 100644 --- a/libs/oci/langchain_oci/chat_models/oci_generative_ai.py +++ b/libs/oci/langchain_oci/chat_models/oci_generative_ai.py @@ -109,13 +109,18 @@ def convert_oci_tool_call_to_langchain(tool_call: Any) -> ToolCall: except json.JSONDecodeError: # If it's not valid JSON, keep it as a string pass + + if "id" in tool_call.attribute_map and tool_call.id: + id = tool_call.id + else: + id = uuid.uuid4().hex return ToolCall( name=tool_call.name, args=parsed if "arguments" in tool_call.attribute_map else tool_call.parameters, - id=tool_call.id if "id" in tool_call.attribute_map else uuid.uuid4().hex[:], + id=id ) @staticmethod From e0eff8b14f3f77ba7afc2f0b8b797418986649ea Mon Sep 17 00:00:00 2001 From: paxiaatucsdedu Date: Wed, 17 Dec 2025 13:48:43 -0800 Subject: [PATCH 3/3] Make format to appease the lint god --- libs/oci/langchain_oci/chat_models/oci_generative_ai.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/oci/langchain_oci/chat_models/oci_generative_ai.py b/libs/oci/langchain_oci/chat_models/oci_generative_ai.py index 945a5be..22fc47c 100644 --- a/libs/oci/langchain_oci/chat_models/oci_generative_ai.py +++ b/libs/oci/langchain_oci/chat_models/oci_generative_ai.py @@ -109,7 +109,7 @@ def convert_oci_tool_call_to_langchain(tool_call: Any) -> ToolCall: except json.JSONDecodeError: # If it's not valid JSON, keep it as a string pass - + if "id" in tool_call.attribute_map and tool_call.id: id = tool_call.id else: @@ -120,7 +120,7 @@ def convert_oci_tool_call_to_langchain(tool_call: Any) -> ToolCall: args=parsed if "arguments" in tool_call.attribute_map else tool_call.parameters, - id=id + id=id, ) @staticmethod