feat: 增加 system 消息格式配置
- 模型管理支持选择字符串或内容块数组格式 - 验证连接携带 system 消息并复用正式运行时模型配置 - 补充配置映射与验证消息角色测试
This commit is contained in:
@@ -3,6 +3,7 @@ package tech.easyflow.agent.runtime;
|
||||
import com.easyagents.agent.runtime.model.AgentHttpVersionPolicy;
|
||||
import com.easyagents.agent.runtime.model.AgentModelProviderType;
|
||||
import com.easyagents.agent.runtime.model.AgentModelSpec;
|
||||
import com.easyagents.agent.runtime.model.AgentSystemContentFormat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tech.easyflow.ai.entity.Model;
|
||||
@@ -60,6 +61,7 @@ public final class AgentModelSpecMapper {
|
||||
spec.setSupportImage(Boolean.TRUE.equals(model.getSupportImage()));
|
||||
spec.setSupportImageBase64Only(Boolean.TRUE.equals(model.getSupportImageB64Only()));
|
||||
spec.setHttpVersionPolicy(parseHttpVersionPolicy(model));
|
||||
spec.setSystemContentFormat(parseSystemContentFormat(model));
|
||||
spec.getMetadata().put("modelId", model.getId());
|
||||
if (providerType != null && !providerType.isBlank()) {
|
||||
spec.getMetadata().put("sourceProviderType", providerType);
|
||||
@@ -90,6 +92,29 @@ public final class AgentModelSpecMapper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析模型配置中的 Agent system content 格式。
|
||||
*
|
||||
* @param model 模型配置
|
||||
* @return system content 格式,缺失或非法时返回 STRING
|
||||
*/
|
||||
private static AgentSystemContentFormat parseSystemContentFormat(Model model) {
|
||||
Object rawFormat = model.getOptions() == null
|
||||
? null
|
||||
: model.getOptions().get("agentSystemContentFormat");
|
||||
if (rawFormat == null || String.valueOf(rawFormat).isBlank()) {
|
||||
return AgentSystemContentFormat.STRING;
|
||||
}
|
||||
String normalizedFormat = String.valueOf(rawFormat).trim().toUpperCase(Locale.ROOT);
|
||||
try {
|
||||
return AgentSystemContentFormat.valueOf(normalizedFormat);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
LOG.warn("Invalid Agent system content format '{}' for model {}, fallback to STRING",
|
||||
rawFormat, model.getId());
|
||||
return AgentSystemContentFormat.STRING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 AgentScope 支持的模型供应商类型。
|
||||
*
|
||||
|
||||
@@ -43,6 +43,8 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
||||
/** 为未识别关闭思考扩展参数的推理模型保留足够的小额输出预算。 */
|
||||
private static final int MAX_TOKENS = 256;
|
||||
private static final Duration DEFAULT_PHASE_TIMEOUT = Duration.ofSeconds(60);
|
||||
private static final String VERIFICATION_SYSTEM_PROMPT =
|
||||
"You are verifying model connectivity. Follow the user's instruction exactly.";
|
||||
|
||||
/** AgentScope 模型工厂。 */
|
||||
private final AgentModelFactory<io.agentscope.core.model.Model> modelFactory;
|
||||
@@ -128,7 +130,11 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
||||
generationOptions.setMaxTokens(MAX_TOKENS);
|
||||
io.agentscope.core.model.Model agentScopeModel = modelFactory.create(modelSpec, generationOptions);
|
||||
|
||||
Msg message = messageAdapter.toMsg(verificationMessage);
|
||||
List<Msg> messages = List.of(
|
||||
messageAdapter.toMsg(AgentMessage.text(
|
||||
AgentMessageRole.SYSTEM,
|
||||
VERIFICATION_SYSTEM_PROMPT)),
|
||||
messageAdapter.toMsg(verificationMessage));
|
||||
GenerateOptions requestOptions = GenerateOptions.builder()
|
||||
.stream(stream)
|
||||
.maxTokens(MAX_TOKENS)
|
||||
@@ -138,7 +144,7 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
||||
.build())
|
||||
.build();
|
||||
List<ChatResponse> responses = agentScopeModel
|
||||
.stream(List.of(message), List.of(), requestOptions)
|
||||
.stream(messages, List.of(), requestOptions)
|
||||
.timeout(phaseTimeout)
|
||||
.collectList()
|
||||
.block(phaseTimeout.plusSeconds(1));
|
||||
|
||||
Reference in New Issue
Block a user