# SpringAI后端模板 **Repository Path**: PhiloKun/spring-ai-template ## Basic Information - **Project Name**: SpringAI后端模板 - **Description**: SpringAI模板 链接本地ollama - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2025-04-08 - **Last Updated**: 2025-08-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SpringAI后端模板 | Spring AI Template [中文](#chinese) | [English](#english) ## 中文 ### 介绍 这是一个SpringAI模板项目,可与本地Ollama进行集成,为AI应用开发提供基础框架。 ### 特性 - 集成本地Ollama AI模型 - 支持流式和非流式聊天响应 - 内存中的聊天历史管理 - 支持多会话ID - 简单的聊天日志系统 ### 环境要求 - Java 17或更高版本 - Spring Boot 3.x - 本地安装Ollama - Maven ### 项目结构 ``` src/main/java/com/zkz/springai/ ├── config/ │ ├── AIConfig.java # AI配置和Bean定义 │ └── MvcConfig.java # MVC配置 ├── controller/ │ └── ChatController.java # 聊天REST接口 └── SpringAiTemplateApplication.java ``` ### API接口 1. **基础聊天** - 接口:`GET /ai/chat` - 参数:`prompt`(查询参数) - 返回:单次响应字符串 2. **流式聊天** - 接口:`GET /ai/chat-stream` - 参数:`prompt`(查询参数) - 返回:流式响应 3. **带会话的流式聊天** - 接口:`GET /ai/chat-stream-id` - 参数: - `prompt`(查询参数) - `chatId`(查询参数) - 返回:带会话管理的流式响应 ### 配置说明 项目包含以下内置配置: - 带默认系统提示的聊天客户端 - 内存中的聊天历史存储 - 简单的日志记录器 - 消息聊天记忆管理器 ### 快速开始 1. 克隆仓库 2. 确保本地Ollama正在运行 3. 构建项目:`mvn clean install` 4. 运行应用:`mvn spring-boot:run` 5. 访问接口文档: - 文档地址:`http://localhost:8088/doc.html` - 使用 Knife4j 增强的 Swagger 文档界面 - 支持在线调试API接口 --- ## English ### Introduction This is a Spring AI template project that integrates with local Ollama for AI capabilities. It provides a foundation for building AI-powered applications using Spring Boot and Spring AI. ### Features - Integration with local Ollama AI model - Support for both streaming and non-streaming chat responses - In-memory chat history management - Conversation ID support for multiple chat sessions - Simple logging system for chat interactions ### Prerequisites - Java 17 or higher - Spring Boot 3.x - Local Ollama installation - Maven ### Project Structure ``` src/main/java/com/zkz/springai/ ├── config/ │ ├── AIConfig.java # AI configuration and beans │ └── MvcConfig.java # MVC configuration ├── controller/ │ └── ChatController.java # REST endpoints for chat └── SpringAiTemplateApplication.java ``` ### API Endpoints 1. **Basic Chat** - Endpoint: `GET /ai/chat` - Parameter: `prompt` (query parameter) - Returns: Single response string 2. **Streaming Chat** - Endpoint: `GET /ai/chat-stream` - Parameter: `prompt` (query parameter) - Returns: Streaming response 3. **Streaming Chat with Session** - Endpoint: `GET /ai/chat-stream-id` - Parameters: - `prompt` (query parameter) - `chatId` (query parameter) - Returns: Streaming response with session management ### Configuration The project includes built-in configurations for: - Chat client with default system prompt - In-memory chat history storage - Simple logging advisor - Message chat memory advisor ### Getting Started 1. Clone the repository 2. Ensure Ollama is running locally 3. Build the project: `mvn clean install` 4. Run the application: `mvn spring-boot:run` 5. Access API Documentation: - Documentation URL: `http://localhost:8088/doc.html` - Enhanced Swagger UI powered by Knife4j - Supports online API testing