A Spring Boot lab of a middleware service bridging users and LLMs.
AI Chat Service acts as a smart bridge between your frontend and LLM providers. It manages AI personalities, maintains per-session conversation memory, and exposes a clean REST API for chat interactions — all with built-in resilience via automatic retry.
| Feature | Description |
|---|---|
| 🤖 Multiple AI Personalities | Switch between Assistant, Coder, and Riddler |
| 💾 Session-Based Memory | Automatic conversation context management |
| 🔄 Automatic Retry | Exponential backoff for resilience |
| 📚 OpenAPI / Swagger UI | Interactive API documentation out of the box |
- Java 21+ (tested with Java 25)
- Maven 3.6+
- OpenRouter API key → Get one here
In IntelliJ IDEA:
- Go to
Run→Edit Configurations... - Select
AiLabApplication - Under Environment Variables, add:
OPENROUTER_API_KEY=your-api-key-here - Click
Apply→OK
Open AiLabApplication.java and click Run
The application starts on http://localhost:8080
http://localhost:8080/
Browser-based chat UI with automatic session management.
http://localhost:8080/swagger-ui/index.html
Interactive API documentation with a built-in test interface.
Request
{
"personality": "coder",
"messages": "How do I write a for-loop in Java?"
}Response
{
"reply": "A for-loop in Java looks like this: for(int i=0; i<10; i++){}",
"sessionId": "abc-123-def-456"
}| Value | Behavior |
|---|---|
assistant |
Helpful general-purpose assistant |
coder |
Programming teacher |
riddler |
Responds with riddles |
ai-lab/
├── src/main/java/org/example/ailab/
│ ├── controller/ # REST controllers
│ ├── service/ # Business logic & AI client
│ ├── dto/ # Data transfer objects
│ ├── configuration/ # Spring configuration
│ └── exception/ # Global exception handler
├── src/main/resources/
│ ├── application.properties # App configuration
│ └── static/ # Web files (index.html)
└── src/test/java/ # Tests