Introduction
Integrating AI into an application doesn’t always require an agentic approach or complex prompt engineering always. Often, we simply want to leverage the power of AI to make an application more robust and user-friendly.
For example, consider an ecommerce application where a customer submits a service request via email or text:
Items purchased in order ORD-002 not working. I want to return it. Thanks. - Omkar
To process the request programmatically, the application needs to extract a structured format:
| |
The Embabel agentic framework allows you to harness the power of AI wherever it is needed within a Spring Boot application.
Implementation
The full code is available here.
Add the Embabel dependency:
| |
In this case, we are using OpenAI models. Embabel supports other model providers like Gemini, Anthropic etc.
Inject com.embabel.agent.api.common.Ai into your Spring component:
| |
We will use Ai to make a call to LLMs.
In the following controller API, the LLM parses the customer query and returns a formatted JSON output.
| |
Generating a Java object from a natural language query makes it easy for the application to process the data further.
Testing
Export or set environment variable for your model provider’s API key. In this case, use OPENAI_API_KEY.
| |
Run the Spring Boot application.
| |
Make API call:
| |
Congratulations! 🎉 We have successfully converted a natural language query into a Java object.
LLMs, in combination with frameworks like Embabel, makes it a breeze to utilize the power of AI across your entire application.
Please let me know your thoughts in the comments below.