AI Chatbot with Conversational Memory
Intelligent conversational AI system built with Spring Boot and Spring AI framework, featuring persistent memory for context retention across multiple interactions. Implements prompt engineering with custom templates and OpenAI GPT-4 integration for natural language understanding and generation.
The chatbot uses InMemoryChatMemory for maintaining conversation history and PromptChatMemoryAdvisor for context-aware responses. Features include template-based prompt engineering with StringTemplate format, ChatClient API for OpenAI interactions, and RESTful endpoints for seamless integration with frontend applications.
Developed with Spring Boot 3.3, Java 21, and Spring AI milestone releases. Implements advisor pattern for logging and memory management, record-based DTOs for immutability, and resource loading for prompt templates from classpath resources.
Key Features
- Conversational memory using InMemoryChatMemory for multi-turn dialogue continuity
- Prompt engineering with StringTemplate (.st) files for dynamic prompt generation
- OpenAI GPT-4 integration via Spring AI ChatClient with configurable model parameters
- PromptChatMemoryAdvisor for automatic context injection into AI requests
- SimpleLoggerAdvisor for request/response debugging and conversation tracking
- RESTful API with JSON request/response using Spring Web and Jackson
- Resource loading from classpath for externalized prompt template management
- Error handling with try-catch blocks and fallback responses for robustness
- Lombok integration for reduced boilerplate code with @RequiredArgsConstructor and @Slf4j