From dbfe122cb7ae26b8a91edd99cc7c262e897f3873 Mon Sep 17 00:00:00 2001 From: Padam Prakash Bengani Date: Sat, 4 Oct 2025 06:37:42 +0100 Subject: [PATCH] Change the order of if / elif in convert_to_oci_tool func to prefer using convert_to_openai_function for any callable tool Signed-off-by: Padam Prakash Bengani --- .../chat_models/oci_generative_ai.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 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 8d8ce34..3d99544 100644 --- a/libs/oci/langchain_oci/chat_models/oci_generative_ai.py +++ b/libs/oci/langchain_oci/chat_models/oci_generative_ai.py @@ -804,7 +804,22 @@ def convert_to_oci_tool( Raises: ValueError: If the tool type is not supported. """ - if isinstance(tool, BaseTool): + if (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool): + as_json_schema_function = convert_to_openai_function(tool) + parameters = as_json_schema_function.get("parameters", {}) + return self.oci_function_definition( + name=as_json_schema_function.get("name"), + description=as_json_schema_function.get( + "description", + as_json_schema_function.get("name"), + ), + parameters={ + "type": "object", + "properties": parameters.get("properties", {}), + "required": parameters.get("required", []), + }, + ) + elif isinstance(tool, BaseTool): return self.oci_function_definition( name=tool.name, description=OCIUtils.remove_signature_from_tool_description( @@ -826,21 +841,6 @@ def convert_to_oci_tool( ], }, ) - elif (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool): - as_json_schema_function = convert_to_openai_function(tool) - parameters = as_json_schema_function.get("parameters", {}) - return self.oci_function_definition( - name=as_json_schema_function.get("name"), - description=as_json_schema_function.get( - "description", - as_json_schema_function.get("name"), - ), - parameters={ - "type": "object", - "properties": parameters.get("properties", {}), - "required": parameters.get("required", []), - }, - ) raise ValueError( f"Unsupported tool type {type(tool)}. " "Tool must be passed in as a BaseTool "