# coze_ai **Repository Path**: lwrong/coze_ai ## Basic Information - **Project Name**: coze_ai - **Description**: 对接扣子开发 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-17 - **Last Updated**: 2026-04-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SmartOP AI Demo This project demonstrates how to integrate Spring Cloud and Nacos with a Spring Boot application. ## Prerequisites - Java 17 - Maven - Nacos Server (running on localhost:8848) ## Configuration 1. Start the Nacos server. 2. Update the `bootstrap.properties` file with your Nacos server address if it's not running on `localhost:8848`. ## Running the Application 1. Build the project: ``` mvn clean install ``` 2. Run the application: ``` mvn spring-boot:run ``` ### Using Docker 1. Build the Docker image: ``` docker build -t smartop-ai . ``` 2. Run the Docker container: ``` docker run -p 8080:8080 smartop-ai ``` ### Using Maven to build Docker image 1. Build the Docker image using Maven: ``` mvn clean package dockerfile:build ``` 2. Run the Docker container: ``` docker run -p 8080:8080 smartop-ai ``` ## Testing Once the application is running, you can access the following endpoints: - `/config`: Get configuration information from Nacos. - `/proxy/**`: Generic proxy endpoint for various API endpoints (supports POST, GET, and DELETE methods). - `/ai-proxy/**`: Enhanced proxy endpoint that supports POST, GET, and DELETE methods. It can automatically add default headers and choose to call ProxyController or directly request target API endpoints. To test the Nacos configuration, you can add a configuration in Nacos with the following details: - Data ID: `smartop-ai.yaml` - Group: `DEFAULT_GROUP` - Configuration Format: `YAML` - Configuration Content: ```yaml config: info: "This is a test configuration from Nacos" ai: proxy: authorization: "your-authorization-token" principal: "your-principal" credential: "your-credential" ``` Note: The `ai-apply-token` is now dynamically fetched from the token service using the `principal` and `credential`. You no longer need to configure it directly. To test the proxy endpoint, you can send requests to `/proxy/chat-messages` using different HTTP methods: - POST: For creating new resources - GET: For retrieving resources - DELETE: For deleting resources The proxy endpoint is now generic and can handle multiple API endpoints by mapping the path after `/proxy/` to the corresponding target API endpoint. For streaming responses, make sure to set the `response_mode` parameter to `streaming` in the request body. If the `conversation_id` is `undefined`, it will be removed from the request body before forwarding to the target API. To test the streaming response, you can use the `test-proxy.sh` script provided in the repository. You can also run the tests using the following command: ```bash mvn test ``` ## Error Handling The proxy endpoint will forward any error responses from the target API to the client. Make sure to handle these errors appropriately in your client application. The `WebClient` is configured to handle `WebClientResponseException` and forward the error response to the client. This ensures that any errors from the target API are properly propagated to the client. ## Streaming Response The proxy endpoint now uses `WebClient` to handle streaming responses from the target API. This allows for better performance and resource utilization when dealing with large responses. The `WebClient` is configured to use a `DataBuffer` to stream the response body to the client. This is more efficient than using an `InputStream` and `OutputStream` because it avoids the need to buffer the entire response in memory. This is especially important for large responses, as it reduces memory usage and improves performance. To avoid `ReadOnlyBufferException` when processing the response, the implementation creates a copy of the buffer data before writing it to the servlet response output stream. ## Dependencies - `spring-boot-starter-webflux` (Spring Boot 3.2.5) - `spring-boot-starter-reactor-netty` (Spring Boot 3.2.5) - `spring-ai-starter-model-openai` (Spring AI 1.0.1) - `spring-cloud-starter-openfeign` (Spring Cloud 2023.0.3) - `spring-cloud-starter-loadbalancer` (Spring Cloud 2023.0.3)