Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions libs/oci/langchain_oci/chat_models/oci_generative_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 "
Expand Down