7 小时以前 9bad721754fe8bbe2e5f459d0706e0fefac569f3
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/config/AiAutoConfiguration.java
@@ -13,15 +13,14 @@
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.openai.OpenAiEmbeddingOptions;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.ai.tokenizer.JTokkitTokenCountEstimator;
import org.springframework.ai.tokenizer.TokenCountEstimator;
import org.springframework.ai.vectorstore.qdrant.autoconfigure.QdrantVectorStoreProperties;
import org.springframework.ai.vectorstore.redis.autoconfigure.RedisVectorStoreProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import java.time.Duration;
/**
 * 超级管理员 AI 自动配置
@@ -30,11 +29,7 @@
 * 向量库配置见 yudao.ai.vector-store 节点,不再依赖 Spring AI 的 Milvus 自动配置属性
 */
@Configuration
@EnableConfigurationProperties({
        YudaoAiProperties.class,
        QdrantVectorStoreProperties.class,
        RedisVectorStoreProperties.class
})
@EnableConfigurationProperties(YudaoAiProperties.class)
@Slf4j
public class AiAutoConfiguration {
@@ -65,13 +60,25 @@
    // ========== 通义千问 Chat(通过 OpenAI 兼容接口)==========
    public static OpenAiChatModel buildTongYiChatModel(String apiKey, String model) {
    /**
     * 构建通义千问 Chat 模型
     *
     * @param temperature 采样温度,为 null 时用 0.7(与历史行为一致)
     * @param maxTokens   单次回复的最大 token 数,为 null 时沿用模型默认值。
     *                    不传会让长文档的输出被静默截断,表现为「JSON 尾部缺失、解析失败」
     * @param timeout     单次调用超时。不设超时的话,模型排队时请求会一直挂到 TCP 层超时
     */
    public static OpenAiChatModel buildTongYiChatModel(String apiKey, String model,
                                                       Double temperature, Integer maxTokens,
                                                       Duration timeout) {
        return OpenAiChatModel.builder()
                .options(OpenAiChatOptions.builder()
                        .baseUrl(DASHSCOPE_BASE_URL)
                        .apiKey(apiKey)
                        .model(StrUtil.blankToDefault(model, "qwen-plus"))
                        .temperature(0.7)
                        .temperature(temperature != null ? temperature : 0.7)
                        .maxTokens(maxTokens)
                        .timeout(timeout)
                        .build())
                .toolCallingManager(ToolCallingManager.builder().build())
                .build();