AI Tool Client¶
- ibm_watsonx_gov.tools.clients.ai_tool_client.delete_tool(tool_id: str, inventory_id: str, **kwargs)¶
Delete the AI tool based on the tool_id and inventory_id
- Parameters:
tool_id (str) – The ID of the tool to be deleted.
inventory_id (str) – The ID of the inventory to which the tool contains.
- Returns:
AI Tool Deleted Successfully
Example:¶
from ibm_watsonx_gov.tools.clients.ai_tool_client import delete_tool tool_id = '23dd7ec8-3d13-4f8f-a485-10278287bxxx' inventory_id = '81b1b891-0ded-46ca-bc3f-155e98a15xxx' response = delete_tool(tool_id=tool_id, inventory_id=inventory_id)
- ibm_watsonx_gov.tools.clients.ai_tool_client.delete_tool_with_name(tool_name)¶
Method to delete the tool with tool_name
- Parameters:
tool_name (str) – Name of the tool
- ibm_watsonx_gov.tools.clients.ai_tool_client.get_tool(tool_id: str, inventory_id: str, **kwargs)¶
Retrieves the details of a specific tool based on the given tool ID and inventory ID.
- Parameters:
tool_id (str) – The ID of the tool to be retrieved.
inventory_id (str) – The ID of the inventory to fetch the tool from.
- Returns:
The processed result containing tool details.
- Return type:
dict
Example:¶
from ibm_watsonx_gov.tools.clients.ai_tool_client import get_tool tool_id = '23dd7ec8-3d13-4f8f-a485-10278287bxxx' inventory_id = '81b1b891-0ded-46ca-bc3f-155e98a15xxx' response = get_tool(tool_id=tool_id, inventory_id=inventory_id)
- ibm_watsonx_gov.tools.clients.ai_tool_client.get_tool_info(tool_name: str, inventory_id: str = None) dict ¶
Method to retrieve tool information based on the tool name within the current inventory ID.
- Parameters:
tool_name (str) – Name of the tool
inventory_id (str, optional) – Inventory id
- Returns:
Returns the tool details based on the tool name.
- Return type:
dict
Example:¶
from ibm_watsonx_gov.tools.clients.ai_tool_client import get_tool_info tool_name = 'Google_search' inventory_id = '81b1b891-0ded-46ca-bc3f-155e98a15xxx' response = get_tool_info(tool_name=tool_name,inventory_id=inventory_id)
- ibm_watsonx_gov.tools.clients.ai_tool_client.list_tools(service_provider_type: list[str] | str = None, category: list[str] | str = None, inventory_id: list[str] | str = None, framework: list[str] | str = None, tool_name: list[str] | str = None, run_time_details: list[str] | str = None, search_text: list[str] | str = None)¶
Retrieves a list of registered AI tools based on the provided filter criteria.
All parameters are optional. If no filters are provided, all tools will be listed.
- Parameters:
service_provider_type (Union[list[str], str], optional) – Filter tools by one or more service provider types.
category (Union[list[str], str], optional) – Filter tools by one or more categories.
inventory_id (Union[list[str], str], optional) – Filter tools by one or more inventory IDs.
framework (Union[list[str], str], optional) – Filter tools by one or more frameworks (e.g., “langchain”).
tool_name (Union[list[str], str], optional) – Filter tools by one or more tool names.
run_time_details (Union[list[str], str], optional) – Filter tools by specific runtime details.
search_text – Filters tools based on matching keywords.
- ibm_watsonx_gov.tools.clients.ai_tool_client.register_tool(payload: dict | ToolRegistrationPayload)¶
Registers a new tool by converting the provided payload to an ToolRegistrationPayload instance. And then call the tool registration endpoint.
- Parameters:
payload (Union[dict, ToolRegistrationPayload]) – The payload to register the tool. It can either be a dictionary or an instance of ToolRegistrationPayload.
- Returns:
The processed result from the tool registration API.
- Return type:
dict
Examples:¶
- Using ToolRegistrationPayload model:
from ibm_watsonx_gov.tools.clients import register_tool, ToolRegistrationPayload post_payload = { "tool_name": "add", "description":"Use GooglSearch and return results for given query" "code": { "source_code_base64": ''' def add(num1: int, num2: int): return num1 + num2 ''', "run_time_details": { "engine": "python 3.11.0" } }, "schema":{ "properties": { "num1": { "description": "First number", "title": "num1", "type": "integer", }, "query": { "description": "Second number", "title": "num2", "type": "integer", } } } } response = register_tool(ToolRegistrationPayload(**post_payload))
- Using Dict:
from ibm_watsonx_gov.tools.clients.ai_tool_client import register_tool, Framework post_payload = { "tool_name": "add", "code": { "source_code_base64": ''' def add(num1: int, num2: int): return num1 + num2 ''', "run_time_details": { "engine": "python 3.11.0" } }, "schema":{ "properties": { "num1": { "description": "First number", "title": "num1", "type": "integer", }, "query": { "description": "Second number", "title": "num2", "type": "integer", } } } } response = register_tool(payload=post_payload)
- ibm_watsonx_gov.tools.clients.ai_tool_client.update_tool(tool_id: str, inventory_id: str, payloads: list[dict] | ToolUpdatePayload)¶
Patches the tool information based on the provided tool ID, inventory ID, and payloads.
- Parameters:
tool_id (str) – The ID of the tool to be patched.
inventory_id (str) – The ID of the inventory to which the tool contains.
payloads (list[Union[dict, ToolUpdatePayload]]) – A list of dictionaries or ToolUpdatePayload instances containing the update information for the tool.
- Returns:
The processed result from the tool update API.
- Return type:
dict
Notes
Each item in the payloads list should be either a dictionary or an instance of ToolUpdatePayload.
If a dictionary is provided, it is converted into an ToolUpdatePayload instance.
Examples:¶
- Using ToolUpdatePayload model:
from ibm_watsonx_gov.tools.clients.ai_tool_client import update_tool, ToolUpdatePayload, OPERATION_TYPE patch_payload = [ { "op": OPERATION_TYPE.REPLACE.value, "path": "/reusable", "value": False }, { "op": OPERATION_TYPE.REPLACE.value, "path": "/metrics", "value": { "roc": "64" } } ] update_payload = ToolUpdatePayload(**patch_payload) response = update_tool(payload = update_payload)
- Using Dict:
from ibm_watsonx_gov.tools.clients.ai_tool_client import update_tool, OPERATION_TYPE patch_payload = [ { "op": OPERATION_TYPE.REPLACE.value, "path": "/reusable", "value": False }, { "op": OPERATION_TYPE.REPLACE.value, "path": "/metrics", "value": { "roc": "64" } } ] response = update_tool(payload = patch_payload)