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 | 19 | 国外:OpenAI、Ollama、Midjourney、StableDiffusion、Suno |
| 20 | 20 | </description> |
| 21 | 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 | 25 | </properties> |
| 26 | 26 | |
| 27 | 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 | 87 | import org.springframework.ai.ollama.OllamaChatModel; |
| 88 | 88 | import org.springframework.ai.ollama.OllamaEmbeddingModel; |
| 89 | 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 | 91 | import org.springframework.ai.openai.OpenAiChatModel; |
| 92 | 92 | import org.springframework.ai.openai.OpenAiEmbeddingModel; |
| 93 | 93 | import org.springframework.ai.openai.OpenAiEmbeddingOptions; |
| ... | ... | @@ -436,10 +436,12 @@ public class AiModelFactoryImpl implements AiModelFactory { |
| 436 | 436 | * 可参考 {@link ZhiPuAiChatAutoConfiguration} 的 zhiPuAiChatModel 方法 |
| 437 | 437 | */ |
| 438 | 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 | 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 | 445 | getObservationRegistry().getIfAvailable()); |
| 444 | 446 | } |
| 445 | 447 | |
| ... | ... | @@ -601,10 +603,12 @@ public class AiModelFactoryImpl implements AiModelFactory { |
| 601 | 603 | * 可参考 {@link ZhiPuAiEmbeddingAutoConfiguration} 的 zhiPuAiEmbeddingModel 方法 |
| 602 | 604 | */ |
| 603 | 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 | 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 | 636 | |
| 633 | 637 | private OllamaEmbeddingModel buildOllamaEmbeddingModel(String url, String model) { |
| 634 | 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 | 640 | return OllamaEmbeddingModel.builder() |
| 637 | 641 | .ollamaApi(ollamaApi) |
| 638 | 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 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; |
| 4 | 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 | 7 | import org.springframework.context.annotation.Bean; |
| 7 | 8 | import org.springframework.context.annotation.Configuration; |
| 8 | 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| ... | ... | @@ -17,7 +18,9 @@ import java.util.Optional; |
| 17 | 18 | public class SecurityConfiguration { |
| 18 | 19 | |
| 19 | 20 | @Resource |
| 20 | - private Optional<McpServerProperties> serverProperties; | |
| 21 | + private Optional<McpServerSseProperties> mcpServerSseProperties; | |
| 22 | + @Resource | |
| 23 | + private Optional<McpServerStreamableHttpProperties> mcpServerStreamableHttpProperties; | |
| 21 | 24 | |
| 22 | 25 | @Bean("aiAuthorizeRequestsCustomizer") |
| 23 | 26 | public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { |
| ... | ... | @@ -25,11 +28,12 @@ public class SecurityConfiguration { |
| 25 | 28 | |
| 26 | 29 | @Override |
| 27 | 30 | public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) { |
| 28 | - // MCP Server | |
| 29 | - serverProperties.ifPresent(properties -> { | |
| 31 | + mcpServerSseProperties.ifPresent(properties -> { | |
| 30 | 32 | registry.requestMatchers(properties.getSseEndpoint()).permitAll(); |
| 31 | 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 | 49 | import org.springframework.ai.chat.prompt.ChatOptions; |
| 50 | 50 | import org.springframework.ai.chat.prompt.Prompt; |
| 51 | 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 | 53 | import org.springframework.ai.tool.ToolCallback; |
| 54 | 54 | import org.springframework.ai.tool.resolution.ToolCallbackResolver; |
| 55 | 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 | 16 | import org.springframework.ai.deepseek.DeepSeekAssistantMessage; |
| 17 | 17 | import org.springframework.ai.deepseek.DeepSeekChatOptions; |
| 18 | 18 | import org.springframework.ai.minimax.MiniMaxChatOptions; |
| 19 | -import org.springframework.ai.ollama.api.OllamaOptions; | |
| 19 | +import org.springframework.ai.ollama.api.OllamaChatOptions; | |
| 20 | 20 | import org.springframework.ai.openai.OpenAiChatOptions; |
| 21 | 21 | import org.springframework.ai.tool.ToolCallback; |
| 22 | 22 | import org.springframework.ai.zhipuai.ZhiPuAiChatOptions; |
| ... | ... | @@ -77,7 +77,7 @@ public class AiUtils { |
| 77 | 77 | return AnthropicChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) |
| 78 | 78 | .toolCallbacks(toolCallbacks).toolContext(toolContext).build(); |
| 79 | 79 | case OLLAMA: |
| 80 | - return OllamaOptions.builder().model(model).temperature(temperature).numPredict(maxTokens) | |
| 80 | + return OllamaChatOptions.builder().model(model).temperature(temperature).numPredict(maxTokens) | |
| 81 | 81 | .toolCallbacks(toolCallbacks).toolContext(toolContext).build(); |
| 82 | 82 | default: |
| 83 | 83 | throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform)); | ... | ... |
yudao-server/src/main/resources/application.yaml