Skip to content

sumanas27/smart-email-summarizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Email Summarizer

A Spring Boot application that uses Spring AI 1.0.0 and OpenAI to intelligently summarize email content with configurable prompt templates.

Features

  • Configurable Prompts: Easily customizable prompt templates
  • REST API: Simple HTTP endpoints for email summarization
  • Validation: Input validation for email content
  • Structured Format: All summaries formatted with "Summary:" header and bullet points

Technology Stack

  • Spring Boot 3.5.0
  • Spring AI 1.0.0
  • OpenAI GPT-4o-mini
  • Java 21
  • Maven

Project Structure

smart-email-summarizer/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com.example.emailsummarizer/
│   │   │       ├── controller/
│   │   │       │   └── EmailSummarizerController.java
│   │   │       ├── config/
│   │   │       │   └── PromptConfig.java
│   │   │       ├── model/
│   │   │       │   └── EmailRequest.java
│   │   │       └── EmailSummarizerApplication.java
│   │   └── resources/
│   │       └── application.yml
└── pom.xml

Major Changes in Spring AI 1.0.0

  1. ChatClient API: New fluent ChatClient.Builder pattern replaces the old ChatClient
  2. Message Structure: Updated to use UserMessage classes
  3. Prompt Building: Enhanced Prompt class with List of messages
  4. Method Chaining: New fluent API with .prompt().call().content() pattern
  5. Spring Boot 3.3.0: Updated to latest Spring Boot version
  6. Java 21: Updated to use Java 21 for better performance
  7. GPT-4o-mini: Updated to use the latest OpenAI model

Setup Instructions

Prerequisites

  1. Java 21 or higher
  2. Maven 3.8+
  3. OpenAI API Key

Installation

  1. Clone the repository

    git clone <repository-url>
    cd smart-email-summarizer
  2. Set up OpenAI API Key

    Option 1: Environment Variable

    export OPENAI_API_KEY=your-actual-openai-api-key

    Option 2: Update application.yml

    spring:
      ai:
        openai:
          api-key: your-actual-openai-api-key
  3. Build the project

    mvn clean install
  4. Run the application

    mvn spring-boot:run

The application will start on http://localhost:8080

API Endpoints

1. Summarize Email (Full Options)

POST /api/email/summarize

Request Body:

{
  "subject": "Q2 Revenue Forecast",
  "from": "[email protected]",
  "content": "Hi team, please find attached the latest projections for Q2. Revenue is expected to increase by 15% compared to Q1...",
}

Parameters:

  • subject (required): Email subject line
  • from (required): Sender's email address
  • content (required): The email content to summarize

Response:

{
  "summary": "Summary:\n• CEO shared Q2 revenue forecast\n• Projections indicate 15% growth compared to Q1\n• Detailed projections attached in document",
  "subject": "Q2 Revenue Forecast",
  "from": "[email protected]"
}

Usage Examples

Example 1: Summary

curl -X POST http://localhost:8080/api/email/summarize \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Q4 Budget Review",
    "from": "[email protected]",
    "content": "The Q4 budget review meeting is scheduled for next Friday at 2 PM. Please prepare your department budgets and expense reports. We need to finalize the numbers before the board meeting on Monday."
  }

Configuration

OpenAI Configuration

Customize OpenAI settings in application.yml:

spring:
  ai:
    openai:
      api-key: ${OPENAI_API_KEY}
      chat:
        options:
          model: gpt-4o-mini          # Latest OpenAI model
          temperature: 0.3            # Creativity level (0.0-1.0)
          max-tokens: 1000           # Response length limit
      base-url: https://api.openai.com

Available Models

  • gpt-4o-mini (recommended for cost efficiency)
  • gpt-4o
  • gpt-4-turbo
  • gpt-3.5-turbo

Spring AI 1.0.0 Migration Notes

Key API Changes:

  1. ChatClient Injection:

    @Autowired
    public EmailSummarizerController(ChatClient.Builder chatClientBuilder, PromptConfig promptConfig) {
        this.chatClient = chatClientBuilder.build();
    }
  2. Message Creation:

    Message userMessage = userPromptTemplate.createMessage(variables);
    Prompt prompt = new Prompt(List.of(userMessage));
  3. Chat Invocation:

    String summary = chatClient.prompt(prompt).call().content();

Development

Building for Production

mvn clean package
java -jar target/smart-email-summarizer-0.0.1-SNAPSHOT.jar

Testing

Run tests with:

mvn test

Troubleshooting

Common Issues

  1. Spring AI 1.0.0 Compatibility

    • Ensure you're using Spring Boot 3.3.0+
    • Java 21 is recommended for optimal performance
  2. OpenAI API Key Error

    • Verify your API key is valid and has sufficient credits
    • Check environment variable or application.yml configuration
  3. Model Availability

    • GPT-4o-mini is the default model for cost efficiency
    • Switch to GPT-4o for enhanced capabilities if needed

License

This project is licensed under the MIT License. Organized list format

  • Priority Modifiers: Additional context for high/low priority emails

OpenAI Configuration

Customize OpenAI settings in application.yml:

spring:
  ai:
    openai:
      api-key: ${OPENAI_API_KEY}
      chat:
        options:
          model: gpt-3.5-turbo        # or gpt-4
          temperature: 0.3            # creativity level (0.0-1.0)
          max-tokens: 1000           # response length limit

Testing

Run tests with:

mvn test

Building for Production

mvn clean package
java -jar target/smart-email-summarizer-0.0.1-SNAPSHOT.jar

Troubleshooting

Common Issues

  1. OpenAI API Key Error

    • Ensure your API key is valid and has sufficient credits
    • Check environment variable or application.yml configuration
  2. Connection Timeout

    • Verify internet connection
    • Check OpenAI service status
  3. Invalid Request Format

    • Ensure JSON is properly formatted
    • Check required fields are present

Logs

Application logs are written to:

  • Console output
  • logs/email-summarizer.log file

License

This project is licensed under the MIT License.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

For issues and questions, please create an issue in the repository or contact the owner.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages