# spring-ai-examples **Repository Path**: dino9527/spring-ai-examples ## Basic Information - **Project Name**: spring-ai-examples - **Description**: Spring AI 示例 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 6 - **Forks**: 3 - **Created**: 2024-10-28 - **Last Updated**: 2025-06-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: SpringAI, SpringBoot, chat, QianFan, MCP ## README # Spring AI with QIANFAN This project is a Spring Boot application that demonstrates the integration of an AI chat client using the Spring AI framework. The application provides several endpoints to interact with the AI chat client. ## Project Structure - **Java**: The primary programming language used. - **Maven**: Build and dependency management tool. - **Spring Boot**: Framework for building the application. ## Configuration ### `application.yml` The `application.yml` file contains the configuration for the server and the AI chat client, including retry settings and API keys. ```yaml server: port: 8888 spring: ai: retry: max-attempts: 3 backoff: initial-interval: 5000ms multiplier: 5 max-interval: 180000ms on-client-errors: true qianfan: api-key: YOUR_API_KEY secret-key: YOUR_SECRET_KEY chat: enabled: true options: model: yi_34b_chat temperature: 0.7 top-p: 0.9 ``` ## Endpoints ### `/chat/ai/simple` Returns a simple chat completion. - **Method**: GET - **Parameters**: `message` (default: "给我讲个笑话") - **Response**: JSON with the completion message. ### `/chat/ai/simple2` Returns a chat completion with a specified voice. - **Method**: GET - **Parameters**: `message` (default: "给我讲个笑话"), `voice` - **Response**: JSON with the completion message. ### `/chat/ai/stream` Streams the chat completion. - **Method**: GET - **Parameters**: `message` (default: "给我讲个笑话"), `voice` - **Response**: Text event stream. ### `/chat/ai/actor` Generates the filmography for a random actor. - **Method**: GET - **Parameters**: `message` (default: "Generate the filmography for a random actor") - **Response**: JSON with the actor's filmography. ### `/chat/ai/actor2` Generates the filmography of 5 movies for Tom Hanks and Bill Murray. - **Method**: GET - **Parameters**: `message` (default: "Generate the filmography of 5 movies for Tom Hanks and Bill Murray.") - **Response**: JSON with the filmographies. ### `/chat/ai/actor3` Generates the filmography for a random actor with a custom format. - **Method**: GET - **Parameters**: `message` (default: "Generate the filmography for a random actor.") - **Response**: JSON with the actor's filmography. ### `/chat/ai/context` Maintains a conversation context with the AI. - **Method**: GET - **Parameters**: `prompt` - **Response**: The AI's response message. ## Running the Application 1. Clone the repository. 2. Update the `application.yml` file with your API key and secret key. 3. Build the project using Maven: ```sh mvn clean install ``` 4. Run the application: ```sh mvn spring-boot:run ``` ## License This project is licensed under the MIT License.