openapi2callables
Top-level package for OpenAPI2Callables.
Submodules
Attributes
Classes
Class instance for executing remote API calls as simple Callables. |
|
Class instance for executing client-local functions |
|
Abstract Base Class for Tool Calling |
Package Contents
- openapi2callables.__author__ = 'Andrew Bolster'
- openapi2callables.__email__ = 'andrew.bolster@gmail.com'
- openapi2callables.__version__
- openapi2callables.logger
- class openapi2callables.APITool
Bases:
ToolClass instance for executing remote API calls as simple Callables.
Enhanced to handle complex OpenAPI features including: - Authentication (API keys, tokens, OAuth) - Complex request bodies with nested objects - File uploads - Custom headers and cookies - Response handling with different content types - Error handling with status codes
- base_url: str = None
- path: str = None
- method: str = 'get'
- responses: Dict[str, Any]
- service_name: str | None = None
- deprecated: bool = False
- access_token_name: str | None = None
- access_token_type: str | None = None
- access_token: str | None = None
- timeout: int = 30
- follow_redirects: bool = True
- retry_count: int = 0
- retry_backoff: float = 1.0
- content_type: str | None = None
- accept: str | None = None
- security_schemes: Dict[str, Dict[str, Any]]
- cookies: Dict[str, str]
- __post_init__()
- property requires_auth
Check if the tool requires authentication.
- resolve_access_token(kwds)
Resolve the access token to use for the API request. Priority: 1. self.access_token_name named argument passed at runtime 2. “access_token” passed set at instantiation 3. “access_token” set in settings 4. raise error
- Return type:
str
- validate_parameter_type(param_name, param_value, expected_type=None)
- prepare_request_data(kwds)
Prepare request data from keyword arguments.
- Parameters:
kwds – Keyword arguments passed to the tool
- Returns:
Tuple of (path, params, headers, cookies, body, files)
- handle_response(response)
Handle the response from the API.
- Parameters:
response – The response object
- Returns:
The processed response data
- __call__(client=requests.request, *args, **kwds)
Execute the API call.
- Parameters:
client – The HTTP client to use (defaults to requests.request)
*args – Positional arguments (ignored)
**kwds – Keyword arguments for the API call
- Returns:
The processed response from the API
- class openapi2callables.LocalTool
Bases:
ToolClass instance for executing client-local functions >>> f = LocalTool(operationId=’f’, description=’f’, parameters={‘x’:{‘type’:”integer”, ‘description’:”the input”, ‘required’=True}}, func=lambda x: x+1) >>> f(1) 2
- func: Callable
- __post_init__()
- property requires_auth
Check if the tool requires authentication
- __call__(*args, **kwds)
- class openapi2callables.Tool
Bases:
abc.ABCAbstract Base Class for Tool Calling
- operationId: str
- description: str
- parameters: Dict[str, Any]
- responses: Dict[str, Any]
- summary: str = None
- tags: Set[str]
- __hash__()
- __post_init__()
- abstract property requires_auth
Check if the tool requires authentication
- property requires_confirmation
Check if the tool requires confirmation by checking the tags
- abstractmethod __call__(*args, **kwds)
- to_tool_spec()
Express the Tool in a format accepted by the OpenAI API as a ‘Tool’
Execution of the particular tool is the responsibility of the calling client