Commit cc35749d0b5ddfbcbe5615322ad6a684eb7e0742
1 parent
9fe1ce8e
chore:spring ai from 1.0.1 to 1.1.0
Showing
6 changed files
with
28 additions
and
18 deletions
yudao-module-ai/pom.xml
| @@ -19,9 +19,9 @@ | @@ -19,9 +19,9 @@ | ||
| 19 | 国外:OpenAI、Ollama、Midjourney、StableDiffusion、Suno | 19 | 国外:OpenAI、Ollama、Midjourney、StableDiffusion、Suno |
| 20 | </description> | 20 | </description> |
| 21 | <properties> | 21 | <properties> |
| 22 | - <spring-ai.version>1.0.1</spring-ai.version> | ||
| 23 | - <alibaba-ai.version>1.0.0.3</alibaba-ai.version> | ||
| 24 | - <tinyflow.version>1.0.2</tinyflow.version> | 22 | + <spring-ai.version>1.1.0</spring-ai.version> |
| 23 | + <alibaba-ai.version>1.0.0.4</alibaba-ai.version> | ||
| 24 | + <tinyflow.version>1.2.6</tinyflow.version> | ||
| 25 | </properties> | 25 | </properties> |
| 26 | 26 | ||
| 27 | <dependencies> | 27 | <dependencies> |
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/AiModelFactoryImpl.java
| @@ -87,7 +87,7 @@ import org.springframework.ai.model.zhipuai.autoconfigure.ZhiPuAiImageAutoConfig | @@ -87,7 +87,7 @@ import org.springframework.ai.model.zhipuai.autoconfigure.ZhiPuAiImageAutoConfig | ||
| 87 | import org.springframework.ai.ollama.OllamaChatModel; | 87 | import org.springframework.ai.ollama.OllamaChatModel; |
| 88 | import org.springframework.ai.ollama.OllamaEmbeddingModel; | 88 | import org.springframework.ai.ollama.OllamaEmbeddingModel; |
| 89 | import org.springframework.ai.ollama.api.OllamaApi; | 89 | import org.springframework.ai.ollama.api.OllamaApi; |
| 90 | -import org.springframework.ai.ollama.api.OllamaOptions; | 90 | +import org.springframework.ai.ollama.api.OllamaEmbeddingOptions; |
| 91 | import org.springframework.ai.openai.OpenAiChatModel; | 91 | import org.springframework.ai.openai.OpenAiChatModel; |
| 92 | import org.springframework.ai.openai.OpenAiEmbeddingModel; | 92 | import org.springframework.ai.openai.OpenAiEmbeddingModel; |
| 93 | import org.springframework.ai.openai.OpenAiEmbeddingOptions; | 93 | import org.springframework.ai.openai.OpenAiEmbeddingOptions; |
| @@ -436,10 +436,12 @@ public class AiModelFactoryImpl implements AiModelFactory { | @@ -436,10 +436,12 @@ public class AiModelFactoryImpl implements AiModelFactory { | ||
| 436 | * 可参考 {@link ZhiPuAiChatAutoConfiguration} 的 zhiPuAiChatModel 方法 | 436 | * 可参考 {@link ZhiPuAiChatAutoConfiguration} 的 zhiPuAiChatModel 方法 |
| 437 | */ | 437 | */ |
| 438 | private ZhiPuAiChatModel buildZhiPuChatModel(String apiKey, String url) { | 438 | private ZhiPuAiChatModel buildZhiPuChatModel(String apiKey, String url) { |
| 439 | - ZhiPuAiApi zhiPuAiApi = StrUtil.isEmpty(url) ? new ZhiPuAiApi(apiKey) | ||
| 440 | - : new ZhiPuAiApi(url, apiKey); | 439 | + ZhiPuAiApi.Builder zhiPuAiApiBuilder = ZhiPuAiApi.builder().apiKey(apiKey); |
| 440 | + if (StrUtil.isNotEmpty(url)) { | ||
| 441 | + zhiPuAiApiBuilder.baseUrl(url); | ||
| 442 | + } | ||
| 441 | ZhiPuAiChatOptions options = ZhiPuAiChatOptions.builder().model(ZhiPuAiApi.DEFAULT_CHAT_MODEL).temperature(0.7).build(); | 443 | ZhiPuAiChatOptions options = ZhiPuAiChatOptions.builder().model(ZhiPuAiApi.DEFAULT_CHAT_MODEL).temperature(0.7).build(); |
| 442 | - return new ZhiPuAiChatModel(zhiPuAiApi, options, getToolCallingManager(), DEFAULT_RETRY_TEMPLATE, | 444 | + return new ZhiPuAiChatModel(zhiPuAiApiBuilder.build(), options, getToolCallingManager(), DEFAULT_RETRY_TEMPLATE, |
| 443 | getObservationRegistry().getIfAvailable()); | 445 | getObservationRegistry().getIfAvailable()); |
| 444 | } | 446 | } |
| 445 | 447 | ||
| @@ -601,10 +603,12 @@ public class AiModelFactoryImpl implements AiModelFactory { | @@ -601,10 +603,12 @@ public class AiModelFactoryImpl implements AiModelFactory { | ||
| 601 | * 可参考 {@link ZhiPuAiEmbeddingAutoConfiguration} 的 zhiPuAiEmbeddingModel 方法 | 603 | * 可参考 {@link ZhiPuAiEmbeddingAutoConfiguration} 的 zhiPuAiEmbeddingModel 方法 |
| 602 | */ | 604 | */ |
| 603 | private ZhiPuAiEmbeddingModel buildZhiPuEmbeddingModel(String apiKey, String url, String model) { | 605 | private ZhiPuAiEmbeddingModel buildZhiPuEmbeddingModel(String apiKey, String url, String model) { |
| 604 | - ZhiPuAiApi zhiPuAiApi = StrUtil.isEmpty(url) ? new ZhiPuAiApi(apiKey) | ||
| 605 | - : new ZhiPuAiApi(url, apiKey); | 606 | + ZhiPuAiApi.Builder zhiPuAiApiBuilder = ZhiPuAiApi.builder().apiKey(apiKey); |
| 607 | + if (StrUtil.isNotEmpty(url)) { | ||
| 608 | + zhiPuAiApiBuilder.baseUrl(url); | ||
| 609 | + } | ||
| 606 | ZhiPuAiEmbeddingOptions zhiPuAiEmbeddingOptions = ZhiPuAiEmbeddingOptions.builder().model(model).build(); | 610 | ZhiPuAiEmbeddingOptions zhiPuAiEmbeddingOptions = ZhiPuAiEmbeddingOptions.builder().model(model).build(); |
| 607 | - return new ZhiPuAiEmbeddingModel(zhiPuAiApi, MetadataMode.EMBED, zhiPuAiEmbeddingOptions); | 611 | + return new ZhiPuAiEmbeddingModel(zhiPuAiApiBuilder.build(), MetadataMode.EMBED, zhiPuAiEmbeddingOptions); |
| 608 | } | 612 | } |
| 609 | 613 | ||
| 610 | /** | 614 | /** |
| @@ -632,7 +636,7 @@ public class AiModelFactoryImpl implements AiModelFactory { | @@ -632,7 +636,7 @@ public class AiModelFactoryImpl implements AiModelFactory { | ||
| 632 | 636 | ||
| 633 | private OllamaEmbeddingModel buildOllamaEmbeddingModel(String url, String model) { | 637 | private OllamaEmbeddingModel buildOllamaEmbeddingModel(String url, String model) { |
| 634 | OllamaApi ollamaApi = OllamaApi.builder().baseUrl(url).build(); | 638 | OllamaApi ollamaApi = OllamaApi.builder().baseUrl(url).build(); |
| 635 | - OllamaOptions ollamaOptions = OllamaOptions.builder().model(model).build(); | 639 | + OllamaEmbeddingOptions ollamaOptions = OllamaEmbeddingOptions.builder().model(model).build(); |
| 636 | return OllamaEmbeddingModel.builder() | 640 | return OllamaEmbeddingModel.builder() |
| 637 | .ollamaApi(ollamaApi) | 641 | .ollamaApi(ollamaApi) |
| 638 | .defaultOptions(ollamaOptions) | 642 | .defaultOptions(ollamaOptions) |
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/security/config/SecurityConfiguration.java
| @@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.ai.framework.security.config; | @@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.ai.framework.security.config; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; | 3 | import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; |
| 4 | import jakarta.annotation.Resource; | 4 | import jakarta.annotation.Resource; |
| 5 | -import org.springframework.ai.mcp.server.autoconfigure.McpServerProperties; | 5 | +import org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerSseProperties; |
| 6 | +import org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerStreamableHttpProperties; | ||
| 6 | import org.springframework.context.annotation.Bean; | 7 | import org.springframework.context.annotation.Bean; |
| 7 | import org.springframework.context.annotation.Configuration; | 8 | import org.springframework.context.annotation.Configuration; |
| 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; | 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| @@ -17,7 +18,9 @@ import java.util.Optional; | @@ -17,7 +18,9 @@ import java.util.Optional; | ||
| 17 | public class SecurityConfiguration { | 18 | public class SecurityConfiguration { |
| 18 | 19 | ||
| 19 | @Resource | 20 | @Resource |
| 20 | - private Optional<McpServerProperties> serverProperties; | 21 | + private Optional<McpServerSseProperties> mcpServerSseProperties; |
| 22 | + @Resource | ||
| 23 | + private Optional<McpServerStreamableHttpProperties> mcpServerStreamableHttpProperties; | ||
| 21 | 24 | ||
| 22 | @Bean("aiAuthorizeRequestsCustomizer") | 25 | @Bean("aiAuthorizeRequestsCustomizer") |
| 23 | public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { | 26 | public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { |
| @@ -25,11 +28,12 @@ public class SecurityConfiguration { | @@ -25,11 +28,12 @@ public class SecurityConfiguration { | ||
| 25 | 28 | ||
| 26 | @Override | 29 | @Override |
| 27 | public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) { | 30 | public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) { |
| 28 | - // MCP Server | ||
| 29 | - serverProperties.ifPresent(properties -> { | 31 | + mcpServerSseProperties.ifPresent(properties -> { |
| 30 | registry.requestMatchers(properties.getSseEndpoint()).permitAll(); | 32 | registry.requestMatchers(properties.getSseEndpoint()).permitAll(); |
| 31 | registry.requestMatchers(properties.getSseMessageEndpoint()).permitAll(); | 33 | registry.requestMatchers(properties.getSseMessageEndpoint()).permitAll(); |
| 32 | }); | 34 | }); |
| 35 | + mcpServerStreamableHttpProperties.ifPresent(properties -> | ||
| 36 | + registry.requestMatchers(properties.getMcpEndpoint()).permitAll()); | ||
| 33 | } | 37 | } |
| 34 | 38 | ||
| 35 | }; | 39 | }; |
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/service/chat/AiChatMessageServiceImpl.java
| @@ -49,7 +49,7 @@ import org.springframework.ai.chat.model.StreamingChatModel; | @@ -49,7 +49,7 @@ import org.springframework.ai.chat.model.StreamingChatModel; | ||
| 49 | import org.springframework.ai.chat.prompt.ChatOptions; | 49 | import org.springframework.ai.chat.prompt.ChatOptions; |
| 50 | import org.springframework.ai.chat.prompt.Prompt; | 50 | import org.springframework.ai.chat.prompt.Prompt; |
| 51 | import org.springframework.ai.mcp.SyncMcpToolCallbackProvider; | 51 | import org.springframework.ai.mcp.SyncMcpToolCallbackProvider; |
| 52 | -import org.springframework.ai.mcp.client.autoconfigure.properties.McpClientCommonProperties; | 52 | +import org.springframework.ai.mcp.client.common.autoconfigure.properties.McpClientCommonProperties; |
| 53 | import org.springframework.ai.tool.ToolCallback; | 53 | import org.springframework.ai.tool.ToolCallback; |
| 54 | import org.springframework.ai.tool.resolution.ToolCallbackResolver; | 54 | import org.springframework.ai.tool.resolution.ToolCallbackResolver; |
| 55 | import org.springframework.beans.factory.annotation.Autowired; | 55 | import org.springframework.beans.factory.annotation.Autowired; |
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/util/AiUtils.java
| @@ -16,7 +16,7 @@ import org.springframework.ai.chat.prompt.ChatOptions; | @@ -16,7 +16,7 @@ import org.springframework.ai.chat.prompt.ChatOptions; | ||
| 16 | import org.springframework.ai.deepseek.DeepSeekAssistantMessage; | 16 | import org.springframework.ai.deepseek.DeepSeekAssistantMessage; |
| 17 | import org.springframework.ai.deepseek.DeepSeekChatOptions; | 17 | import org.springframework.ai.deepseek.DeepSeekChatOptions; |
| 18 | import org.springframework.ai.minimax.MiniMaxChatOptions; | 18 | import org.springframework.ai.minimax.MiniMaxChatOptions; |
| 19 | -import org.springframework.ai.ollama.api.OllamaOptions; | 19 | +import org.springframework.ai.ollama.api.OllamaChatOptions; |
| 20 | import org.springframework.ai.openai.OpenAiChatOptions; | 20 | import org.springframework.ai.openai.OpenAiChatOptions; |
| 21 | import org.springframework.ai.tool.ToolCallback; | 21 | import org.springframework.ai.tool.ToolCallback; |
| 22 | import org.springframework.ai.zhipuai.ZhiPuAiChatOptions; | 22 | import org.springframework.ai.zhipuai.ZhiPuAiChatOptions; |
| @@ -77,7 +77,7 @@ public class AiUtils { | @@ -77,7 +77,7 @@ public class AiUtils { | ||
| 77 | return AnthropicChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) | 77 | return AnthropicChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) |
| 78 | .toolCallbacks(toolCallbacks).toolContext(toolContext).build(); | 78 | .toolCallbacks(toolCallbacks).toolContext(toolContext).build(); |
| 79 | case OLLAMA: | 79 | case OLLAMA: |
| 80 | - return OllamaOptions.builder().model(model).temperature(temperature).numPredict(maxTokens) | 80 | + return OllamaChatOptions.builder().model(model).temperature(temperature).numPredict(maxTokens) |
| 81 | .toolCallbacks(toolCallbacks).toolContext(toolContext).build(); | 81 | .toolCallbacks(toolCallbacks).toolContext(toolContext).build(); |
| 82 | default: | 82 | default: |
| 83 | throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform)); | 83 | throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform)); |
yudao-server/src/main/resources/application.yaml
| @@ -211,6 +211,8 @@ spring: | @@ -211,6 +211,8 @@ spring: | ||
| 211 | filesystem: | 211 | filesystem: |
| 212 | url: http://127.0.0.1:8089 | 212 | url: http://127.0.0.1:8089 |
| 213 | sse-endpoint: /sse | 213 | sse-endpoint: /sse |
| 214 | + annotation-scanner: | ||
| 215 | + enabled: false # TODO @芋艿:有 bug https://github.com/spring-projects/spring-ai/issues/4917 需要官方修复 | ||
| 214 | 216 | ||
| 215 | yudao: | 217 | yudao: |
| 216 | ai: | 218 | ai: |