Skip to content

Commit dbfe122

Browse files
committed
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 <[email protected]>
1 parent c694b3f commit dbfe122

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

libs/oci/langchain_oci/chat_models/oci_generative_ai.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,22 @@ def convert_to_oci_tool(
804804
Raises:
805805
ValueError: If the tool type is not supported.
806806
"""
807-
if isinstance(tool, BaseTool):
807+
if (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool):
808+
as_json_schema_function = convert_to_openai_function(tool)
809+
parameters = as_json_schema_function.get("parameters", {})
810+
return self.oci_function_definition(
811+
name=as_json_schema_function.get("name"),
812+
description=as_json_schema_function.get(
813+
"description",
814+
as_json_schema_function.get("name"),
815+
),
816+
parameters={
817+
"type": "object",
818+
"properties": parameters.get("properties", {}),
819+
"required": parameters.get("required", []),
820+
},
821+
)
822+
elif isinstance(tool, BaseTool):
808823
return self.oci_function_definition(
809824
name=tool.name,
810825
description=OCIUtils.remove_signature_from_tool_description(
@@ -826,21 +841,6 @@ def convert_to_oci_tool(
826841
],
827842
},
828843
)
829-
elif (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool):
830-
as_json_schema_function = convert_to_openai_function(tool)
831-
parameters = as_json_schema_function.get("parameters", {})
832-
return self.oci_function_definition(
833-
name=as_json_schema_function.get("name"),
834-
description=as_json_schema_function.get(
835-
"description",
836-
as_json_schema_function.get("name"),
837-
),
838-
parameters={
839-
"type": "object",
840-
"properties": parameters.get("properties", {}),
841-
"required": parameters.get("required", []),
842-
},
843-
)
844844
raise ValueError(
845845
f"Unsupported tool type {type(tool)}. "
846846
"Tool must be passed in as a BaseTool "

0 commit comments

Comments
 (0)