Restapi Tool

pydantic model ibm_watsonx_gov.tools.rest_api.restapi_tool.RestApiTool

Bases: BaseTool

Class to construct a tool using the rest api , schema dynamically

Show JSON schema
{
   "title": "RestApiTool",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "description": {
         "title": "Description",
         "type": "string"
      },
      "args_schema": {
         "title": "Args Schema"
      },
      "return_direct": {
         "default": false,
         "title": "Return Direct",
         "type": "boolean"
      },
      "verbose": {
         "default": false,
         "title": "Verbose",
         "type": "boolean"
      },
      "callbacks": {
         "default": null,
         "title": "Callbacks",
         "type": "null"
      },
      "callback_manager": {
         "default": null,
         "title": "Callback Manager"
      },
      "tags": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Tags"
      },
      "metadata": {
         "anyOf": [
            {
               "type": "object"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Metadata"
      },
      "handle_tool_error": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": false,
         "title": "Handle Tool Error"
      },
      "handle_validation_error": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": false,
         "title": "Handle Validation Error"
      },
      "response_format": {
         "default": "content",
         "enum": [
            "content",
            "content_and_artifact"
         ],
         "title": "Response Format",
         "type": "string"
      },
      "method": {
         "default": "POST",
         "title": "Method",
         "type": "string"
      },
      "endpoint": {
         "default": "",
         "title": "Endpoint",
         "type": "string"
      },
      "headers": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Headers",
         "type": "object"
      }
   },
   "required": [
      "name",
      "description",
      "args_schema"
   ]
}

Config:
  • extra: str = ignore

  • protected_namespaces: tuple = ()

  • arbitrary_types_allowed: bool = True

Fields:
Validators:

field args_schema: Type[BaseModel] [Required]

Pydantic model class to validate and parse the tool’s input arguments.

Args schema should be either:

  • A subclass of pydantic.BaseModel.

or - A subclass of pydantic.v1.BaseModel if accessing v1 namespace in pydantic 2 or - a JSON schema dict

Validated by:
  • raise_deprecation

field description: str [Required]

Used to tell the model how/when/why to use the tool.

You can provide few-shot examples as a part of the description.

Validated by:
  • raise_deprecation

field endpoint: str = ''
Validated by:
  • raise_deprecation

field headers: Dict[str, str] = {}
Validated by:
  • raise_deprecation

field method: str = 'POST'
Validated by:
  • raise_deprecation

field name: str [Required]

The unique name of the tool that clearly communicates its purpose.

Validated by:
  • raise_deprecation

ibm_watsonx_gov.tools.rest_api.restapi_tool.load_headers(tool_name, headers: dict = {}) dict

Method to load the header using evv information

Parameters:
  • tool_name (_type_) – Name of the tool

  • headers (dict, optional) – Headers associated. Defaults to {}.

Raises:

Exception – _description_

Returns:

_description_

Return type:

dict