A Spring Boot project demonstrating real-world integration with Generative AI models.
This demo showcases multiple AI-powered capabilities, including conversational chat, structured responses, image generation, multimodal interactions, and streaming responses.
- Conversational AI: Chat with AI and maintain contextual memory.
- Structured Responses: Map AI responses to Java objects (e.g., movies list).
- Image Generation: Generate images using OpenAI DALL·E 3 model.
- Multimodal AI: Interact with images—ask questions or analyze uploaded images.
- Streaming Responses: Stream AI responses in real-time for dynamic interactions.
- Language: Java 17+
- Framework: Spring Boot 3+
- AI Integration: Spring AI (OpenAI API)
- Reactive Streaming: Project Reactor
- Build Tool: Maven
Configure your OpenAI API key and AI options in application.properties:
spring.application.name=gen-ai-demo
spring.ai.openai.api-key=${OPENAI_API_KEY}
spring.ai.openai.chat.options.model=gpt-4.1
server.port=8899
logging.level.org.springframework.ai.chat.client.advisor=DEBUGReplace ${OPENAI_API_KEY} with your OpenAI API key.
-
GET /chat?query=Hello– Chat with AI using simple messages. -
GET /askAgent?query=Listtop 5 action movies` – Get structured AI responses as MovieList.
GET /generateImage?prompt=A futuristic city skyline– Returns a generated image URL.
-
GET /describe– Describe a predefined image. -
GET /askImage?question=What does the handwriting say?– Query a predefined image. -
POST /getInfo– Upload an image and ask questions about it.
curl -F "file=@your-image.png" -F "question=What is in this image?" http://localhost:8899/getInfo
-
GET /stream?query=Tell me a story– Stream AI response in real-time. -
GET /nostream?query=Tell me a story– Receive AI response after full processing.
All AI requests and responses are logged for debugging:
logging.level.org.springframework.ai.chat.client.advisor=DEBUG
This project is for demonstration and learning purposes.
