openapi2callables ================= .. py:module:: openapi2callables .. autoapi-nested-parse:: Top-level package for OpenAPI2Callables. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/openapi2callables/cli/index /autoapi/openapi2callables/parse/index /autoapi/openapi2callables/server/index /autoapi/openapi2callables/tools/index Attributes ---------- .. autoapisummary:: openapi2callables.__author__ openapi2callables.__email__ openapi2callables.__version__ openapi2callables.logger Classes ------- .. autoapisummary:: openapi2callables.APITool openapi2callables.LocalTool openapi2callables.Tool Package Contents ---------------- .. py:data:: __author__ :value: 'Andrew Bolster' .. py:data:: __email__ :value: 'andrew.bolster@gmail.com' .. py:data:: __version__ .. py:data:: logger .. py:class:: APITool Bases: :py:obj:`Tool` Class 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 .. py:attribute:: base_url :type: str :value: None .. py:attribute:: path :type: str :value: None .. py:attribute:: method :type: str :value: 'get' .. py:attribute:: responses :type: Dict[str, Any] .. py:attribute:: service_name :type: str | None :value: None .. py:attribute:: deprecated :type: bool :value: False .. py:attribute:: access_token_name :type: str | None :value: None .. py:attribute:: access_token_type :type: str | None :value: None .. py:attribute:: access_token :type: str | None :value: None .. py:attribute:: timeout :type: int :value: 30 .. py:attribute:: follow_redirects :type: bool :value: True .. py:attribute:: retry_count :type: int :value: 0 .. py:attribute:: retry_backoff :type: float :value: 1.0 .. py:attribute:: content_type :type: str | None :value: None .. py:attribute:: accept :type: str | None :value: None .. py:attribute:: security_schemes :type: Dict[str, Dict[str, Any]] .. py:attribute:: cookies :type: Dict[str, str] .. py:method:: __post_init__() .. py:property:: requires_auth Check if the tool requires authentication. .. py:method:: 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 .. py:method:: validate_parameter_type(param_name, param_value, expected_type=None) .. py:method:: prepare_request_data(kwds) Prepare request data from keyword arguments. :param kwds: Keyword arguments passed to the tool :returns: Tuple of (path, params, headers, cookies, body, files) .. py:method:: handle_response(response) Handle the response from the API. :param response: The response object :returns: The processed response data .. py:method:: __call__(client=requests.request, *args, **kwds) Execute the API call. :param client: The HTTP client to use (defaults to requests.request) :param \*args: Positional arguments (ignored) :param \*\*kwds: Keyword arguments for the API call :returns: The processed response from the API .. py:class:: LocalTool Bases: :py:obj:`Tool` Class 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 .. py:attribute:: func :type: Callable .. py:method:: __post_init__() .. py:property:: requires_auth Check if the tool requires authentication .. py:method:: __call__(*args, **kwds) .. py:class:: Tool Bases: :py:obj:`abc.ABC` Abstract Base Class for Tool Calling .. py:attribute:: operationId :type: str .. py:attribute:: description :type: str .. py:attribute:: parameters :type: Dict[str, Any] .. py:attribute:: responses :type: Dict[str, Any] .. py:attribute:: summary :type: str :value: None .. py:attribute:: tags :type: Set[str] .. py:method:: __hash__() .. py:method:: __post_init__() .. py:property:: requires_auth :abstractmethod: Check if the tool requires authentication .. py:property:: requires_confirmation Check if the tool requires confirmation by checking the tags .. py:method:: __call__(*args, **kwds) :abstractmethod: .. py:method:: 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