A working Spring AI example application featuring OpenAI integration, Pinecone vector store, and a React frontend.
- OpenAI Chat: Chat with OpenAI's GPT models
- DALL·E Image Generation: Generate images using OpenAI's DALL·E
- Vector Store: Pinecone integration for document search and retrieval
- Memory: Conversation memory with caching
- Device Control: Mock IoT device control functionality
- WebSocket: Real-time updates for device states
- Audio: Text-to-speech for AI responses
- Java 24 (or Java 23 with compatible Gradle version)
- Node.js (for the UI)
- Gradle 8.14+ (included via wrapper)
You'll need accounts and API keys for:
- OpenAI: Get your API key from OpenAI Platform
- Pinecone: Create a free account at Pinecone and get your API key
# Set your API keys as environment variables
export PINECONE_API_KEY="your-pinecone-api-key"
export SPRING_AI_OPENAI_API_KEY="your-openai-api-key"
export SPRING_PROFILES_ACTIVE="local,personal"Create your personal configuration file:
On macOS/Linux:
./create-personal-config.shOn Windows:
create-personal-config.batThis creates app/src/main/resources/application-personal.yml. Edit it with your Pinecone details:
spring:
ai:
vectorstore:
pinecone:
environment: aped-4627-b74a # Your Pinecone environment ID
projectId: bk8jiap # Your Pinecone project ID
apiKey: ${PINECONE_API_KEY} # References environment variableFinding your Pinecone values:
- Go to your Pinecone Console
- Environment: Found in your project settings (format:
xxxx-xxxx-xxx) - Project ID: Found in your project settings (short alphanumeric string)
- API Key: Generate from API Keys section (set as environment variable)
# Build and run the application (includes UI build)
./gradlew bootRunIf you want to develop the UI separately:
# Terminal 1: Run the backend
./gradlew compileJava
./gradlew bootRun
# Terminal 2: Run the frontend in development mode
cd ui
npm install
npm run devOpen your browser to: http://localhost:8055/
- OpenAI Chat: General conversation with GPT
- DALL·E: Generate images by describing what you want
- Click "Add Document" to upload files to the vector store
- Chat with your documents using the OpenAI Chat mode
- The system will search relevant documents and include them in responses
- Use the device control panel to simulate IoT device interactions
- Try asking the AI to "turn on the living room light" or "check the status of the kitchen fan"
- Server port: 8055
- Spring AI settings
- WebSocket configuration
- Your Pinecone credentials
- Environment-specific settings
# Build and run with Docker Compose
docker-compose up# Deploy to Kubernetes
kubectl apply -f spring-ai-k8s.ymlBuild fails with npm error:
- Make sure Node.js is installed
- Try running
npm installin theui/directory first
Pinecone connection issues:
- Verify your API key and environment settings
- Check that your Pinecone index exists
- Ensure your account has sufficient credits
OpenAI API errors:
- Verify your OpenAI API key is valid
- Check your OpenAI account has sufficient credits
- Ensure the API key has the necessary permissions
Java version issues:
- This project requires Java 24 or Java 23 with Gradle 8.14+
- Check your Java version:
java -version - Update JAVA_HOME if necessary
For more detailed logging, add this to your environment:
export SPRING_PROFILES_ACTIVE="local,personal,debug"- Backend: Spring Boot with Spring AI framework
- Frontend: React with Vite build system
- Vector Store: Pinecone for document embeddings
- AI Models: OpenAI GPT and DALL·E
- Real-time: WebSocket for device state updates
- Memory: In-memory conversation history with caching
GET /openai?message=hello- Chat with OpenAIGET /openai/image?message=sunset- Generate image with DALL·EGET /openai/stream?message=hello- Streaming chat responsePOST /pinecone/add- Add documents to vector storeGET /device/status- Get device statesWebSocket /device-state- Real-time device updates
├── app/ # Spring Boot backend
│ ├── src/main/java/ # Java source code
│ ├── src/main/resources/ # Configuration files
│ └── build.gradle # Dependencies and build config
├── ui/ # React frontend
│ ├── src/ # React components and hooks
│ ├── package.json # Node dependencies
│ └── vite.config.js # Build configuration
└── docker-compose.yml # Container deployment
- Spring AI 1.0.0-M6
- Spring Boot 3.4.3
- Java 24
- React 18
- Tailwind CSS
- Vite
- WebSocket