Skip to content

addee1/AdamAI-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AdamAI – AI Integrated Spring Boot Service

AdamAI is a Spring Boot based middleware service that acts as a bridge between a user and a Large Language Model (LLM) using OpenRouter AI.

The application supports:

  • AI personalities (helper, coder, pirate)
  • Session memory/context handling
  • Retry & exponential backoff for failed AI requests
  • Swagger/OpenAPI documentation
  • Global exception handling
  • Frontend chat interface
  • REST API communication

Features

AI Personalities

Users can choose between different personalities:

  • helper
  • coder
  • pirate

Each personality maps to a different system prompt before sending requests to the AI model.


Session Memory

The application stores conversation history in-memory using:

Map<String, List<AIMessage>>

This allows the AI to remember previous messages in the same conversation.


Retry & Exponential Backoff

Failed AI requests automatically retry using Spring Retry.

Implemented with:

@Retryable(
        retryFor = Exception.class,
        maxAttempts = 3,
        backoff = @Backoff(
                delay = 1000,
                multiplier = 2
        )
)

Retry functionality is enabled globally using:

@EnableRetry

This improves resilience when the AI service is temporarily unavailable.


Global Exception Handling

The application uses:

@ControllerAdvice

to return clean and user-friendly error responses.


Swagger / OpenAPI

API documentation is automatically generated using SpringDoc OpenAPI.

Swagger UI:

http://localhost:8080/swagger-ui.html

Technologies Used

  • Java 25
  • Spring Boot 4
  • Spring Web
  • Spring Validation
  • Spring Retry
  • OpenRouter AI
  • Swagger / OpenAPI
  • JUnit 5
  • Mockito
  • MockMvc
  • JaCoCo
  • HTML / CSS / JavaScript

Project Structure

src
├── client
├── controllers
├── DTO
├── exceptions
├── services
├── resources
│   ├── static
│   └── application.properties
└── test

API Endpoint

POST /api/v1/chat

Request Body

{
  "message": "Hello AI",
  "personality": "helper",
  "sessionId": "user-123"
}

Response

{
  "reply": "Hello! How can I help you today?"
}

Validation

The API validates incoming request bodies before processing them.

The application validates incoming requests using:

@NotBlank

If validation fails, the API returns:

400 Bad Request

Testing

The project includes:

  • Controller tests using MockMvc
  • Service layer unit tests
  • Validation tests
  • Global exception handler tests
  • AIClient personality tests
  • Mocked dependencies using Mockito
  • Spring Boot context loading tests

Code coverage is measured using JaCoCo.


Running the Application

1. Clone the repository

git clone https://github.com/addee1/AdamAI-chatbot.git

2. Configure Environment Variable

The application uses environment variables to securely manage the OpenRouter API key.

Inside:

src/main/resources/application.properties

the following property is already configured:

ai.api.key=${OPENROUTER_API_KEY:test-key}

Add your API key in IntelliJ IDEA

  1. Open:
Run → Edit Configurations
  1. Select the Spring Boot application

  2. Add the following environment variable:

OPENROUTER_API_KEY=your_api_key_here
  1. Save and run the application

3. Run the application

mvn spring-boot:run

Frontend

The application includes a custom frontend chat interface where users can:

  • send messages
  • choose AI personalities
  • maintain conversation memory
  • interact with the AI in real-time

Author

Built and designed by Adam Ottosson

Portfolio: https://adamottosson.se

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors