Skip to content

Commit 36f40c4

Browse files
authored
Change the order of if / elif in convert_to_oci_tool func to prefer using convert_to_openai_function for any callable tool (#39)
Signed-off-by: Padam Prakash Bengani <[email protected]>
1 parent 2e65d06 commit 36f40c4

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
@@ -814,7 +814,22 @@ def convert_to_oci_tool(
814814
Raises:
815815
ValueError: If the tool type is not supported.
816816
"""
817-
if isinstance(tool, BaseTool):
817+
if (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool):
818+
as_json_schema_function = convert_to_openai_function(tool)
819+
parameters = as_json_schema_function.get("parameters", {})
820+
return self.oci_function_definition(
821+
name=as_json_schema_function.get("name"),
822+
description=as_json_schema_function.get(
823+
"description",
824+
as_json_schema_function.get("name"),
825+
),
826+
parameters={
827+
"type": "object",
828+
"properties": parameters.get("properties", {}),
829+
"required": parameters.get("required", []),
830+
},
831+
)
832+
elif isinstance(tool, BaseTool):
818833
return self.oci_function_definition(
819834
name=tool.name,
820835
description=OCIUtils.remove_signature_from_tool_description(
@@ -836,21 +851,6 @@ def convert_to_oci_tool(
836851
],
837852
},
838853
)
839-
elif (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool):
840-
as_json_schema_function = convert_to_openai_function(tool)
841-
parameters = as_json_schema_function.get("parameters", {})
842-
return self.oci_function_definition(
843-
name=as_json_schema_function.get("name"),
844-
description=as_json_schema_function.get(
845-
"description",
846-
as_json_schema_function.get("name"),
847-
),
848-
parameters={
849-
"type": "object",
850-
"properties": parameters.get("properties", {}),
851-
"required": parameters.get("required", []),
852-
},
853-
)
854854
raise ValueError(
855855
f"Unsupported tool type {type(tool)}. "
856856
"Tool must be passed in as a BaseTool "

0 commit comments

Comments
 (0)