This project demonstrates the integration of Spring AI with the Tavily Search API to build a conversational AI application using the Vaadin framework for the user interface.
The application allows users to input natural language queries. These queries are then processed through a chain of AI agents:
- Query Formulation Agent: Transforms the user's input into a structured
TavilyRequest
object, optimizing it for the Tavily Search API. - Tavily Search: The
TavilyApiClient
sends the structured query to the Tavily API, which performs a search and returns relevant results. - Response Curation Agent: Takes the raw search results and crafts a well-structured, conversational response with a detailed summary and references to the most relevant sources, using markdown format for links.
The application's user interface is built with Vaadin and features a simple chat-like interface where users can interact with the AI.
- Java 17 or higher
- Maven or Gradle (this project uses Gradle)
- OpenAI API Key - set as environment variable
OPENAI_API_KEY
- Tavily API Key - set as environment variable
TAVILY_API_KEY
-
Set environment variables:
export OPENAI_API_KEY=<your-openai-api-key> export TAVILY_API_KEY=<your-tavily-api-key>
-
Build and run the application (using Gradle):
./gradlew bootRun
-
Access the application:
Open your web browser and navigate to
http://localhost:8080
.
The project is organized as follows:
src/main/java/com/apappascs/spring/ai/tavily
:agent
: Contains theQueryFormulationAgent
andResponseCurationAgent
that process user input and search results.service
: Contains theTavilyApiClient
for interacting with the Tavily API and theChatService
that orchestrates the AI agents.MainView.java
: The Vaadin-based user interface.
- Spring AI: A framework for building AI-powered applications.
- Tavily Search API: An API for performing high-quality, real-time searches.
- Vaadin: A web framework for building user interfaces in Java.
- Spring Boot: A framework for building stand-alone, production-grade Spring applications.
- OpenAI: Large Language Models (LLMs)
- Gradle: A build automation tool.
- Project Lombok: A library to reduce boilerplate code.
- Viritin: Useful additions to Vaadin.
Contributions are welcome! Please feel free to submit pull requests or open issues to improve the project.