Skip to main content

OpenAPIServiceToFunctions

Convert OpenAPI service definitions to a format suitable for OpenAI function calling.

Basic Information

  • Type: haystack.components.converters.openapi_functions.OpenAPIServiceToFunctions
  • Components it can connect with:
    • FilesInput: OpenAPIServiceToFunctions receives files from FilesInput.
    • OpenAPIServiceConnector: OpenAPIServiceToFunctions can send OpenAI specification to OpenAPIServiceConnector.

Inputs

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]File paths or ByteStream objects of OpenAPI definitions (in JSON or YAML format).

Outputs

ParameterTypeDefaultDescription
functionsList[Dict[str, Any]]A list of JSON objects that define how OpenAI functions are called. Each path in the OpenAPI specification has a matching function definition in this list.
openapi_specsList[Dict[str, Any]]OpenAPI specs in JSON/YAML object format with resolved references. You can use these OpenAPI specifications as input to OpenAPIServiceConnector.

Overview

OpenAPIServiceToFunctions transforms OpenAPI service specifications into an OpenAI function calling format. It takes an OpenAI specification, extracts function definitions, and formats them so that they're compatible with OpenAI's function calling JSON format.

The definitions must respect OpenAPI specification 3.0.0 or higher. It can be JSON or YAML format. Each function must have:

  • unique operationId
  • description
  • requestBody and/or parameters
  • schema for the requestBody and/or parameters For more details on OpenAPI specification see the OpenAPI documentation. For more details on OpenAI function calling see the OpenAI documentation.

OpenAPIServiceToFunctions works best when paired with the OpenAPIServiceConnector component. It converts OpenAPI specifications into definitions that OpenAI functions can use. This lets OpenAPIServiceConnector manage input parameters from the OpenAPI spec and send them as REST API calls.

Usage Example

Initializing the Component

spec_to_functions:
type: haystack.components.converters.openapi_functions.OpenAPIServiceToFunctions
init_parameters: {}

Parameters

Init Parameters

This component has no init parameters.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]File paths or ByteStream objects of OpenAPI definitions (in JSON or YAML format).