CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework-ai--spring-ai-spring-boot-autoconfigure

Spring AI Spring Boot Auto Configuration modules providing automatic setup for AI models, vector stores, MCP, and retry capabilities

Overview
Eval results
Files

quick-start.mddocs/guides/

Quick Start Guide

Get started with Spring AI Spring Boot Auto Configuration in 5 minutes.

Prerequisites

  • Java 17 or later
  • Spring Boot 3.0 or later
  • Maven or Gradle

Step 1: Add Dependencies

Add the Spring AI starter dependency for your chosen provider:

OpenAI

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
    <version>1.1.2</version>
</dependency>

Anthropic

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-anthropic-spring-boot-starter</artifactId>
    <version>1.1.2</version>
</dependency>

Azure OpenAI

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
    <version>1.1.2</version>
</dependency>

Step 2: Configure Properties

Add configuration to application.properties:

OpenAI

spring.ai.openai.api-key=${OPENAI_API_KEY}
spring.ai.openai.chat.options.model=gpt-4
spring.ai.openai.chat.options.temperature=0.7

Anthropic

spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
spring.ai.anthropic.chat.options.model=claude-3-5-sonnet-20241022
spring.ai.anthropic.chat.options.temperature=0.7

Azure OpenAI

spring.ai.azure.openai.api-key=${AZURE_OPENAI_API_KEY}
spring.ai.azure.openai.endpoint=https://your-resource.openai.azure.com
spring.ai.azure.openai.chat.options.deployment-name=gpt-4

Step 3: Create a Service

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.stereotype.Service;

@Service
public class ChatService {
    private final ChatModel chatModel;
    
    public ChatService(ChatModel chatModel) {
        this.chatModel = chatModel;
    }
    
    public String chat(String message) {
        return chatModel.call(message);
    }
}

Step 4: Use the Service

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class ChatRunner implements CommandLineRunner {
    private final ChatService chatService;
    
    public ChatRunner(ChatService chatService) {
        this.chatService = chatService;
    }
    
    @Override
    public void run(String... args) {
        String response = chatService.chat("What is Spring AI?");
        System.out.println("Response: " + response);
    }
}

Step 5: Run Your Application

./mvnw spring-boot:run

Next Steps

Add Chat Memory

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
    <version>1.1.2</version>
</dependency>
spring.ai.chat.memory.repository.jdbc.initialize-schema=always

Add Vector Store

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
    <version>1.1.2</version>
</dependency>
spring.ai.vectorstore.pgvector.initialize-schema=true
spring.ai.vectorstore.pgvector.index-type=HNSW
spring.datasource.url=jdbc:postgresql://localhost:5432/vectordb

Enable Retry

spring.ai.retry.max-attempts=5
spring.ai.retry.backoff.initial-interval=1s
spring.ai.retry.backoff.multiplier=2

Enable Observations

spring.ai.chat.observations.log-prompt=true
management.metrics.export.prometheus.enabled=true
management.tracing.enabled=true

Common Issues

API Key Not Found

Ensure your API key is set in environment variables:

export OPENAI_API_KEY=your-key

Connection Timeout

Increase the request timeout:

spring.ai.openai.chat.options.timeout=60s

Rate Limiting

Configure retry for rate limits:

spring.ai.retry.on-http-codes=429
spring.ai.retry.max-attempts=10

Further Reading

  • Configuration Properties Reference
  • Provider API Reference
  • Real-World Scenarios

Install with Tessl CLI

npx tessl i tessl/maven-org-springframework-ai--spring-ai-spring-boot-autoconfigure

docs

index.md

tile.json