Skip to content

Feature Request: Support for Invoking HTTP-based APIs via OpenAPI Spec #806

Open
@LiveNathan

Description

@LiveNathan

I would like to propose an enhancement to Spring AI that could significantly broaden its application: the ability to generate and invoke HTTP-based API calls dynamically based on OpenAPI specifications.

Current Functionality:

Spring AI currently allows the registration of custom Java functions with the OpenAiChatModel, which the model can then call by generating a JSON object with the required arguments. This setup works excellently for predefined functions where the function signature is known beforehand.

Proposed Enhancement:

Extend the functionality to allow the AI to interpret OpenAPI specifications and generate HTTP requests dynamically. This feature would enable developers to automate interactions with various APIs without needing to manually define each possible function or endpoint.

Benefits:

Enhanced Flexibility: Automating the generation of API calls based on OpenAPI specs would make Spring AI more adaptable, allowing it to interact with a broader range of external APIs.

Reduced Development Time: Developers wouldn't need to manually define and maintain function signatures for each API endpoint they wish to call. Instead, they could simply provide the OpenAPI spec and let the AI handle the rest.

Increased Productivity: This feature could automate complex workflows involving multiple API calls, making it easier to build sophisticated applications quickly.

Implementation Suggestion:

Function Bean: Introduce a new type of function bean that can interpret OpenAPI specs and generate the corresponding HTTP requests. This bean would parse the OpenAPI document, extract endpoint details, and formulate the necessary request parameters dynamically.

AI Integration: Enhance the OpenAiChatModel to understand when to call these new function beans based on the provided API documentation and user requests.

Example Use Case:

Imagine a staffing application that interacts with an API to manage contacts. Currently, a developer might need to:

GET a contact's UUID.
Use that UUID in a subsequent POST request to update their email address.
With this proposed enhancement, the developer could provide the OpenAPI spec for the staffing API, and the AI could dynamically generate and execute these calls based on the user's request.

Conclusion:

This feature would greatly enhance the capabilities of Spring AI, bringing it closer to the functionality offered by frameworks like LangChain, but with the added robustness and flexibility of the Spring ecosystem. It would empower developers to automate complex workflows and integrate with a vast array of external APIs more efficiently.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions