mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-12 19:31:04 +08:00
feat(react-agent-dashscope): add DashScope entry and DashScopeSpec
DashScope.of(modelName) returns DashScopeSpec with a thinking sub-builder using DashScope's native budget term. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.yomahub.liteflow.agent.dashscope;
|
||||
|
||||
public final class DashScope {
|
||||
private DashScope() {}
|
||||
public static DashScopeSpec of(String modelName) {
|
||||
return new DashScopeSpec(modelName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.yomahub.liteflow.agent.dashscope;
|
||||
|
||||
import com.yomahub.liteflow.agent.model.CredentialResolver;
|
||||
import com.yomahub.liteflow.agent.model.ModelSpec;
|
||||
import com.yomahub.liteflow.property.agent.AgentConfig;
|
||||
import com.yomahub.liteflow.property.agent.PlatformCredential;
|
||||
import io.agentscope.core.model.DashScopeChatModel;
|
||||
import io.agentscope.core.model.GenerateOptions;
|
||||
import io.agentscope.core.model.Model;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DashScopeSpec extends ModelSpec<DashScopeSpec> {
|
||||
|
||||
private final String modelName;
|
||||
private Integer thinkingBudget;
|
||||
|
||||
public DashScopeSpec(String modelName) { this.modelName = modelName; }
|
||||
|
||||
public DashScopeSpec thinking(Consumer<DashScopeThinking> c) {
|
||||
DashScopeThinking t = new DashScopeThinking();
|
||||
c.accept(t);
|
||||
this.thinkingBudget = t.getBudget();
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getModelName() { return modelName; }
|
||||
public Integer getThinkingBudget() { return thinkingBudget; }
|
||||
|
||||
@Override
|
||||
public Model resolve(AgentConfig cfg) {
|
||||
PlatformCredential cred = CredentialResolver.requireFirstClass(
|
||||
cfg.getDashscope(), "liteflow.agent.dashscope");
|
||||
|
||||
DashScopeChatModel.Builder builder = DashScopeChatModel.builder()
|
||||
.apiKey(cred.getApiKey())
|
||||
.modelName(modelName);
|
||||
GenerateOptions options = buildGenerateOptions();
|
||||
if (options != null) {
|
||||
builder.defaultOptions(options);
|
||||
}
|
||||
if (getStream() != null) {
|
||||
builder.stream(getStream());
|
||||
}
|
||||
if (thinkingBudget != null) {
|
||||
builder.enableThinking(true);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private GenerateOptions buildGenerateOptions() {
|
||||
if (getTemperature() == null && getTopP() == null && getTopK() == null
|
||||
&& getMaxTokens() == null && getSeed() == null
|
||||
&& getCacheControl() == null && thinkingBudget == null) {
|
||||
return null;
|
||||
}
|
||||
GenerateOptions.Builder b = GenerateOptions.builder();
|
||||
if (getTemperature() != null) b.temperature(getTemperature());
|
||||
if (getTopP() != null) b.topP(getTopP());
|
||||
if (getTopK() != null) b.topK(getTopK());
|
||||
if (getMaxTokens() != null) b.maxTokens(getMaxTokens());
|
||||
if (getSeed() != null) b.seed(getSeed());
|
||||
if (getCacheControl() != null) b.cacheControl(getCacheControl());
|
||||
if (thinkingBudget != null) b.thinkingBudget(thinkingBudget);
|
||||
return b.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.yomahub.liteflow.agent.dashscope;
|
||||
|
||||
/** DashScope(通义千问)thinking 子构建器,沿用 thinking_budget 术语。 */
|
||||
public final class DashScopeThinking {
|
||||
private Integer budget;
|
||||
|
||||
public DashScopeThinking budget(int tokens) { this.budget = tokens; return this; }
|
||||
public Integer getBudget() { return budget; }
|
||||
}
|
||||
Reference in New Issue
Block a user