spring-projects / spring-projects/spring-ai
Feature Request: Support for Invoking HTTP-based APIs via OpenAPI Spec
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by reading OpenAiChatModel's current custom Java function registration and how function beans are represented; define the scope for parsing an OpenAPI document, generating HTTP requests, and integrating those calls with model requests, with tests covering the proposed contact workflow as the completion target.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100