diff --git a/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/ModelConfig.java b/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/ModelConfig.java index ccbb9ac17..0da988f19 100644 --- a/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/ModelConfig.java +++ b/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/ModelConfig.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.ai.model; import java.time.Duration; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; /** * 模型配置信息 @@ -15,6 +16,8 @@ public class ModelConfig { protected String apiUrl; + protected String endPoint; + protected String apiKey; protected String provider; @@ -23,7 +26,38 @@ public class ModelConfig { protected Duration timeout = Duration.ofSeconds(60); - protected final Map headersConfig = new LinkedHashMap<>(); + protected Map headersConfig = new LinkedHashMap<>(); + + public ModelConfig() { + } + + public ModelConfig( + String apiUrl, + String endPoint, + String apiKey, + String provider, + String model, + Duration timeout, + Map headersConfig + ) { + this.apiUrl = apiUrl; + this.endPoint = endPoint; + this.apiKey = apiKey; + this.provider = provider; + this.model = model; + this.timeout = timeout; + this.headersConfig = headersConfig; + } + + protected ModelConfig(Builder builder) { + this.apiUrl = builder.apiUrl; + this.endPoint = builder.endPoint; + this.apiKey = builder.apiKey; + this.provider = builder.provider; + this.model = builder.model; + this.timeout = builder.timeout; + this.headersConfig.putAll(builder.headersConfig); + } public String getApiUrl() { return apiUrl; @@ -33,6 +67,14 @@ public class ModelConfig { this.apiUrl = apiUrl; } + public String getEndPoint() { + return endPoint; + } + + public void setEndPoint(String endPoint) { + this.endPoint = endPoint; + } + public String getApiKey() { return apiKey; } @@ -76,4 +118,68 @@ public class ModelConfig { public void removeHeader(String key) { this.headersConfig.remove(key); } + + public Builder builder() { + return new Builder(); + } + + public static class Builder { + protected String apiUrl; + + protected String endPoint; + + protected String apiKey; + + protected String provider; + + protected String model; + + protected Duration timeout = Duration.ofSeconds(60); + + protected Map headersConfig = new LinkedHashMap<>(); + + public Builder apiUrl(String apiUrl) { + this.apiUrl = apiUrl; + return this; + } + + public Builder endPoint(String endPoint) { + this.endPoint = endPoint; + return this; + } + + public Builder apiKey(String apiKey) { + this.apiKey = apiKey; + return this; + } + + public Builder provider(String provider) { + this.provider = provider; + return this; + } + + public Builder model(String model) { + this.model = model; + return this; + } + + public Builder timeout(Duration timeout) { + this.timeout = timeout; + return this; + } + + public Builder headersConfig(Map headersConfig) { + this.headersConfig = headersConfig; + return this; + } + + public ModelConfig build() { + Objects.requireNonNull(apiUrl, "API URL must not be null"); + Objects.requireNonNull(endPoint, "End Point must not be null"); + Objects.requireNonNull(apiKey, "API Key must not be null"); + Objects.requireNonNull(provider, "Provider must not be null"); + Objects.requireNonNull(model, "Model must not be null"); + return new ModelConfig(this); + } + } } diff --git a/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/chat/entity/ChatConfig.java b/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/chat/entity/ChatConfig.java index c78cbc4fe..cee80fe05 100644 --- a/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/chat/entity/ChatConfig.java +++ b/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/model/chat/entity/ChatConfig.java @@ -2,6 +2,9 @@ package com.yomahub.liteflow.ai.model.chat.entity; import com.yomahub.liteflow.ai.model.ModelConfig; +import java.time.Duration; +import java.util.Map; + /** * 对话配置信息 * @@ -11,7 +14,28 @@ import com.yomahub.liteflow.ai.model.ModelConfig; public class ChatConfig extends ModelConfig { - private boolean autoToolCallEnabled; + private boolean autoToolCallEnabled = true; + + public ChatConfig() {} + + public ChatConfig( + String apiUrl, + String endPoint, + String apiKey, + String provider, + String model, + Duration timeout, + Map headersConfig, + boolean autoToolCallEnabled + ) { + super(apiUrl, endPoint, apiKey, provider, model, timeout, headersConfig); + this.autoToolCallEnabled = autoToolCallEnabled; + } + + private ChatConfig(Builder builder) { + super(builder); + this.autoToolCallEnabled = builder.autoToolCallEnabled; + } public boolean isAutoToolCallEnabled() { return autoToolCallEnabled; @@ -21,4 +45,17 @@ public class ChatConfig extends ModelConfig { this.autoToolCallEnabled = autoToolCallEnabled; } + public static class Builder extends ModelConfig.Builder { + private boolean autoToolCallEnabled; + + public Builder autoToolCallEnabled(boolean autoToolCallEnabled) { + this.autoToolCallEnabled = autoToolCallEnabled; + return this; + } + + @Override + public ChatConfig build() { + return new ChatConfig(this); + } + } }