发布 v1.10 #5
@@ -13,6 +13,7 @@ import tech.easyflow.ai.entity.ModelProvider;
|
|||||||
import tech.easyflow.ai.entity.table.ModelTableDef;
|
import tech.easyflow.ai.entity.table.ModelTableDef;
|
||||||
import tech.easyflow.ai.mapper.ModelMapper;
|
import tech.easyflow.ai.mapper.ModelMapper;
|
||||||
import tech.easyflow.ai.service.ModelService;
|
import tech.easyflow.ai.service.ModelService;
|
||||||
|
import tech.easyflow.ai.service.capability.ModelCapabilityResolution;
|
||||||
import tech.easyflow.common.domain.Result;
|
import tech.easyflow.common.domain.Result;
|
||||||
import tech.easyflow.common.entity.LoginAccount;
|
import tech.easyflow.common.entity.LoginAccount;
|
||||||
import tech.easyflow.common.satoken.util.SaTokenUtil;
|
import tech.easyflow.common.satoken.util.SaTokenUtil;
|
||||||
@@ -92,6 +93,21 @@ public class ModelController extends BaseCurdController<ModelService, Model> {
|
|||||||
return Result.ok(modelService.verifyModelConfig(model));
|
return Result.ok(modelService.verifyModelConfig(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据模型 ID 返回自动识别的类型和能力。
|
||||||
|
*
|
||||||
|
* @param providerId 供应商 ID
|
||||||
|
* @param modelName 模型 ID
|
||||||
|
* @return 模型能力识别结果
|
||||||
|
*/
|
||||||
|
@GetMapping("capabilities")
|
||||||
|
@SaCheckPermission("/api/v1/model/query")
|
||||||
|
public Result<ModelCapabilityResolution> resolveCapabilities(
|
||||||
|
@RequestParam(required = false) BigInteger providerId,
|
||||||
|
@RequestParam String modelName) {
|
||||||
|
return Result.ok(modelService.resolveModelCapabilities(providerId, modelName));
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/removeByEntity")
|
@PostMapping("/removeByEntity")
|
||||||
@SaCheckPermission("/api/v1/model/remove")
|
@SaCheckPermission("/api/v1/model/remove")
|
||||||
public Result<?> removeByEntity(@RequestBody Model entity) {
|
public Result<?> removeByEntity(@RequestBody Model entity) {
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ import com.easyagents.agent.runtime.model.AgentModelSpec;
|
|||||||
import io.agentscope.core.message.ContentBlock;
|
import io.agentscope.core.message.ContentBlock;
|
||||||
import io.agentscope.core.message.Msg;
|
import io.agentscope.core.message.Msg;
|
||||||
import io.agentscope.core.message.TextBlock;
|
import io.agentscope.core.message.TextBlock;
|
||||||
|
import io.agentscope.core.message.ToolUseBlock;
|
||||||
import io.agentscope.core.model.ChatResponse;
|
import io.agentscope.core.model.ChatResponse;
|
||||||
import io.agentscope.core.model.ExecutionConfig;
|
import io.agentscope.core.model.ExecutionConfig;
|
||||||
import io.agentscope.core.model.GenerateOptions;
|
import io.agentscope.core.model.GenerateOptions;
|
||||||
|
import io.agentscope.core.model.ToolChoice;
|
||||||
|
import io.agentscope.core.model.ToolSchema;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -30,8 +33,12 @@ import tech.easyflow.common.web.exceptions.BusinessException;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用 AgentScope 真实运行链路验证 Chat Model 与 VLM 连通性。
|
* 使用 AgentScope 真实运行链路验证 Chat Model 与 VLM 连通性。
|
||||||
@@ -40,11 +47,13 @@ import java.util.Map;
|
|||||||
public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnectivityVerifier {
|
public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnectivityVerifier {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AgentScopeChatModelConnectivityVerifier.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AgentScopeChatModelConnectivityVerifier.class);
|
||||||
|
private static final String PROBE_TOOL_NAME = "easyflow_capability_probe";
|
||||||
|
private static final String PROBE_NONCE_FIELD = "nonce";
|
||||||
|
private static final String PROBE_IMAGE_FIELD = "imageCode";
|
||||||
|
private static final String VERIFICATION_SYSTEM_PROMPT = "You are a model connectivity verification assistant.";
|
||||||
/** 为未识别关闭思考扩展参数的推理模型保留足够的小额输出预算。 */
|
/** 为未识别关闭思考扩展参数的推理模型保留足够的小额输出预算。 */
|
||||||
private static final int MAX_TOKENS = 256;
|
private static final int MAX_TOKENS = 128;
|
||||||
private static final Duration DEFAULT_PHASE_TIMEOUT = Duration.ofSeconds(60);
|
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 模型工厂。 */
|
/** AgentScope 模型工厂。 */
|
||||||
private final AgentModelFactory<io.agentscope.core.model.Model> modelFactory;
|
private final AgentModelFactory<io.agentscope.core.model.Model> modelFactory;
|
||||||
@@ -52,12 +61,15 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
|||||||
private final AgentScopeMessageAdapter messageAdapter;
|
private final AgentScopeMessageAdapter messageAdapter;
|
||||||
/** 单阶段最大等待时间。 */
|
/** 单阶段最大等待时间。 */
|
||||||
private final Duration phaseTimeout;
|
private final Duration phaseTimeout;
|
||||||
|
/** 为每次工具能力探测生成随机校验值。 */
|
||||||
|
private final Supplier<String> nonceSupplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用生产运行时组件创建验证器。
|
* 使用生产运行时组件创建验证器。
|
||||||
*/
|
*/
|
||||||
public AgentScopeChatModelConnectivityVerifier() {
|
public AgentScopeChatModelConnectivityVerifier() {
|
||||||
this(new AgentScopeModelFactory(), new AgentScopeMessageAdapter(), DEFAULT_PHASE_TIMEOUT);
|
this(new AgentScopeModelFactory(), new AgentScopeMessageAdapter(), DEFAULT_PHASE_TIMEOUT,
|
||||||
|
() -> UUID.randomUUID().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,60 +83,122 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
|||||||
AgentModelFactory<io.agentscope.core.model.Model> modelFactory,
|
AgentModelFactory<io.agentscope.core.model.Model> modelFactory,
|
||||||
AgentScopeMessageAdapter messageAdapter,
|
AgentScopeMessageAdapter messageAdapter,
|
||||||
Duration phaseTimeout) {
|
Duration phaseTimeout) {
|
||||||
this.modelFactory = modelFactory;
|
this(modelFactory, messageAdapter, phaseTimeout, () -> UUID.randomUUID().toString());
|
||||||
this.messageAdapter = messageAdapter;
|
|
||||||
this.phaseTimeout = phaseTimeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 依次验证非流式基础连接与流式响应能力。
|
* 使用可控随机值创建验证器,供能力探测测试使用。
|
||||||
|
*
|
||||||
|
* @param modelFactory AgentScope 模型工厂
|
||||||
|
* @param messageAdapter 消息适配器
|
||||||
|
* @param phaseTimeout 单阶段最大等待时间
|
||||||
|
* @param nonceSupplier 探测随机值生成器
|
||||||
|
*/
|
||||||
|
AgentScopeChatModelConnectivityVerifier(
|
||||||
|
AgentModelFactory<io.agentscope.core.model.Model> modelFactory,
|
||||||
|
AgentScopeMessageAdapter messageAdapter,
|
||||||
|
Duration phaseTimeout,
|
||||||
|
Supplier<String> nonceSupplier) {
|
||||||
|
this.modelFactory = modelFactory;
|
||||||
|
this.messageAdapter = messageAdapter;
|
||||||
|
this.phaseTimeout = phaseTimeout;
|
||||||
|
this.nonceSupplier = nonceSupplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用一次非流式 Chat 请求优先同时验证连接、视觉与工具调用能力。
|
||||||
|
*
|
||||||
|
* <p>当兼容接口明确拒绝工具参数时,追加一次不带工具的连接兜底请求,
|
||||||
|
* 避免将可用的普通对话模型误判为连接失败。</p>
|
||||||
*
|
*
|
||||||
* @param model 已补齐供应商默认配置的模型
|
* @param model 已补齐供应商默认配置的模型
|
||||||
* @return 双阶段验证结果
|
* @return 连接和工具能力验证结果
|
||||||
* @throws BusinessException 非流式基础连接失败时抛出
|
* @throws BusinessException 连接或视觉验证失败时抛出
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ChatModelVerificationResult verify(Model model) {
|
public ChatModelVerificationResult verify(Model model) {
|
||||||
AgentModelSpec modelSpec = AgentModelSpecMapper.fromModel(model);
|
AgentModelSpec modelSpec = AgentModelSpecMapper.fromModel(model);
|
||||||
String effectiveHttpVersion = AgentHttpTransportProvider.resolveEffectivePolicy(
|
String effectiveHttpVersion = AgentHttpTransportProvider.resolveEffectivePolicy(
|
||||||
modelSpec.getHttpVersionPolicy(), modelSpec.getBaseUrl()).name();
|
modelSpec.getHttpVersionPolicy(), modelSpec.getBaseUrl()).name();
|
||||||
AgentMessage verificationMessage = buildVerificationMessage(modelSpec.isSupportImage());
|
String nonce = nonceSupplier.get();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
verifyPhase(modelSpec, verificationMessage, false);
|
boolean supportTool = verifyProbeRequest(modelSpec, nonce);
|
||||||
} catch (BusinessException exception) {
|
return ChatModelVerificationResult.passed(effectiveHttpVersion, supportTool);
|
||||||
LOG.error("AgentScope model base connectivity verification failed, modelId={}, httpPolicy={}",
|
|
||||||
model.getId(), effectiveHttpVersion, exception);
|
|
||||||
throw exception;
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
LOG.error("AgentScope model base connectivity verification failed, modelId={}, httpPolicy={}",
|
if (isToolCapabilityRejection(exception)) {
|
||||||
model.getId(), effectiveHttpVersion, exception);
|
LOG.info("Model endpoint rejected tool probe, fallback to plain connectivity, modelId={}",
|
||||||
throw new BusinessException(400, 1, "模型基础连接验证失败,请查看后端日志", exception);
|
model.getId());
|
||||||
|
try {
|
||||||
|
verifyPlainRequest(modelSpec);
|
||||||
|
return ChatModelVerificationResult.passed(effectiveHttpVersion, false);
|
||||||
|
} catch (Exception fallbackException) {
|
||||||
|
LOG.error("AgentScope model fallback connectivity verification failed, modelId={}, httpPolicy={}",
|
||||||
|
model.getId(), effectiveHttpVersion, fallbackException);
|
||||||
|
throw new BusinessException(
|
||||||
|
400, 1, "模型连接验证失败,请查看后端日志", fallbackException);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try {
|
LOG.error("AgentScope model connectivity verification failed, modelId={}, httpPolicy={}",
|
||||||
verifyPhase(modelSpec, verificationMessage, true);
|
|
||||||
return ChatModelVerificationResult.passed(effectiveHttpVersion);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
LOG.warn("AgentScope model streaming verification failed, modelId={}, httpPolicy={}",
|
|
||||||
model.getId(), effectiveHttpVersion, exception);
|
model.getId(), effectiveHttpVersion, exception);
|
||||||
return ChatModelVerificationResult.streamingUnavailable(effectiveHttpVersion);
|
if (exception instanceof BusinessException businessException) {
|
||||||
|
throw businessException;
|
||||||
|
}
|
||||||
|
throw new BusinessException(400, 1, "模型连接验证失败,请查看后端日志", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行一次指定流式模式的模型请求并校验响应。
|
* 执行携带无副作用工具 Schema 的能力探测请求。
|
||||||
|
*
|
||||||
|
* @param modelSpec 运行时模型声明
|
||||||
|
* @param nonce 本次探测随机值
|
||||||
|
* @return 模型是否正确返回指定工具调用
|
||||||
|
* @throws BusinessException 响应为空或视觉识别失败时抛出
|
||||||
|
*/
|
||||||
|
private boolean verifyProbeRequest(AgentModelSpec modelSpec, String nonce) {
|
||||||
|
AgentMessage message = buildProbeMessage(modelSpec.isSupportImage(), nonce);
|
||||||
|
List<ChatResponse> responses = request(
|
||||||
|
modelSpec,
|
||||||
|
message,
|
||||||
|
List.of(buildProbeToolSchema(modelSpec.isSupportImage())),
|
||||||
|
new ToolChoice.Specific(PROBE_TOOL_NAME));
|
||||||
|
boolean validToolCall = hasValidProbeToolCall(
|
||||||
|
responses, nonce, modelSpec.isSupportImage());
|
||||||
|
validateProbeResponse(modelSpec.isSupportImage(), responses, validToolCall);
|
||||||
|
return validToolCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行不带工具的兼容性兜底请求。
|
||||||
|
*
|
||||||
|
* @param modelSpec 运行时模型声明
|
||||||
|
* @throws BusinessException 响应为空或视觉识别失败时抛出
|
||||||
|
*/
|
||||||
|
private void verifyPlainRequest(AgentModelSpec modelSpec) {
|
||||||
|
List<ChatResponse> responses = request(
|
||||||
|
modelSpec,
|
||||||
|
buildPlainVerificationMessage(modelSpec.isSupportImage()),
|
||||||
|
List.of(),
|
||||||
|
null);
|
||||||
|
validateTextResponse(modelSpec.isSupportImage(), aggregateText(responses));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用统一低成本参数执行一次非流式模型请求。
|
||||||
*
|
*
|
||||||
* @param modelSpec 运行时模型声明
|
* @param modelSpec 运行时模型声明
|
||||||
* @param verificationMessage 验证消息
|
* @param verificationMessage 验证消息
|
||||||
* @param stream 是否启用流式响应
|
* @param tools 工具 Schema
|
||||||
* @throws BusinessException 响应为空或 VLM 图片识别错误时抛出
|
* @param toolChoice 工具选择策略
|
||||||
|
* @return 模型响应片段
|
||||||
*/
|
*/
|
||||||
private void verifyPhase(AgentModelSpec modelSpec,
|
private List<ChatResponse> request(AgentModelSpec modelSpec,
|
||||||
AgentMessage verificationMessage,
|
AgentMessage verificationMessage,
|
||||||
boolean stream) {
|
List<ToolSchema> tools,
|
||||||
|
ToolChoice toolChoice) {
|
||||||
AgentGenerationOptions generationOptions = new AgentGenerationOptions();
|
AgentGenerationOptions generationOptions = new AgentGenerationOptions();
|
||||||
generationOptions.setStream(stream);
|
generationOptions.setStream(false);
|
||||||
generationOptions.setThinkingEnabled(false);
|
generationOptions.setThinkingEnabled(false);
|
||||||
disableOpenAiCompatibleThinking(modelSpec, generationOptions);
|
disableOpenAiCompatibleThinking(modelSpec, generationOptions);
|
||||||
generationOptions.setMaxTokens(MAX_TOKENS);
|
generationOptions.setMaxTokens(MAX_TOKENS);
|
||||||
@@ -132,24 +206,23 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
|||||||
|
|
||||||
List<Msg> messages = List.of(
|
List<Msg> messages = List.of(
|
||||||
messageAdapter.toMsg(AgentMessage.text(
|
messageAdapter.toMsg(AgentMessage.text(
|
||||||
AgentMessageRole.SYSTEM,
|
AgentMessageRole.SYSTEM, VERIFICATION_SYSTEM_PROMPT)),
|
||||||
VERIFICATION_SYSTEM_PROMPT)),
|
|
||||||
messageAdapter.toMsg(verificationMessage));
|
messageAdapter.toMsg(verificationMessage));
|
||||||
GenerateOptions requestOptions = GenerateOptions.builder()
|
GenerateOptions.Builder requestBuilder = GenerateOptions.builder()
|
||||||
.stream(stream)
|
.stream(false)
|
||||||
.maxTokens(MAX_TOKENS)
|
.maxTokens(MAX_TOKENS)
|
||||||
.executionConfig(ExecutionConfig.builder()
|
.executionConfig(ExecutionConfig.builder()
|
||||||
.timeout(phaseTimeout)
|
.timeout(phaseTimeout)
|
||||||
.maxAttempts(1)
|
.maxAttempts(1)
|
||||||
.build())
|
.build());
|
||||||
.build();
|
if (toolChoice != null) {
|
||||||
List<ChatResponse> responses = agentScopeModel
|
requestBuilder.toolChoice(toolChoice);
|
||||||
.stream(messages, List.of(), requestOptions)
|
}
|
||||||
|
return agentScopeModel
|
||||||
|
.stream(messages, tools, requestBuilder.build())
|
||||||
.timeout(phaseTimeout)
|
.timeout(phaseTimeout)
|
||||||
.collectList()
|
.collectList()
|
||||||
.block(phaseTimeout.plusSeconds(1));
|
.block(phaseTimeout.plusSeconds(1));
|
||||||
String responseText = aggregateText(responses);
|
|
||||||
validateResponse(modelSpec.isSupportImage(), responseText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,19 +255,47 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文字模型或 VLM 的最小验证消息。
|
* 创建同时验证连接、视觉和工具调用的消息。
|
||||||
*
|
*
|
||||||
* @param supportImage 是否验证图片理解能力
|
* @param supportImage 是否验证图片理解能力
|
||||||
* @return 验证消息
|
* @param nonce 本次探测随机值
|
||||||
|
* @return 工具能力探测消息
|
||||||
*/
|
*/
|
||||||
private AgentMessage buildVerificationMessage(boolean supportImage) {
|
private AgentMessage buildProbeMessage(boolean supportImage, String nonce) {
|
||||||
|
String prompt = supportImage
|
||||||
|
? "请调用 " + PROBE_TOOL_NAME + " 工具,将 nonce 设置为“" + nonce
|
||||||
|
+ "”,并将图片中的验证码设置为 imageCode。不要直接回答。"
|
||||||
|
: "请调用 " + PROBE_TOOL_NAME + " 工具,并将 nonce 设置为“" + nonce
|
||||||
|
+ "”。不要直接回答。";
|
||||||
|
return buildVerificationMessage(prompt, supportImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建不带工具的兼容性兜底消息。
|
||||||
|
*
|
||||||
|
* @param supportImage 是否验证图片理解能力
|
||||||
|
* @return 普通连接验证消息
|
||||||
|
*/
|
||||||
|
private AgentMessage buildPlainVerificationMessage(boolean supportImage) {
|
||||||
|
String prompt = supportImage
|
||||||
|
? "请直接输出图片中的内容,不要补充其他内容。"
|
||||||
|
: "请直接回复“你好”,不要补充其他内容。";
|
||||||
|
return buildVerificationMessage(prompt, supportImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建文字或 VLM 验证消息。
|
||||||
|
*
|
||||||
|
* @param prompt 验证提示词
|
||||||
|
* @param supportImage 是否附加验证图片
|
||||||
|
* @return AgentScope 消息
|
||||||
|
*/
|
||||||
|
private AgentMessage buildVerificationMessage(String prompt, boolean supportImage) {
|
||||||
if (!supportImage) {
|
if (!supportImage) {
|
||||||
return AgentMessage.text(
|
return AgentMessage.text(AgentMessageRole.USER, prompt);
|
||||||
AgentMessageRole.USER,
|
|
||||||
"请直接回复“你好”,不要补充其他内容。");
|
|
||||||
}
|
}
|
||||||
List<AgentContentBlock> blocks = new ArrayList<>();
|
List<AgentContentBlock> blocks = new ArrayList<>();
|
||||||
blocks.add(new AgentTextBlock("请直接输出图片中的内容,不要补充其他内容。"));
|
blocks.add(new AgentTextBlock(prompt));
|
||||||
AgentMediaBlock image = new AgentMediaBlock("image");
|
AgentMediaBlock image = new AgentMediaBlock("image");
|
||||||
image.setMimeType("image/png");
|
image.setMimeType("image/png");
|
||||||
image.setData(Base64.getEncoder().encodeToString(VlmVerificationImage.pngBytes()));
|
image.setData(Base64.getEncoder().encodeToString(VlmVerificationImage.pngBytes()));
|
||||||
@@ -205,6 +306,111 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建只声明参数、不绑定执行逻辑的探测工具 Schema。
|
||||||
|
*
|
||||||
|
* @param supportImage 是否包含图片验证码参数
|
||||||
|
* @return 探测工具 Schema
|
||||||
|
*/
|
||||||
|
private ToolSchema buildProbeToolSchema(boolean supportImage) {
|
||||||
|
Map<String, Object> properties = new LinkedHashMap<>();
|
||||||
|
properties.put(PROBE_NONCE_FIELD, Map.of(
|
||||||
|
"type", "string",
|
||||||
|
"description", "原样返回用户提供的 nonce"));
|
||||||
|
List<String> required = new ArrayList<>();
|
||||||
|
required.add(PROBE_NONCE_FIELD);
|
||||||
|
if (supportImage) {
|
||||||
|
properties.put(PROBE_IMAGE_FIELD, Map.of(
|
||||||
|
"type", "string",
|
||||||
|
"description", "图片中的验证码"));
|
||||||
|
required.add(PROBE_IMAGE_FIELD);
|
||||||
|
}
|
||||||
|
return ToolSchema.builder()
|
||||||
|
.name(PROBE_TOOL_NAME)
|
||||||
|
.description("验证模型是否能生成结构化工具调用")
|
||||||
|
.parameters(Map.of(
|
||||||
|
"type", "object",
|
||||||
|
"properties", properties,
|
||||||
|
"required", required))
|
||||||
|
.strict(false)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断响应是否包含参数正确的探测工具调用。
|
||||||
|
*
|
||||||
|
* @param responses AgentScope 响应片段
|
||||||
|
* @param nonce 本次探测随机值
|
||||||
|
* @param supportImage 是否同时验证图片
|
||||||
|
* @return 工具名和参数均正确返回 true
|
||||||
|
*/
|
||||||
|
private boolean hasValidProbeToolCall(List<ChatResponse> responses,
|
||||||
|
String nonce,
|
||||||
|
boolean supportImage) {
|
||||||
|
if (responses == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (ChatResponse response : responses) {
|
||||||
|
if (response == null || response.getContent() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (ContentBlock block : response.getContent()) {
|
||||||
|
if (!(block instanceof ToolUseBlock toolUse)
|
||||||
|
|| !PROBE_TOOL_NAME.equals(toolUse.getName())
|
||||||
|
|| toolUse.getInput() == null
|
||||||
|
|| !nonce.equals(String.valueOf(toolUse.getInput().get(PROBE_NONCE_FIELD)))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!supportImage || VlmVerificationImage.VERIFICATION_CODE.equals(
|
||||||
|
normalizeVerificationText(String.valueOf(
|
||||||
|
toolUse.getInput().get(PROBE_IMAGE_FIELD))))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验探测响应是否足以证明连接和视觉能力。
|
||||||
|
*
|
||||||
|
* @param supportImage 是否验证图片理解能力
|
||||||
|
* @param responses AgentScope 响应片段
|
||||||
|
* @param validToolCall 是否包含正确工具调用
|
||||||
|
* @throws BusinessException 响应为空或图片识别错误时抛出
|
||||||
|
*/
|
||||||
|
private void validateProbeResponse(boolean supportImage,
|
||||||
|
List<ChatResponse> responses,
|
||||||
|
boolean validToolCall) {
|
||||||
|
if (validToolCall) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String responseText = aggregateText(responses);
|
||||||
|
if (responseText != null && !responseText.isBlank()) {
|
||||||
|
validateTextResponse(supportImage, responseText);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (hasAnyContent(responses) && !supportImage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new BusinessException("模型未返回有效内容");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断模型是否返回任意内容块。
|
||||||
|
*
|
||||||
|
* @param responses AgentScope 响应片段
|
||||||
|
* @return 存在内容块返回 true
|
||||||
|
*/
|
||||||
|
private boolean hasAnyContent(List<ChatResponse> responses) {
|
||||||
|
if (responses == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return responses.stream()
|
||||||
|
.filter(response -> response != null && response.getContent() != null)
|
||||||
|
.anyMatch(response -> !response.getContent().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 聚合流式响应中的全部文本增量。
|
* 聚合流式响应中的全部文本增量。
|
||||||
*
|
*
|
||||||
@@ -236,7 +442,7 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
|||||||
* @param responseText 聚合后的响应文本
|
* @param responseText 聚合后的响应文本
|
||||||
* @throws BusinessException 响应为空或图片识别结果不匹配时抛出
|
* @throws BusinessException 响应为空或图片识别结果不匹配时抛出
|
||||||
*/
|
*/
|
||||||
private void validateResponse(boolean supportImage, String responseText) {
|
private void validateTextResponse(boolean supportImage, String responseText) {
|
||||||
if (responseText == null || responseText.isBlank()) {
|
if (responseText == null || responseText.isBlank()) {
|
||||||
throw new BusinessException("模型未返回有效内容");
|
throw new BusinessException("模型未返回有效内容");
|
||||||
}
|
}
|
||||||
@@ -278,4 +484,34 @@ public class AgentScopeChatModelConnectivityVerifier implements ChatModelConnect
|
|||||||
? normalized
|
? normalized
|
||||||
: normalized.substring(0, 160) + "...";
|
: normalized.substring(0, 160) + "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断异常是否明确来自工具或工具选择参数不兼容。
|
||||||
|
*
|
||||||
|
* @param exception 模型调用异常
|
||||||
|
* @return 工具参数被拒绝返回 true
|
||||||
|
*/
|
||||||
|
private boolean isToolCapabilityRejection(Throwable exception) {
|
||||||
|
Throwable current = exception;
|
||||||
|
while (current != null) {
|
||||||
|
String message = current.getMessage();
|
||||||
|
if (message != null) {
|
||||||
|
String normalized = message.toLowerCase(Locale.ROOT);
|
||||||
|
if (normalized.contains("tool_choice")
|
||||||
|
|| normalized.contains("tool choice")
|
||||||
|
|| normalized.contains("tool_call")
|
||||||
|
|| normalized.contains("tool call")
|
||||||
|
|| normalized.contains("tools parameter")
|
||||||
|
|| normalized.contains("function calling")
|
||||||
|
|| (normalized.contains("tools")
|
||||||
|
&& (normalized.contains("unsupported")
|
||||||
|
|| normalized.contains("not support")
|
||||||
|
|| normalized.contains("invalid")))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current = current.getCause();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import io.agentscope.core.message.ImageBlock;
|
|||||||
import io.agentscope.core.message.Msg;
|
import io.agentscope.core.message.Msg;
|
||||||
import io.agentscope.core.message.MsgRole;
|
import io.agentscope.core.message.MsgRole;
|
||||||
import io.agentscope.core.message.TextBlock;
|
import io.agentscope.core.message.TextBlock;
|
||||||
|
import io.agentscope.core.message.ToolUseBlock;
|
||||||
import io.agentscope.core.model.ChatResponse;
|
import io.agentscope.core.model.ChatResponse;
|
||||||
import io.agentscope.core.model.GenerateOptions;
|
import io.agentscope.core.model.GenerateOptions;
|
||||||
|
import io.agentscope.core.model.ToolChoice;
|
||||||
import io.agentscope.core.model.ToolSchema;
|
import io.agentscope.core.model.ToolSchema;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -27,101 +29,102 @@ import java.time.Duration;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AgentScope 双阶段模型连通性验证测试。
|
* AgentScope 单次优先模型连接与工具能力验证测试。
|
||||||
*/
|
*/
|
||||||
public class AgentScopeChatModelConnectivityVerifierTest {
|
public class AgentScopeChatModelConnectivityVerifierTest {
|
||||||
|
|
||||||
/**
|
private static final String TEST_NONCE = "probe-nonce";
|
||||||
* 验证非流式与流式阶段按顺序执行并返回通过状态。
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void shouldPassWhenBothPhasesReturnText() {
|
|
||||||
RecordingModelFactory factory = new RecordingModelFactory(
|
|
||||||
Flux.just(response("你好")),
|
|
||||||
Flux.just(response("你"), response("好")));
|
|
||||||
AgentScopeChatModelConnectivityVerifier verifier = verifier(factory);
|
|
||||||
|
|
||||||
ChatModelVerificationResult result = verifier.verify(model(false));
|
|
||||||
|
|
||||||
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getStatus());
|
|
||||||
Assert.assertEquals("HTTP_1_1", result.getEffectiveHttpVersion());
|
|
||||||
Assert.assertEquals(List.of(false, true), factory.getFactoryStreams());
|
|
||||||
Assert.assertEquals(List.of(false, true), factory.getRequestStreams());
|
|
||||||
Assert.assertEquals(List.of(MsgRole.SYSTEM, MsgRole.USER), factory.getMessageRoles().get(0));
|
|
||||||
Assert.assertEquals(List.of(false, false), factory.getEnableThinkingValues());
|
|
||||||
Assert.assertEquals(List.of(false, false), factory.getChatTemplateThinkingValues());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证基础连接通过而流式阶段失败时返回部分通过结果。
|
* 验证一次请求正确返回工具调用时同时确认连接和工具能力。
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnPartialWhenStreamingPhaseFails() {
|
public void shouldPassConnectionAndToolProbeInOneRequest() {
|
||||||
RecordingModelFactory factory = new RecordingModelFactory(
|
RecordingModelFactory factory = new RecordingModelFactory(
|
||||||
Flux.just(response("你好")),
|
Flux.just(toolResponse(TEST_NONCE, null)));
|
||||||
Flux.error(new IllegalStateException("stream failed")));
|
|
||||||
|
|
||||||
ChatModelVerificationResult result = verifier(factory).verify(model(false));
|
ChatModelVerificationResult result = verifier(factory).verify(model(false));
|
||||||
|
|
||||||
Assert.assertEquals(ModelVerificationStatus.PARTIAL, result.getStatus());
|
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getStatus());
|
||||||
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getNonStreaming());
|
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getNonStreaming());
|
||||||
Assert.assertEquals(ModelVerificationStatus.FAILED, result.getStreaming());
|
Assert.assertEquals(ModelVerificationStatus.SKIPPED, result.getStreaming());
|
||||||
Assert.assertTrue(result.getMessage().contains("流式响应不可用"));
|
Assert.assertEquals(Boolean.TRUE, result.getSupportTool());
|
||||||
|
Assert.assertEquals("验证通过", result.getMessage());
|
||||||
|
Assert.assertEquals(List.of(false), factory.getFactoryStreams());
|
||||||
|
Assert.assertEquals(List.of(false), factory.getRequestStreams());
|
||||||
|
Assert.assertEquals(List.of(1), factory.getToolCounts());
|
||||||
|
Assert.assertTrue(factory.getToolChoices().get(0) instanceof ToolChoice.Specific);
|
||||||
|
Assert.assertEquals(MsgRole.SYSTEM, factory.getMessageBatches().get(0).get(0).getRole());
|
||||||
|
Assert.assertEquals(MsgRole.USER, factory.getMessageBatches().get(0).get(1).getRole());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证基础连接失败时立即终止且返回业务失败。
|
* 验证模型返回普通文本时连接通过但工具能力保持关闭。
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldStopWhenNonStreamingPhaseFails() {
|
public void shouldPassConnectionAndMarkToolUnsupportedWhenTextReturned() {
|
||||||
|
RecordingModelFactory factory = new RecordingModelFactory(
|
||||||
|
Flux.just(textResponse("你好")));
|
||||||
|
|
||||||
|
ChatModelVerificationResult result = verifier(factory).verify(model(false));
|
||||||
|
|
||||||
|
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getStatus());
|
||||||
|
Assert.assertEquals(Boolean.FALSE, result.getSupportTool());
|
||||||
|
Assert.assertEquals(List.of(1), factory.getToolCounts());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证接口明确拒绝工具参数时仅追加一次普通连接兜底。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldFallbackToPlainRequestWhenToolChoiceIsRejected() {
|
||||||
|
RecordingModelFactory factory = new RecordingModelFactory(
|
||||||
|
Flux.error(new IllegalArgumentException("tool_choice is unsupported")),
|
||||||
|
Flux.just(textResponse("你好")));
|
||||||
|
|
||||||
|
ChatModelVerificationResult result = verifier(factory).verify(model(false));
|
||||||
|
|
||||||
|
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getStatus());
|
||||||
|
Assert.assertEquals(Boolean.FALSE, result.getSupportTool());
|
||||||
|
Assert.assertEquals(List.of(1, 0), factory.getToolCounts());
|
||||||
|
Assert.assertTrue(factory.getToolChoices().get(0) instanceof ToolChoice.Specific);
|
||||||
|
Assert.assertNull(factory.getToolChoices().get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证普通连接异常不会被工具兼容兜底掩盖。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldFailWhenConnectivityRequestFails() {
|
||||||
RecordingModelFactory factory = new RecordingModelFactory(
|
RecordingModelFactory factory = new RecordingModelFactory(
|
||||||
Flux.error(new IllegalStateException("connection failed")));
|
Flux.error(new IllegalStateException("connection failed")));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
verifier(factory).verify(model(false));
|
verifier(factory).verify(model(false));
|
||||||
Assert.fail("Expected base connectivity verification failure");
|
Assert.fail("Expected connectivity verification failure");
|
||||||
} catch (BusinessException exception) {
|
} catch (BusinessException exception) {
|
||||||
Assert.assertTrue(exception.getMessage().contains("基础连接验证失败"));
|
Assert.assertTrue(exception.getMessage().contains("连接验证失败"));
|
||||||
Assert.assertFalse(exception.getMessage().contains("connection failed"));
|
Assert.assertFalse(exception.getMessage().contains("connection failed"));
|
||||||
}
|
}
|
||||||
Assert.assertEquals(List.of(false), factory.getFactoryStreams());
|
Assert.assertEquals(List.of(1), factory.getToolCounts());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证流式阶段超时被归类为部分可用且不暴露底层异常。
|
* 验证 VLM 在同一次工具调用中返回图片验证码。
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnPartialWhenStreamingPhaseTimesOut() {
|
public void shouldVerifyVlmAndToolCallInOneRequest() {
|
||||||
RecordingModelFactory factory = new RecordingModelFactory(
|
RecordingModelFactory factory = new RecordingModelFactory(
|
||||||
Flux.just(response("你好")),
|
Flux.just(toolResponse(TEST_NONCE, VlmVerificationImage.VERIFICATION_CODE)));
|
||||||
Flux.never());
|
|
||||||
AgentScopeChatModelConnectivityVerifier verifier = new AgentScopeChatModelConnectivityVerifier(
|
|
||||||
factory,
|
|
||||||
new AgentScopeMessageAdapter(),
|
|
||||||
Duration.ofMillis(20));
|
|
||||||
|
|
||||||
ChatModelVerificationResult result = verifier.verify(model(false));
|
|
||||||
|
|
||||||
Assert.assertEquals(ModelVerificationStatus.PARTIAL, result.getStatus());
|
|
||||||
Assert.assertEquals("连接成功,流式响应不可用,可关闭智能体的模型流式响应。",
|
|
||||||
result.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证 VLM 使用 Base64 图片,并能聚合流式文本增量。
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void shouldVerifyVlmImageAndAggregateStreamingChunks() {
|
|
||||||
RecordingModelFactory factory = new RecordingModelFactory(
|
|
||||||
Flux.just(response("图片中的内容是“" + VlmVerificationImage.VERIFICATION_CODE + "”。")),
|
|
||||||
Flux.just(response("识别结果:58"), response("39")));
|
|
||||||
|
|
||||||
ChatModelVerificationResult result = verifier(factory).verify(model(true));
|
ChatModelVerificationResult result = verifier(factory).verify(model(true));
|
||||||
|
|
||||||
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getStatus());
|
Assert.assertEquals(ModelVerificationStatus.PASSED, result.getStatus());
|
||||||
Msg message = factory.getMessages().get(0);
|
Assert.assertEquals(Boolean.TRUE, result.getSupportTool());
|
||||||
|
Msg message = factory.getMessageBatches().get(0).get(1);
|
||||||
ImageBlock image = message.getContent().stream()
|
ImageBlock image = message.getContent().stream()
|
||||||
.filter(ImageBlock.class::isInstance)
|
.filter(ImageBlock.class::isInstance)
|
||||||
.map(ImageBlock.class::cast)
|
.map(ImageBlock.class::cast)
|
||||||
@@ -154,7 +157,7 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建使用测试工厂的验证器。
|
* 创建使用固定随机值的验证器。
|
||||||
*
|
*
|
||||||
* @param factory 记录型模型工厂
|
* @param factory 记录型模型工厂
|
||||||
* @return 验证器
|
* @return 验证器
|
||||||
@@ -163,54 +166,73 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
|||||||
return new AgentScopeChatModelConnectivityVerifier(
|
return new AgentScopeChatModelConnectivityVerifier(
|
||||||
factory,
|
factory,
|
||||||
new AgentScopeMessageAdapter(),
|
new AgentScopeMessageAdapter(),
|
||||||
Duration.ofSeconds(2));
|
Duration.ofSeconds(2),
|
||||||
|
() -> TEST_NONCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建单个文本响应片段。
|
* 创建文本响应。
|
||||||
*
|
*
|
||||||
* @param text 文本内容
|
* @param text 文本内容
|
||||||
* @return AgentScope 响应
|
* @return AgentScope 响应
|
||||||
*/
|
*/
|
||||||
private ChatResponse response(String text) {
|
private ChatResponse textResponse(String text) {
|
||||||
return ChatResponse.builder()
|
return ChatResponse.builder()
|
||||||
.content(List.of(TextBlock.builder().text(text).build()))
|
.content(List.of(TextBlock.builder().text(text).build()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按阶段返回预设响应并记录调用参数的模型工厂。
|
* 创建探测工具调用响应。
|
||||||
|
*
|
||||||
|
* @param nonce 随机校验值
|
||||||
|
* @param imageCode 图片验证码
|
||||||
|
* @return AgentScope 响应
|
||||||
|
*/
|
||||||
|
private ChatResponse toolResponse(String nonce, String imageCode) {
|
||||||
|
Map<String, Object> input = imageCode == null
|
||||||
|
? Map.of("nonce", nonce)
|
||||||
|
: Map.of("nonce", nonce, "imageCode", imageCode);
|
||||||
|
return ChatResponse.builder()
|
||||||
|
.content(List.of(ToolUseBlock.builder()
|
||||||
|
.id("call-probe")
|
||||||
|
.name("easyflow_capability_probe")
|
||||||
|
.input(input)
|
||||||
|
.build()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按调用顺序返回预设响应并记录真实请求参数的模型工厂。
|
||||||
*/
|
*/
|
||||||
private static final class RecordingModelFactory
|
private static final class RecordingModelFactory
|
||||||
implements AgentModelFactory<io.agentscope.core.model.Model> {
|
implements AgentModelFactory<io.agentscope.core.model.Model> {
|
||||||
|
|
||||||
/** 每个阶段的预设响应。 */
|
/** 每次调用的预设响应。 */
|
||||||
private final List<Flux<ChatResponse>> phaseResponses;
|
private final List<Flux<ChatResponse>> responses;
|
||||||
/** 模型工厂收到的流式参数。 */
|
/** 模型工厂收到的流式参数。 */
|
||||||
private final List<Boolean> factoryStreams = new ArrayList<>();
|
private final List<Boolean> factoryStreams = new ArrayList<>();
|
||||||
/** 模型请求收到的流式参数。 */
|
/** 模型请求收到的流式参数。 */
|
||||||
private final List<Boolean> requestStreams = new ArrayList<>();
|
private final List<Boolean> requestStreams = new ArrayList<>();
|
||||||
/** 模型请求收到的消息。 */
|
/** 模型请求收到的消息批次。 */
|
||||||
private final List<Msg> messages = new ArrayList<>();
|
private final List<List<Msg>> messageBatches = new ArrayList<>();
|
||||||
/** 各阶段请求消息的角色顺序。 */
|
/** 每次请求携带的工具数量。 */
|
||||||
private final List<List<MsgRole>> messageRoles = new ArrayList<>();
|
private final List<Integer> toolCounts = new ArrayList<>();
|
||||||
/** OpenAI-compatible 请求中的思考开关。 */
|
/** 每次请求使用的工具选择策略。 */
|
||||||
private final List<Object> enableThinkingValues = new ArrayList<>();
|
private final List<ToolChoice> toolChoices = new ArrayList<>();
|
||||||
/** GPUStack 模板参数中的思考开关。 */
|
|
||||||
private final List<Object> chatTemplateThinkingValues = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建记录型模型工厂。
|
* 创建记录型模型工厂。
|
||||||
*
|
*
|
||||||
* @param phaseResponses 每个阶段的预设响应
|
* @param responses 每次调用的预设响应
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
private RecordingModelFactory(Flux<ChatResponse>... phaseResponses) {
|
private RecordingModelFactory(Flux<ChatResponse>... responses) {
|
||||||
this.phaseResponses = List.of(phaseResponses);
|
this.responses = List.of(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建当前验证阶段的测试模型。
|
* 创建当前验证请求使用的模型。
|
||||||
*
|
*
|
||||||
* @param modelSpec 模型声明
|
* @param modelSpec 模型声明
|
||||||
* @param generationOptions 生成参数
|
* @param generationOptions 生成参数
|
||||||
@@ -220,19 +242,12 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
|||||||
public io.agentscope.core.model.Model create(
|
public io.agentscope.core.model.Model create(
|
||||||
AgentModelSpec modelSpec,
|
AgentModelSpec modelSpec,
|
||||||
AgentGenerationOptions generationOptions) {
|
AgentGenerationOptions generationOptions) {
|
||||||
int phaseIndex = factoryStreams.size();
|
int requestIndex = factoryStreams.size();
|
||||||
factoryStreams.add(Boolean.TRUE.equals(generationOptions.getStream()));
|
factoryStreams.add(Boolean.TRUE.equals(generationOptions.getStream()));
|
||||||
enableThinkingValues.add(
|
Flux<ChatResponse> response = responses.get(requestIndex);
|
||||||
generationOptions.getAdditionalBodyParams().get("enable_thinking"));
|
|
||||||
Object templateOptions = generationOptions.getAdditionalBodyParams()
|
|
||||||
.get("chat_template_kwargs");
|
|
||||||
chatTemplateThinkingValues.add(templateOptions instanceof java.util.Map<?, ?> map
|
|
||||||
? map.get("enable_thinking")
|
|
||||||
: null);
|
|
||||||
Flux<ChatResponse> responses = phaseResponses.get(phaseIndex);
|
|
||||||
return new io.agentscope.core.model.Model() {
|
return new io.agentscope.core.model.Model() {
|
||||||
/**
|
/**
|
||||||
* 返回预设响应并记录真实请求参数。
|
* 返回预设响应并记录请求参数。
|
||||||
*
|
*
|
||||||
* @param inputMessages 模型消息
|
* @param inputMessages 模型消息
|
||||||
* @param tools 工具声明
|
* @param tools 工具声明
|
||||||
@@ -245,9 +260,10 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
|||||||
List<ToolSchema> tools,
|
List<ToolSchema> tools,
|
||||||
GenerateOptions options) {
|
GenerateOptions options) {
|
||||||
requestStreams.add(Boolean.TRUE.equals(options.getStream()));
|
requestStreams.add(Boolean.TRUE.equals(options.getStream()));
|
||||||
messages.add(inputMessages.get(inputMessages.size() - 1));
|
messageBatches.add(List.copyOf(inputMessages));
|
||||||
messageRoles.add(inputMessages.stream().map(Msg::getRole).toList());
|
toolCounts.add(tools.size());
|
||||||
return responses;
|
toolChoices.add(options.getToolChoice());
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,7 +279,7 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取工厂流式参数记录。
|
* 获取模型工厂流式参数。
|
||||||
*
|
*
|
||||||
* @return 流式参数列表
|
* @return 流式参数列表
|
||||||
*/
|
*/
|
||||||
@@ -272,7 +288,7 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求流式参数记录。
|
* 获取请求流式参数。
|
||||||
*
|
*
|
||||||
* @return 流式参数列表
|
* @return 流式参数列表
|
||||||
*/
|
*/
|
||||||
@@ -281,39 +297,30 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求消息记录。
|
* 获取每次请求的验证消息批次。
|
||||||
*
|
*
|
||||||
* @return 消息列表
|
* @return 验证消息批次
|
||||||
*/
|
*/
|
||||||
private List<Msg> getMessages() {
|
private List<List<Msg>> getMessageBatches() {
|
||||||
return messages;
|
return messageBatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取各阶段请求消息的角色顺序。
|
* 获取工具数量。
|
||||||
*
|
*
|
||||||
* @return 消息角色顺序
|
* @return 工具数量列表
|
||||||
*/
|
*/
|
||||||
private List<List<MsgRole>> getMessageRoles() {
|
private List<Integer> getToolCounts() {
|
||||||
return messageRoles;
|
return toolCounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 OpenAI-compatible 请求中的思考开关。
|
* 获取工具选择策略。
|
||||||
*
|
*
|
||||||
* @return 各阶段思考开关
|
* @return 工具选择策略列表
|
||||||
*/
|
*/
|
||||||
private List<Object> getEnableThinkingValues() {
|
private List<ToolChoice> getToolChoices() {
|
||||||
return enableThinkingValues;
|
return toolChoices;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取 GPUStack 模板参数中的思考开关。
|
|
||||||
*
|
|
||||||
* @return 各阶段模板思考开关
|
|
||||||
*/
|
|
||||||
private List<Object> getChatTemplateThinkingValues() {
|
|
||||||
return chatTemplateThinkingValues;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ public class Model extends ModelBase {
|
|||||||
deepseekConfig.setThinkingProtocol("deepseek");
|
deepseekConfig.setThinkingProtocol("deepseek");
|
||||||
deepseekConfig.setNeedReasoningContentForToolMessage(Boolean.TRUE);
|
deepseekConfig.setNeedReasoningContentForToolMessage(Boolean.TRUE);
|
||||||
deepseekConfig.setSupportImageBase64Only(getSupportImageB64Only());
|
deepseekConfig.setSupportImageBase64Only(getSupportImageB64Only());
|
||||||
if (getSupportToolMessage() != null) {
|
if (getSupportTool() != null) {
|
||||||
deepseekConfig.setSupportToolMessage(getSupportToolMessage());
|
deepseekConfig.setSupportToolMessage(getSupportTool());
|
||||||
}
|
}
|
||||||
return new DeepseekChatModel(deepseekConfig);
|
return new DeepseekChatModel(deepseekConfig);
|
||||||
default:
|
default:
|
||||||
@@ -92,8 +92,8 @@ public class Model extends ModelBase {
|
|||||||
openAIChatConfig.setModel(checkAndGetModelName());
|
openAIChatConfig.setModel(checkAndGetModelName());
|
||||||
openAIChatConfig.setRequestPath(checkAndGetRequestPath());
|
openAIChatConfig.setRequestPath(checkAndGetRequestPath());
|
||||||
openAIChatConfig.setSupportImageBase64Only(getSupportImageB64Only());
|
openAIChatConfig.setSupportImageBase64Only(getSupportImageB64Only());
|
||||||
if (getSupportToolMessage() != null) {
|
if (getSupportTool() != null) {
|
||||||
openAIChatConfig.setSupportToolMessage(getSupportToolMessage());
|
openAIChatConfig.setSupportToolMessage(getSupportTool());
|
||||||
}
|
}
|
||||||
return new OpenAIChatModel(openAIChatConfig);
|
return new OpenAIChatModel(openAIChatConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,10 +77,12 @@ public class UnifiedModelInvokeServiceImpl implements UnifiedModelInvokeService
|
|||||||
throw ModelInvokeException.badRequest("当前模型仅支持 base64 图片输入", "messages", "image_base64_only");
|
throw ModelInvokeException.badRequest("当前模型仅支持 base64 图片输入", "messages", "image_base64_only");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (request.getTools() != null && !request.getTools().isEmpty() && !Boolean.TRUE.equals(model.getSupportTool())) {
|
if (request.getTools() != null
|
||||||
|
&& !request.getTools().isEmpty()
|
||||||
|
&& Boolean.FALSE.equals(model.getSupportTool())) {
|
||||||
throw ModelInvokeException.badRequest("当前模型不支持 tools 参数", "tools", "tool_not_supported");
|
throw ModelInvokeException.badRequest("当前模型不支持 tools 参数", "tools", "tool_not_supported");
|
||||||
}
|
}
|
||||||
if (hasToolMessage(messages) && !Boolean.TRUE.equals(model.getSupportToolMessage())) {
|
if (hasToolMessage(messages) && Boolean.FALSE.equals(model.getSupportTool())) {
|
||||||
throw ModelInvokeException.badRequest("当前模型不支持 tool 消息透传", "messages", "tool_message_not_supported");
|
throw ModelInvokeException.badRequest("当前模型不支持 tool 消息透传", "messages", "tool_message_not_supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package tech.easyflow.ai.service;
|
|||||||
|
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import tech.easyflow.ai.entity.Model;
|
import tech.easyflow.ai.entity.Model;
|
||||||
|
import tech.easyflow.ai.service.capability.ModelCapabilityResolution;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -19,6 +20,15 @@ public interface ModelService extends IService<Model> {
|
|||||||
|
|
||||||
Map<String, Object> verifyModelConfig(Model llm);
|
Map<String, Object> verifyModelConfig(Model llm);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据供应商和模型 ID 自动解析模型能力。
|
||||||
|
*
|
||||||
|
* @param providerId 供应商 ID
|
||||||
|
* @param modelName 模型 ID
|
||||||
|
* @return 模型能力识别结果
|
||||||
|
*/
|
||||||
|
ModelCapabilityResolution resolveModelCapabilities(BigInteger providerId, String modelName);
|
||||||
|
|
||||||
Map<String, Map<String, List<Model>>> getList(Model entity);
|
Map<String, Map<String, List<Model>>> getList(Model entity);
|
||||||
|
|
||||||
void removeByEntity(Model entity);
|
void removeByEntity(Model entity);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.easyagents.core.model.embedding.EmbeddingModel;
|
|||||||
import com.easyagents.core.model.rerank.RerankModel;
|
import com.easyagents.core.model.rerank.RerankModel;
|
||||||
import com.easyagents.core.store.VectorData;
|
import com.easyagents.core.store.VectorData;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.core.update.UpdateChain;
|
||||||
import com.mybatisflex.core.util.StringUtil;
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -21,7 +22,11 @@ import tech.easyflow.ai.entity.ModelProvider;
|
|||||||
import tech.easyflow.ai.mapper.ModelMapper;
|
import tech.easyflow.ai.mapper.ModelMapper;
|
||||||
import tech.easyflow.ai.service.ModelProviderService;
|
import tech.easyflow.ai.service.ModelProviderService;
|
||||||
import tech.easyflow.ai.service.ModelService;
|
import tech.easyflow.ai.service.ModelService;
|
||||||
|
import tech.easyflow.ai.service.capability.ModelCapabilityResolution;
|
||||||
|
import tech.easyflow.ai.service.capability.ModelCapabilityResolver;
|
||||||
|
import tech.easyflow.ai.service.capability.ModelCapabilitySource;
|
||||||
import tech.easyflow.ai.service.verification.ChatModelConnectivityVerifier;
|
import tech.easyflow.ai.service.verification.ChatModelConnectivityVerifier;
|
||||||
|
import tech.easyflow.ai.service.verification.ChatModelVerificationResult;
|
||||||
import tech.easyflow.common.tree.Tree;
|
import tech.easyflow.common.tree.Tree;
|
||||||
import tech.easyflow.common.util.SqlOperatorsUtil;
|
import tech.easyflow.common.util.SqlOperatorsUtil;
|
||||||
import tech.easyflow.common.util.SqlUtil;
|
import tech.easyflow.common.util.SqlUtil;
|
||||||
@@ -47,6 +52,10 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
ModelProviderService modelProviderService;
|
ModelProviderService modelProviderService;
|
||||||
|
|
||||||
|
/** 统一模型能力解析器。 */
|
||||||
|
@Autowired
|
||||||
|
private ModelCapabilityResolver modelCapabilityResolver;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Cache<String, Object> cache;
|
private Cache<String, Object> cache;
|
||||||
|
|
||||||
@@ -92,6 +101,18 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据供应商和模型 ID 自动解析模型能力。
|
||||||
|
*
|
||||||
|
* @param providerId 供应商 ID
|
||||||
|
* @param modelName 模型 ID
|
||||||
|
* @return 模型能力识别结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ModelCapabilityResolution resolveModelCapabilities(BigInteger providerId, String modelName) {
|
||||||
|
return modelCapabilityResolver.resolve(resolveProviderType(providerId, null), modelName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Map<String, List<Model>>> getList(Model entity) {
|
public Map<String, Map<String, List<Model>>> getList(Model entity) {
|
||||||
Map<String, Map<String, List<Model>>> result = new HashMap<>();
|
Map<String, Map<String, List<Model>>> result = new HashMap<>();
|
||||||
@@ -166,7 +187,15 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements
|
|||||||
if (chatModelConnectivityVerifier == null) {
|
if (chatModelConnectivityVerifier == null) {
|
||||||
throw new BusinessException("Agent 模型连通性验证组件未加载");
|
throw new BusinessException("Agent 模型连通性验证组件未加载");
|
||||||
}
|
}
|
||||||
return chatModelConnectivityVerifier.verify(model).toMap();
|
ChatModelVerificationResult result = chatModelConnectivityVerifier.verify(model);
|
||||||
|
if (result.getSupportTool() != null && model.getId() != null) {
|
||||||
|
UpdateChain<Model> updateChain = updateChain();
|
||||||
|
updateChain.set(Model::getSupportTool, result.getSupportTool());
|
||||||
|
updateChain.set(Model::getSupportToolMessage, result.getSupportTool());
|
||||||
|
updateChain.eq(Model::getId, model.getId());
|
||||||
|
updateChain.update();
|
||||||
|
}
|
||||||
|
return result.toMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -199,6 +228,7 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements
|
|||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new BusinessException("模型配置不能为空");
|
throw new BusinessException("模型配置不能为空");
|
||||||
}
|
}
|
||||||
|
applyAutoCapabilities(entity);
|
||||||
if (entity.getPublishEnabled() == null) {
|
if (entity.getPublishEnabled() == null) {
|
||||||
entity.setPublishEnabled(Boolean.FALSE);
|
entity.setPublishEnabled(Boolean.FALSE);
|
||||||
}
|
}
|
||||||
@@ -239,6 +269,101 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements
|
|||||||
entity.setInvokeCode(invokeCode);
|
entity.setInvokeCode(invokeCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将自动识别结果写入待保存模型,并清理已下线的展示能力字段。
|
||||||
|
*
|
||||||
|
* @param entity 待保存模型
|
||||||
|
*/
|
||||||
|
private void applyAutoCapabilities(Model entity) {
|
||||||
|
String providerType = resolveProviderType(entity.getProviderId(), entity.getModelProvider());
|
||||||
|
ModelCapabilityResolution resolution = modelCapabilityResolver.resolve(
|
||||||
|
providerType, entity.getModelName());
|
||||||
|
boolean modelIdentityChanged = hasModelIdentityChanged(entity);
|
||||||
|
|
||||||
|
if (resolution.getSource() != ModelCapabilitySource.DEFAULT) {
|
||||||
|
entity.setModelType(resolution.getModelType());
|
||||||
|
applyResolvedChatCapabilities(entity, resolution);
|
||||||
|
} else if (StrUtil.isBlank(entity.getModelType())) {
|
||||||
|
entity.setModelType(Model.MODEL_TYPES[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Model.MODEL_TYPES[0].equals(entity.getModelType())) {
|
||||||
|
entity.setSupportImage(Boolean.FALSE);
|
||||||
|
entity.setSupportThinking(Boolean.FALSE);
|
||||||
|
entity.setSupportTool(Boolean.FALSE);
|
||||||
|
} else if (modelIdentityChanged) {
|
||||||
|
// 切换模型后,仅将仍无法识别且未被用户设置的能力归零。
|
||||||
|
entity.setSupportImage(Boolean.TRUE.equals(entity.getSupportImage()));
|
||||||
|
entity.setSupportThinking(Boolean.TRUE.equals(entity.getSupportThinking()));
|
||||||
|
entity.setSupportTool(Boolean.TRUE.equals(entity.getSupportTool()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频、音频尚未接入模型调用链,保存时保持关闭。
|
||||||
|
entity.setSupportVideo(Boolean.FALSE);
|
||||||
|
entity.setSupportAudio(Boolean.FALSE);
|
||||||
|
// tool 消息能力跟随工具调用能力,不再由前端单独配置。
|
||||||
|
entity.setSupportToolMessage(entity.getSupportTool());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断更新请求是否切换了实际模型或供应商。
|
||||||
|
*
|
||||||
|
* @param entity 待更新模型
|
||||||
|
* @return 模型标识发生变化返回 true
|
||||||
|
*/
|
||||||
|
private boolean hasModelIdentityChanged(Model entity) {
|
||||||
|
if (entity.getId() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Model stored = modelMapper.selectOneById(entity.getId());
|
||||||
|
if (stored == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean modelChanged = StrUtil.isNotBlank(entity.getModelName())
|
||||||
|
&& !StrUtil.equalsIgnoreCase(
|
||||||
|
StrUtil.trim(entity.getModelName()),
|
||||||
|
StrUtil.trim(stored.getModelName()));
|
||||||
|
boolean providerChanged = entity.getProviderId() != null
|
||||||
|
&& !Objects.equals(entity.getProviderId(), stored.getProviderId());
|
||||||
|
return modelChanged || providerChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用识别结果补齐尚未明确配置的对话能力,保留用户手动设置。
|
||||||
|
*
|
||||||
|
* @param entity 待保存模型
|
||||||
|
* @param resolution 模型能力识别结果
|
||||||
|
*/
|
||||||
|
private void applyResolvedChatCapabilities(Model entity, ModelCapabilityResolution resolution) {
|
||||||
|
if (entity.getSupportImage() == null && resolution.getSupportImage() != null) {
|
||||||
|
entity.setSupportImage(resolution.getSupportImage());
|
||||||
|
}
|
||||||
|
if (entity.getSupportThinking() == null && resolution.getSupportThinking() != null) {
|
||||||
|
entity.setSupportThinking(resolution.getSupportThinking());
|
||||||
|
}
|
||||||
|
if (entity.getSupportTool() == null && resolution.getSupportTool() != null) {
|
||||||
|
entity.setSupportTool(resolution.getSupportTool());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取模型配置对应的供应商类型。
|
||||||
|
*
|
||||||
|
* @param providerId 供应商 ID
|
||||||
|
* @param provider 已加载的供应商对象
|
||||||
|
* @return 供应商类型,供应商不存在时返回 null
|
||||||
|
*/
|
||||||
|
private String resolveProviderType(BigInteger providerId, ModelProvider provider) {
|
||||||
|
if (provider != null && StrUtil.isNotBlank(provider.getProviderType())) {
|
||||||
|
return provider.getProviderType();
|
||||||
|
}
|
||||||
|
if (providerId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ModelProvider storedProvider = modelProviderService.getById(providerId);
|
||||||
|
return storedProvider == null ? null : storedProvider.getProviderType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Model> listInvokeModels() {
|
public List<Model> listInvokeModels() {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create().eq(Model::getModelType, Model.MODEL_TYPES[0]);
|
QueryWrapper queryWrapper = QueryWrapper.create().eq(Model::getModelType, Model.MODEL_TYPES[0]);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chat Model 与 VLM 的双阶段连通性验证结果。
|
* Chat Model 与 VLM 的连接和工具能力验证结果。
|
||||||
*/
|
*/
|
||||||
public final class ChatModelVerificationResult {
|
public final class ChatModelVerificationResult {
|
||||||
|
|
||||||
@@ -16,6 +16,8 @@ public final class ChatModelVerificationResult {
|
|||||||
private final ModelVerificationStatus streaming;
|
private final ModelVerificationStatus streaming;
|
||||||
/** 实际生效的 HTTP 版本策略。 */
|
/** 实际生效的 HTTP 版本策略。 */
|
||||||
private final String effectiveHttpVersion;
|
private final String effectiveHttpVersion;
|
||||||
|
/** 当前端点是否通过工具调用探测。 */
|
||||||
|
private final Boolean supportTool;
|
||||||
/** 用户可见的简洁结果说明。 */
|
/** 用户可见的简洁结果说明。 */
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
@@ -26,48 +28,39 @@ public final class ChatModelVerificationResult {
|
|||||||
* @param nonStreaming 非流式验证状态
|
* @param nonStreaming 非流式验证状态
|
||||||
* @param streaming 流式验证状态
|
* @param streaming 流式验证状态
|
||||||
* @param effectiveHttpVersion 实际生效的 HTTP 版本策略
|
* @param effectiveHttpVersion 实际生效的 HTTP 版本策略
|
||||||
|
* @param supportTool 当前端点是否通过工具调用探测
|
||||||
* @param message 用户可见结果说明
|
* @param message 用户可见结果说明
|
||||||
*/
|
*/
|
||||||
private ChatModelVerificationResult(ModelVerificationStatus status,
|
private ChatModelVerificationResult(ModelVerificationStatus status,
|
||||||
ModelVerificationStatus nonStreaming,
|
ModelVerificationStatus nonStreaming,
|
||||||
ModelVerificationStatus streaming,
|
ModelVerificationStatus streaming,
|
||||||
String effectiveHttpVersion,
|
String effectiveHttpVersion,
|
||||||
|
Boolean supportTool,
|
||||||
String message) {
|
String message) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.nonStreaming = nonStreaming;
|
this.nonStreaming = nonStreaming;
|
||||||
this.streaming = streaming;
|
this.streaming = streaming;
|
||||||
this.effectiveHttpVersion = effectiveHttpVersion;
|
this.effectiveHttpVersion = effectiveHttpVersion;
|
||||||
|
this.supportTool = supportTool;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建双阶段全部通过的结果。
|
* 创建一次连接与工具探测通过的结果。
|
||||||
*
|
*
|
||||||
* @param effectiveHttpVersion 实际生效的 HTTP 版本策略
|
* @param effectiveHttpVersion 实际生效的 HTTP 版本策略
|
||||||
* @return 全部通过结果
|
* @param supportTool 当前端点是否通过工具调用探测
|
||||||
|
* @return 验证通过结果
|
||||||
*/
|
*/
|
||||||
public static ChatModelVerificationResult passed(String effectiveHttpVersion) {
|
public static ChatModelVerificationResult passed(String effectiveHttpVersion,
|
||||||
|
boolean supportTool) {
|
||||||
return new ChatModelVerificationResult(
|
return new ChatModelVerificationResult(
|
||||||
ModelVerificationStatus.PASSED,
|
ModelVerificationStatus.PASSED,
|
||||||
ModelVerificationStatus.PASSED,
|
ModelVerificationStatus.PASSED,
|
||||||
ModelVerificationStatus.PASSED,
|
ModelVerificationStatus.SKIPPED,
|
||||||
effectiveHttpVersion,
|
effectiveHttpVersion,
|
||||||
"验证成功");
|
supportTool,
|
||||||
}
|
"验证通过");
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建基础连接通过但流式阶段失败的结果。
|
|
||||||
*
|
|
||||||
* @param effectiveHttpVersion 实际生效的 HTTP 版本策略
|
|
||||||
* @return 部分通过结果
|
|
||||||
*/
|
|
||||||
public static ChatModelVerificationResult streamingUnavailable(String effectiveHttpVersion) {
|
|
||||||
return new ChatModelVerificationResult(
|
|
||||||
ModelVerificationStatus.PARTIAL,
|
|
||||||
ModelVerificationStatus.PASSED,
|
|
||||||
ModelVerificationStatus.FAILED,
|
|
||||||
effectiveHttpVersion,
|
|
||||||
"连接成功,流式响应不可用,可关闭智能体的模型流式响应。");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,6 +99,15 @@ public final class ChatModelVerificationResult {
|
|||||||
return effectiveHttpVersion;
|
return effectiveHttpVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取工具调用探测结果。
|
||||||
|
*
|
||||||
|
* @return 是否通过工具调用探测
|
||||||
|
*/
|
||||||
|
public Boolean getSupportTool() {
|
||||||
|
return supportTool;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户可见结果说明。
|
* 获取用户可见结果说明。
|
||||||
*
|
*
|
||||||
@@ -126,6 +128,9 @@ public final class ChatModelVerificationResult {
|
|||||||
result.put("nonStreaming", nonStreaming.name());
|
result.put("nonStreaming", nonStreaming.name());
|
||||||
result.put("streaming", streaming.name());
|
result.put("streaming", streaming.name());
|
||||||
result.put("effectiveHttpVersion", effectiveHttpVersion);
|
result.put("effectiveHttpVersion", effectiveHttpVersion);
|
||||||
|
if (supportTool != null) {
|
||||||
|
result.put("supportTool", supportTool);
|
||||||
|
}
|
||||||
result.put("message", message);
|
result.put("message", message);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package tech.easyflow.ai.service.impl;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import tech.easyflow.ai.entity.Model;
|
||||||
|
import tech.easyflow.ai.service.capability.ModelCapabilityResolution;
|
||||||
|
import tech.easyflow.ai.service.capability.ModelCapabilitySource;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型能力自动识别与手动覆盖合并规则测试。
|
||||||
|
*/
|
||||||
|
public class ModelServiceImplCapabilityOverrideTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证用户明确关闭的能力不会被模型库重新打开。
|
||||||
|
*
|
||||||
|
* @throws ReflectiveOperationException 无法调用待测试方法时抛出
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldPreserveExplicitCapabilityOverrides() throws ReflectiveOperationException {
|
||||||
|
Model model = new Model();
|
||||||
|
model.setSupportImage(Boolean.FALSE);
|
||||||
|
model.setSupportThinking(Boolean.FALSE);
|
||||||
|
model.setSupportTool(Boolean.FALSE);
|
||||||
|
|
||||||
|
applyResolvedCapabilities(model, detectedCapabilities());
|
||||||
|
|
||||||
|
Assert.assertEquals(Boolean.FALSE, model.getSupportImage());
|
||||||
|
Assert.assertEquals(Boolean.FALSE, model.getSupportThinking());
|
||||||
|
Assert.assertEquals(Boolean.FALSE, model.getSupportTool());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证空能力值会由模型库自动补齐。
|
||||||
|
*
|
||||||
|
* @throws ReflectiveOperationException 无法调用待测试方法时抛出
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldFillCapabilitiesWhenNotConfigured() throws ReflectiveOperationException {
|
||||||
|
Model model = new Model();
|
||||||
|
|
||||||
|
applyResolvedCapabilities(model, detectedCapabilities());
|
||||||
|
|
||||||
|
Assert.assertEquals(Boolean.TRUE, model.getSupportImage());
|
||||||
|
Assert.assertEquals(Boolean.TRUE, model.getSupportThinking());
|
||||||
|
Assert.assertEquals(Boolean.TRUE, model.getSupportTool());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建模型库已确认的对话能力。
|
||||||
|
*
|
||||||
|
* @return 全部开启的模型能力
|
||||||
|
*/
|
||||||
|
private ModelCapabilityResolution detectedCapabilities() {
|
||||||
|
return new ModelCapabilityResolution(
|
||||||
|
Model.MODEL_TYPES[0],
|
||||||
|
Boolean.TRUE,
|
||||||
|
Boolean.TRUE,
|
||||||
|
Boolean.TRUE,
|
||||||
|
ModelCapabilitySource.CATALOG);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用服务内部的能力合并逻辑。
|
||||||
|
*
|
||||||
|
* @param model 待合并模型
|
||||||
|
* @param resolution 自动识别结果
|
||||||
|
* @throws ReflectiveOperationException 无法调用待测试方法时抛出
|
||||||
|
*/
|
||||||
|
private void applyResolvedCapabilities(Model model, ModelCapabilityResolution resolution)
|
||||||
|
throws ReflectiveOperationException {
|
||||||
|
ModelServiceImpl service = new ModelServiceImpl();
|
||||||
|
Method method = ModelServiceImpl.class.getDeclaredMethod(
|
||||||
|
"applyResolvedChatCapabilities", Model.class, ModelCapabilityResolution.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
method.invoke(service, model, resolution);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,22 @@ export async function verifyModelConfig(id: string) {
|
|||||||
|
|
||||||
export type ModelCapabilitySource = 'CATALOG' | 'DEFAULT' | 'RULE';
|
export type ModelCapabilitySource = 'CATALOG' | 'DEFAULT' | 'RULE';
|
||||||
|
|
||||||
|
export interface ModelCapabilityResolution {
|
||||||
|
detected: boolean;
|
||||||
|
modelType: 'chatModel' | 'embeddingModel' | 'rerankModel';
|
||||||
|
source: ModelCapabilitySource;
|
||||||
|
supportImage?: boolean | null;
|
||||||
|
supportThinking?: boolean | null;
|
||||||
|
supportTool?: boolean | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resolveModelCapabilities(params: {
|
||||||
|
modelName: string;
|
||||||
|
providerId?: string;
|
||||||
|
}) {
|
||||||
|
return api.get('/api/v1/model/capabilities', { params });
|
||||||
|
}
|
||||||
|
|
||||||
export interface RemoteModelDescriptor {
|
export interface RemoteModelDescriptor {
|
||||||
addable: boolean;
|
addable: boolean;
|
||||||
added: boolean;
|
added: boolean;
|
||||||
@@ -91,6 +107,7 @@ export interface ModelVerificationData {
|
|||||||
nonStreaming?: ModelVerificationStageStatus;
|
nonStreaming?: ModelVerificationStageStatus;
|
||||||
status?: ModelVerificationStageStatus;
|
status?: ModelVerificationStageStatus;
|
||||||
streaming?: ModelVerificationStageStatus;
|
streaming?: ModelVerificationStageStatus;
|
||||||
|
supportTool?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModelInvokeConfigPayload {
|
export interface ModelInvokeConfigPayload {
|
||||||
@@ -136,8 +153,9 @@ export interface llmType {
|
|||||||
groupName: string;
|
groupName: string;
|
||||||
invokeCode?: string;
|
invokeCode?: string;
|
||||||
publishEnabled?: boolean;
|
publishEnabled?: boolean;
|
||||||
supportTool?: boolean;
|
supportThinking?: boolean | null;
|
||||||
supportImage?: boolean;
|
supportTool?: boolean | null;
|
||||||
|
supportImage?: boolean | null;
|
||||||
supportImageB64Only?: boolean;
|
supportImageB64Only?: boolean;
|
||||||
supportToolMessage?: boolean;
|
supportToolMessage?: boolean;
|
||||||
added: boolean;
|
added: boolean;
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
"groupName": "GroupName",
|
"groupName": "GroupName",
|
||||||
"provider": "供应商",
|
"provider": "供应商",
|
||||||
"ability": "ModelAbility",
|
"ability": "ModelAbility",
|
||||||
|
"abilityChangeTip": "Model capabilities are detected automatically from the model ID. Change them carefully, as incorrect settings may prevent the model from working.",
|
||||||
"button": {
|
"button": {
|
||||||
"management": "Management",
|
"management": "Management",
|
||||||
"test": "Test",
|
"test": "Test",
|
||||||
@@ -67,7 +68,7 @@
|
|||||||
"supportTool": "Tool",
|
"supportTool": "Tool",
|
||||||
"supportAudio": "Audio",
|
"supportAudio": "Audio",
|
||||||
"supportVideo": "Video",
|
"supportVideo": "Video",
|
||||||
"supportImage": "Multimodal",
|
"supportImage": "Vision",
|
||||||
"supportFree": "Free",
|
"supportFree": "Free",
|
||||||
"supportImageB64Only": "Base64 images only",
|
"supportImageB64Only": "Base64 images only",
|
||||||
"supportToolMessage": "SupportToolMessage"
|
"supportToolMessage": "SupportToolMessage"
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
"groupName": "分组名称",
|
"groupName": "分组名称",
|
||||||
"provider": "供应商",
|
"provider": "供应商",
|
||||||
"ability": "模型能力",
|
"ability": "模型能力",
|
||||||
|
"abilityChangeTip": "模型能力已根据模型 ID 自动识别,请谨慎修改,错误配置可能导致模型无法正常使用。",
|
||||||
"button": {
|
"button": {
|
||||||
"management": "管理",
|
"management": "管理",
|
||||||
"test": "检测",
|
"test": "检测",
|
||||||
@@ -64,7 +65,7 @@
|
|||||||
"supportTool": "工具",
|
"supportTool": "工具",
|
||||||
"supportAudio": "音频",
|
"supportAudio": "音频",
|
||||||
"supportVideo": "视频",
|
"supportVideo": "视频",
|
||||||
"supportImage": "多模态",
|
"supportImage": "视觉",
|
||||||
"supportFree": "免费",
|
"supportFree": "免费",
|
||||||
"supportImageB64Only": "仅接受 Base64 图片",
|
"supportImageB64Only": "仅接受 Base64 图片",
|
||||||
"supportToolMessage": "支持Tool消息"
|
"supportToolMessage": "支持Tool消息"
|
||||||
|
|||||||
@@ -284,6 +284,9 @@ const handleVerify = async (row: llmType) => {
|
|||||||
const res = await verifyModelConfig(modelId);
|
const res = await verifyModelConfig(modelId);
|
||||||
|
|
||||||
const feedback = resolveModelVerificationFeedback(res, row.modelType);
|
const feedback = resolveModelVerificationFeedback(res, row.modelType);
|
||||||
|
if (typeof res.data?.supportTool === 'boolean') {
|
||||||
|
row.supportTool = res.data.supportTool;
|
||||||
|
}
|
||||||
setVerifyStatus(modelId, feedback.status);
|
setVerifyStatus(modelId, feedback.status);
|
||||||
|
|
||||||
if (feedback.status === 'success') {
|
if (feedback.status === 'success') {
|
||||||
|
|||||||
@@ -6,25 +6,32 @@ import { computed, reactive, ref, watch } from 'vue';
|
|||||||
import { EasyFlowFormModal } from '@easyflow/common-ui';
|
import { EasyFlowFormModal } from '@easyflow/common-ui';
|
||||||
import { IconifyIcon } from '@easyflow/icons';
|
import { IconifyIcon } from '@easyflow/icons';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ArrowDown,
|
||||||
|
ArrowUp,
|
||||||
|
InfoFilled,
|
||||||
|
Loading,
|
||||||
|
} from '@element-plus/icons-vue';
|
||||||
import {
|
import {
|
||||||
ElForm,
|
ElForm,
|
||||||
ElFormItem,
|
ElFormItem,
|
||||||
|
ElIcon,
|
||||||
ElInput,
|
ElInput,
|
||||||
ElMessage,
|
ElMessage,
|
||||||
ElOption,
|
ElOption,
|
||||||
ElSelect,
|
ElSelect,
|
||||||
|
ElTooltip,
|
||||||
} from 'element-plus';
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import { resolveModelCapabilities } from '#/api/ai/llm';
|
||||||
import { api } from '#/api/request';
|
import { api } from '#/api/request';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import {
|
import {
|
||||||
getDefaultModelAbility,
|
getDefaultModelAbility,
|
||||||
|
handleTagClick as handleTagClickUtil,
|
||||||
syncTagSelectedStatus as syncTagSelectedStatusUtil,
|
syncTagSelectedStatus as syncTagSelectedStatusUtil,
|
||||||
} from '#/views/ai/model/modelUtils/model-ability';
|
} from '#/views/ai/model/modelUtils/model-ability';
|
||||||
import {
|
import { resetModelAbility } from '#/views/ai/model/modelUtils/model-ability-utils';
|
||||||
generateFeaturesFromModelAbility,
|
|
||||||
resetModelAbility,
|
|
||||||
} from '#/views/ai/model/modelUtils/model-ability-utils';
|
|
||||||
|
|
||||||
type AgentHttpVersionPolicy = 'AUTO' | 'HTTP_1_1' | 'HTTP_2_PREFERRED';
|
type AgentHttpVersionPolicy = 'AUTO' | 'HTTP_1_1' | 'HTTP_2_PREFERRED';
|
||||||
type AgentSystemContentFormat = 'STRING' | 'TEXT_PARTS';
|
type AgentSystemContentFormat = 'STRING' | 'TEXT_PARTS';
|
||||||
@@ -47,14 +54,14 @@ interface FormData {
|
|||||||
apiKey: string;
|
apiKey: string;
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
requestPath: string;
|
requestPath: string;
|
||||||
supportThinking: boolean;
|
supportThinking: boolean | null;
|
||||||
supportTool: boolean;
|
supportTool: boolean | null;
|
||||||
supportImage: boolean;
|
supportImage: boolean | null;
|
||||||
supportAudio: boolean;
|
supportAudio: boolean;
|
||||||
supportFree: boolean;
|
supportFree: boolean;
|
||||||
supportVideo: boolean;
|
supportVideo: boolean;
|
||||||
supportImageB64Only: boolean;
|
supportImageB64Only: boolean;
|
||||||
supportToolMessage: boolean;
|
supportToolMessage: boolean | null;
|
||||||
options: ModelOptions;
|
options: ModelOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +89,11 @@ const formDataRef = ref();
|
|||||||
const isAdd = ref(true);
|
const isAdd = ref(true);
|
||||||
const dialogVisible = ref(false);
|
const dialogVisible = ref(false);
|
||||||
const btnLoading = ref(false);
|
const btnLoading = ref(false);
|
||||||
|
const showAdvanced = ref(false);
|
||||||
|
const capabilityLoading = ref(false);
|
||||||
|
const autoDetectedModelType = ref(false);
|
||||||
|
let capabilityRequestSequence = 0;
|
||||||
|
let manuallyEditedModelName = '';
|
||||||
|
|
||||||
const formData = reactive<FormData>({
|
const formData = reactive<FormData>({
|
||||||
modelType: '',
|
modelType: '',
|
||||||
@@ -94,14 +106,14 @@ const formData = reactive<FormData>({
|
|||||||
apiKey: '',
|
apiKey: '',
|
||||||
endpoint: '',
|
endpoint: '',
|
||||||
requestPath: '',
|
requestPath: '',
|
||||||
supportThinking: false,
|
supportThinking: null,
|
||||||
supportTool: false,
|
supportTool: null,
|
||||||
supportImage: false,
|
supportImage: null,
|
||||||
supportAudio: false,
|
supportAudio: false,
|
||||||
supportFree: false,
|
supportFree: false,
|
||||||
supportVideo: false,
|
supportVideo: false,
|
||||||
supportImageB64Only: false,
|
supportImageB64Only: false,
|
||||||
supportToolMessage: true,
|
supportToolMessage: null,
|
||||||
options: {
|
options: {
|
||||||
agentHttpVersionPolicy: 'AUTO',
|
agentHttpVersionPolicy: 'AUTO',
|
||||||
agentSystemContentFormat: 'STRING',
|
agentSystemContentFormat: 'STRING',
|
||||||
@@ -151,11 +163,7 @@ const normalizeModelOptions = (options?: unknown): ModelOptions => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const modelAbility = ref<ModelAbilityItem[]>(getDefaultModelAbility());
|
const modelAbility = ref<ModelAbilityItem[]>(getDefaultModelAbility());
|
||||||
const visibleModelAbility = computed(() =>
|
const visibleModelAbility = computed(() => modelAbility.value);
|
||||||
modelAbility.value.filter(
|
|
||||||
(item) => item.field !== 'supportImageB64Only' || formData.supportImage,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
type SelectableModelType = '' | 'embeddingModel' | 'rerankModel';
|
type SelectableModelType = '' | 'embeddingModel' | 'rerankModel';
|
||||||
|
|
||||||
const selectedModelType = ref<SelectableModelType>('');
|
const selectedModelType = ref<SelectableModelType>('');
|
||||||
@@ -175,11 +183,7 @@ const abilityIconMap: Record<string, string> = {
|
|||||||
rerankModel: 'svg:data-center',
|
rerankModel: 'svg:data-center',
|
||||||
thinking: 'svg:llm',
|
thinking: 'svg:llm',
|
||||||
tool: 'svg:wrench',
|
tool: 'svg:wrench',
|
||||||
video: 'mdi:video-outline',
|
|
||||||
image: 'mdi:image-outline',
|
image: 'mdi:image-outline',
|
||||||
audio: 'mdi:microphone-outline',
|
|
||||||
imageB64: 'mdi:file-image-outline',
|
|
||||||
toolMessage: 'mdi:hammer',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncTagSelectedStatus = () => {
|
const syncTagSelectedStatus = () => {
|
||||||
@@ -188,35 +192,61 @@ const syncTagSelectedStatus = () => {
|
|||||||
|
|
||||||
const resetAbilitySelection = () => {
|
const resetAbilitySelection = () => {
|
||||||
resetModelAbility(modelAbility.value);
|
resetModelAbility(modelAbility.value);
|
||||||
|
formData.supportThinking = false;
|
||||||
|
formData.supportTool = false;
|
||||||
|
formData.supportImage = false;
|
||||||
|
formData.supportToolMessage = false;
|
||||||
syncTagSelectedStatus();
|
syncTagSelectedStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTagClick = (item: ModelAbilityItem) => {
|
const markCapabilitiesAsManuallyEdited = () => {
|
||||||
|
manuallyEditedModelName = formData.modelName.trim();
|
||||||
|
capabilityRequestSequence += 1;
|
||||||
|
capabilityLoading.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAbilityChipClick = (item: ModelAbilityItem) => {
|
||||||
if (hasSpecialModelType.value) {
|
if (hasSpecialModelType.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
item.selected = !item.selected;
|
markCapabilitiesAsManuallyEdited();
|
||||||
formData[item.field] = item.selected;
|
handleTagClickUtil(item, formData);
|
||||||
if (item.field === 'supportImage' && !item.selected) {
|
if (item.field === 'supportTool') {
|
||||||
formData.supportImageB64Only = false;
|
formData.supportToolMessage = formData.supportTool;
|
||||||
const base64Ability = modelAbility.value.find(
|
|
||||||
(ability) => ability.field === 'supportImageB64Only',
|
|
||||||
);
|
|
||||||
if (base64Ability) base64Ability.selected = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleModelNameInput = () => {
|
||||||
|
manuallyEditedModelName = '';
|
||||||
|
capabilityRequestSequence += 1;
|
||||||
|
capabilityLoading.value = false;
|
||||||
|
autoDetectedModelType.value = false;
|
||||||
|
selectedModelType.value = '';
|
||||||
|
formData.supportThinking = null;
|
||||||
|
formData.supportTool = null;
|
||||||
|
formData.supportImage = null;
|
||||||
|
formData.supportToolMessage = null;
|
||||||
|
syncTagSelectedStatus();
|
||||||
|
};
|
||||||
|
|
||||||
const handleModelTypeChipClick = (
|
const handleModelTypeChipClick = (
|
||||||
modelType: Exclude<SelectableModelType, ''>,
|
modelType: Exclude<SelectableModelType, ''>,
|
||||||
) => {
|
) => {
|
||||||
const nextType = selectedModelType.value === modelType ? '' : modelType;
|
const nextType = selectedModelType.value === modelType ? '' : modelType;
|
||||||
|
markCapabilitiesAsManuallyEdited();
|
||||||
|
autoDetectedModelType.value = false;
|
||||||
selectedModelType.value = nextType;
|
selectedModelType.value = nextType;
|
||||||
if (nextType) {
|
if (nextType) {
|
||||||
resetAbilitySelection();
|
resetAbilitySelection();
|
||||||
|
} else {
|
||||||
|
formData.supportThinking = null;
|
||||||
|
formData.supportTool = null;
|
||||||
|
formData.supportImage = null;
|
||||||
|
formData.supportToolMessage = null;
|
||||||
|
syncTagSelectedStatus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isAbilityChipDisabled = () => hasSpecialModelType.value;
|
|
||||||
const getAbilityIcon = (value: string) => abilityIconMap[value] || 'svg:llm';
|
const getAbilityIcon = (value: string) => abilityIconMap[value] || 'svg:llm';
|
||||||
|
|
||||||
const resolveModelType = (): FormData['modelType'] => {
|
const resolveModelType = (): FormData['modelType'] => {
|
||||||
@@ -244,14 +274,14 @@ const resetFormData = () => {
|
|||||||
apiKey: '',
|
apiKey: '',
|
||||||
endpoint: '',
|
endpoint: '',
|
||||||
requestPath: '',
|
requestPath: '',
|
||||||
supportThinking: false,
|
supportThinking: null,
|
||||||
supportTool: false,
|
supportTool: null,
|
||||||
supportAudio: false,
|
supportAudio: false,
|
||||||
supportVideo: false,
|
supportVideo: false,
|
||||||
supportImage: false,
|
supportImage: null,
|
||||||
supportImageB64Only: false,
|
supportImageB64Only: false,
|
||||||
supportFree: false,
|
supportFree: false,
|
||||||
supportToolMessage: true,
|
supportToolMessage: null,
|
||||||
options: normalizeModelOptions(),
|
options: normalizeModelOptions(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -261,6 +291,9 @@ defineExpose({
|
|||||||
isAdd.value = true;
|
isAdd.value = true;
|
||||||
formDataRef.value?.resetFields();
|
formDataRef.value?.resetFields();
|
||||||
resetFormData();
|
resetFormData();
|
||||||
|
showAdvanced.value = false;
|
||||||
|
autoDetectedModelType.value = false;
|
||||||
|
manuallyEditedModelName = '';
|
||||||
selectedModelType.value = normalizeSelectableModelType(modelType);
|
selectedModelType.value = normalizeSelectableModelType(modelType);
|
||||||
if (selectedModelType.value) {
|
if (selectedModelType.value) {
|
||||||
resetAbilitySelection();
|
resetAbilitySelection();
|
||||||
@@ -274,6 +307,9 @@ defineExpose({
|
|||||||
dialogVisible.value = true;
|
dialogVisible.value = true;
|
||||||
isAdd.value = false;
|
isAdd.value = false;
|
||||||
resetFormData();
|
resetFormData();
|
||||||
|
showAdvanced.value = false;
|
||||||
|
autoDetectedModelType.value = false;
|
||||||
|
manuallyEditedModelName = '';
|
||||||
Object.assign(formData, {
|
Object.assign(formData, {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
modelType: item.modelType || '',
|
modelType: item.modelType || '',
|
||||||
@@ -286,15 +322,14 @@ defineExpose({
|
|||||||
endpoint: item.endpoint || '',
|
endpoint: item.endpoint || '',
|
||||||
requestPath: item.requestPath || '',
|
requestPath: item.requestPath || '',
|
||||||
apiKey: item.apiKey || '',
|
apiKey: item.apiKey || '',
|
||||||
supportThinking: item.supportThinking || false,
|
supportThinking: item.supportThinking ?? null,
|
||||||
supportAudio: item.supportAudio || false,
|
supportAudio: item.supportAudio || false,
|
||||||
supportImage: item.supportImage || false,
|
supportImage: item.supportImage ?? null,
|
||||||
supportImageB64Only: item.supportImageB64Only || false,
|
supportImageB64Only: item.supportImageB64Only || false,
|
||||||
supportVideo: item.supportVideo || false,
|
supportVideo: item.supportVideo || false,
|
||||||
supportTool: item.supportTool || false,
|
supportTool: item.supportTool ?? null,
|
||||||
supportFree: item.supportFree || false,
|
supportFree: item.supportFree || false,
|
||||||
supportToolMessage:
|
supportToolMessage: item.supportToolMessage ?? null,
|
||||||
item.supportToolMessage === undefined ? true : item.supportToolMessage,
|
|
||||||
options: normalizeModelOptions(item.options),
|
options: normalizeModelOptions(item.options),
|
||||||
});
|
});
|
||||||
selectedModelType.value = normalizeSelectableModelType(item.modelType);
|
selectedModelType.value = normalizeSelectableModelType(item.modelType);
|
||||||
@@ -307,9 +342,65 @@ defineExpose({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const closeDialog = () => {
|
const closeDialog = () => {
|
||||||
|
capabilityRequestSequence += 1;
|
||||||
dialogVisible.value = false;
|
dialogVisible.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const detectModelCapabilities = async () => {
|
||||||
|
const modelName = formData.modelName.trim();
|
||||||
|
if (!modelName || manuallyEditedModelName === modelName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestSequence = ++capabilityRequestSequence;
|
||||||
|
capabilityLoading.value = true;
|
||||||
|
try {
|
||||||
|
const providerId = isAdd.value
|
||||||
|
? selectedProviderId.value
|
||||||
|
: formData.providerId;
|
||||||
|
const res = await resolveModelCapabilities({ modelName, providerId });
|
||||||
|
if (
|
||||||
|
requestSequence !== capabilityRequestSequence ||
|
||||||
|
res.errorCode !== 0 ||
|
||||||
|
!res.data
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const capability = res.data;
|
||||||
|
manuallyEditedModelName = '';
|
||||||
|
if (!capability.detected) {
|
||||||
|
if (autoDetectedModelType.value) {
|
||||||
|
selectedModelType.value = '';
|
||||||
|
}
|
||||||
|
autoDetectedModelType.value = false;
|
||||||
|
formData.supportThinking = null;
|
||||||
|
formData.supportTool = null;
|
||||||
|
formData.supportImage = null;
|
||||||
|
formData.supportToolMessage = null;
|
||||||
|
syncTagSelectedStatus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
autoDetectedModelType.value = true;
|
||||||
|
formData.modelType = capability.modelType;
|
||||||
|
selectedModelType.value = normalizeSelectableModelType(
|
||||||
|
capability.modelType,
|
||||||
|
);
|
||||||
|
formData.supportThinking = capability.supportThinking ?? null;
|
||||||
|
formData.supportTool = capability.supportTool ?? null;
|
||||||
|
formData.supportImage = capability.supportImage ?? null;
|
||||||
|
formData.supportToolMessage = capability.supportTool ?? null;
|
||||||
|
syncTagSelectedStatus();
|
||||||
|
} catch {
|
||||||
|
// 自动识别失败不阻塞表单,保存时后端仍会再次解析能力。
|
||||||
|
} finally {
|
||||||
|
if (requestSequence === capabilityRequestSequence) {
|
||||||
|
capabilityLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
title: [{ required: true, message: $t('message.required'), trigger: 'blur' }],
|
title: [{ required: true, message: $t('message.required'), trigger: 'blur' }],
|
||||||
modelName: [
|
modelName: [
|
||||||
@@ -323,19 +414,11 @@ const rules = {
|
|||||||
const save = async () => {
|
const save = async () => {
|
||||||
btnLoading.value = true;
|
btnLoading.value = true;
|
||||||
const modelType = resolveModelType();
|
const modelType = resolveModelType();
|
||||||
const features = generateFeaturesFromModelAbility(modelAbility.value);
|
|
||||||
|
|
||||||
if (modelType !== 'chatModel') {
|
|
||||||
for (const key of Object.keys(features) as Array<keyof typeof features>) {
|
|
||||||
features[key] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await formDataRef.value.validate();
|
await formDataRef.value.validate();
|
||||||
const submitData = {
|
const submitData = {
|
||||||
...formData,
|
...formData,
|
||||||
...features,
|
|
||||||
modelType,
|
modelType,
|
||||||
providerId: isAdd.value ? selectedProviderId.value : formData.providerId,
|
providerId: isAdd.value ? selectedProviderId.value : formData.providerId,
|
||||||
};
|
};
|
||||||
@@ -393,6 +476,8 @@ const save = async () => {
|
|||||||
<ElInput
|
<ElInput
|
||||||
v-model.trim="formData.modelName"
|
v-model.trim="formData.modelName"
|
||||||
placeholder="例如:gpt-4.1 / glm-4.5 / qwen3:8b"
|
placeholder="例如:gpt-4.1 / glm-4.5 / qwen3:8b"
|
||||||
|
@blur="detectModelCapabilities"
|
||||||
|
@input="handleModelNameInput"
|
||||||
/>
|
/>
|
||||||
</ElFormItem>
|
</ElFormItem>
|
||||||
<ElFormItem prop="groupName" :label="$t('llm.groupName')">
|
<ElFormItem prop="groupName" :label="$t('llm.groupName')">
|
||||||
@@ -402,21 +487,40 @@ const save = async () => {
|
|||||||
/>
|
/>
|
||||||
</ElFormItem>
|
</ElFormItem>
|
||||||
|
|
||||||
<ElFormItem
|
<ElFormItem class="model-modal__ability-item">
|
||||||
:label="$t('llm.ability')"
|
<template #label>
|
||||||
class="model-modal__ability-item"
|
<span class="model-modal__ability-label">
|
||||||
|
{{ $t('llm.ability') }}
|
||||||
|
<ElTooltip
|
||||||
|
:content="$t('llm.abilityChangeTip')"
|
||||||
|
effect="light"
|
||||||
|
placement="top"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="model-modal__ability-info"
|
||||||
|
:aria-label="$t('llm.abilityChangeTip')"
|
||||||
|
>
|
||||||
|
<ElIcon><InfoFilled /></ElIcon>
|
||||||
|
</button>
|
||||||
|
</ElTooltip>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<div
|
||||||
|
class="model-modal__ability-panel"
|
||||||
|
:aria-busy="capabilityLoading"
|
||||||
>
|
>
|
||||||
<div class="model-modal__ability-panel">
|
|
||||||
<div class="model-modal__ability-toolbar">
|
<div class="model-modal__ability-toolbar">
|
||||||
<button
|
<button
|
||||||
v-for="item in modelTypeAbilityOptions"
|
v-for="item in modelTypeAbilityOptions"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
type="button"
|
type="button"
|
||||||
class="model-modal__ability-chip"
|
class="model-modal__ability-chip is-interactive"
|
||||||
:class="[
|
:class="[
|
||||||
`is-tone-${item.value}`,
|
`is-tone-${item.value}`,
|
||||||
{ 'is-active': selectedModelType === item.value },
|
{ 'is-active': selectedModelType === item.value },
|
||||||
]"
|
]"
|
||||||
|
:aria-pressed="selectedModelType === item.value"
|
||||||
@click="handleModelTypeChipClick(item.value)"
|
@click="handleModelTypeChipClick(item.value)"
|
||||||
>
|
>
|
||||||
<IconifyIcon
|
<IconifyIcon
|
||||||
@@ -433,14 +537,15 @@ const save = async () => {
|
|||||||
v-for="item in visibleModelAbility"
|
v-for="item in visibleModelAbility"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
type="button"
|
type="button"
|
||||||
class="model-modal__ability-chip"
|
class="model-modal__ability-chip is-interactive"
|
||||||
:class="{
|
:class="{
|
||||||
'is-active': item.selected,
|
'is-active': item.selected,
|
||||||
'is-disabled': isAbilityChipDisabled(),
|
'is-disabled': hasSpecialModelType,
|
||||||
[`is-tone-${item.value}`]: true,
|
[`is-tone-${item.value}`]: true,
|
||||||
}"
|
}"
|
||||||
:disabled="isAbilityChipDisabled()"
|
:aria-pressed="item.selected"
|
||||||
@click="handleTagClick(item)"
|
:disabled="hasSpecialModelType"
|
||||||
|
@click="handleAbilityChipClick(item)"
|
||||||
>
|
>
|
||||||
<IconifyIcon
|
<IconifyIcon
|
||||||
:icon="getAbilityIcon(item.value)"
|
:icon="getAbilityIcon(item.value)"
|
||||||
@@ -448,11 +553,33 @@ const save = async () => {
|
|||||||
/>
|
/>
|
||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
</button>
|
</button>
|
||||||
|
<ElIcon
|
||||||
|
v-if="capabilityLoading"
|
||||||
|
class="model-modal__ability-loading is-loading"
|
||||||
|
aria-label="正在识别模型能力"
|
||||||
|
>
|
||||||
|
<Loading />
|
||||||
|
</ElIcon>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ElFormItem>
|
</ElFormItem>
|
||||||
|
|
||||||
<ElFormItem v-if="!hasSpecialModelType" label="Agent HTTP 传输">
|
<div v-if="!hasSpecialModelType" class="model-modal__advanced">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="model-modal__advanced-toggle"
|
||||||
|
:aria-expanded="showAdvanced"
|
||||||
|
@click="showAdvanced = !showAdvanced"
|
||||||
|
>
|
||||||
|
<span>高级设置</span>
|
||||||
|
<ElIcon>
|
||||||
|
<ArrowUp v-if="showAdvanced" />
|
||||||
|
<ArrowDown v-else />
|
||||||
|
</ElIcon>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div v-if="showAdvanced" class="model-modal__advanced-body">
|
||||||
|
<ElFormItem label="Agent HTTP 传输">
|
||||||
<ElSelect
|
<ElSelect
|
||||||
v-model="formData.options.agentHttpVersionPolicy"
|
v-model="formData.options.agentHttpVersionPolicy"
|
||||||
aria-label="Agent HTTP 传输"
|
aria-label="Agent HTTP 传输"
|
||||||
@@ -465,7 +592,7 @@ const save = async () => {
|
|||||||
/>
|
/>
|
||||||
</ElSelect>
|
</ElSelect>
|
||||||
</ElFormItem>
|
</ElFormItem>
|
||||||
<ElFormItem v-if="!hasSpecialModelType" label="System 消息格式">
|
<ElFormItem label="System 消息格式">
|
||||||
<ElSelect
|
<ElSelect
|
||||||
v-model="formData.options.agentSystemContentFormat"
|
v-model="formData.options.agentSystemContentFormat"
|
||||||
aria-label="System 消息格式"
|
aria-label="System 消息格式"
|
||||||
@@ -479,6 +606,8 @@ const save = async () => {
|
|||||||
</ElSelect>
|
</ElSelect>
|
||||||
</ElFormItem>
|
</ElFormItem>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</ElForm>
|
</ElForm>
|
||||||
</div>
|
</div>
|
||||||
</EasyFlowFormModal>
|
</EasyFlowFormModal>
|
||||||
@@ -511,6 +640,33 @@ const save = async () => {
|
|||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.model-modal__ability-label {
|
||||||
|
display: inline-flex;
|
||||||
|
gap: var(--space-1);
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__ability-info {
|
||||||
|
display: inline-flex;
|
||||||
|
padding: 0;
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
cursor: help;
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
border-radius: var(--radius-control);
|
||||||
|
transition: color var(--motion-duration-base) var(--motion-ease-standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__ability-info:hover,
|
||||||
|
.model-modal__ability-info:focus-visible {
|
||||||
|
color: hsl(var(--primary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__ability-info:focus-visible {
|
||||||
|
outline: 2px solid hsl(var(--primary) / 24%);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.model-modal__ability-panel {
|
.model-modal__ability-panel {
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -543,7 +699,7 @@ const save = async () => {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
color: hsl(var(--text-muted));
|
color: hsl(var(--text-muted));
|
||||||
cursor: pointer;
|
cursor: default;
|
||||||
background: hsl(var(--surface-contrast-soft) / 86%);
|
background: hsl(var(--surface-contrast-soft) / 86%);
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
border-radius: 999px;
|
border-radius: 999px;
|
||||||
@@ -555,8 +711,12 @@ const save = async () => {
|
|||||||
box-shadow 0.2s ease;
|
box-shadow 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.model-modal__ability-chip:hover:not(:disabled),
|
.model-modal__ability-chip.is-interactive {
|
||||||
.model-modal__ability-chip:focus-visible:not(:disabled) {
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__ability-chip.is-interactive:hover,
|
||||||
|
.model-modal__ability-chip.is-interactive:focus-visible {
|
||||||
color: hsl(var(--text-strong));
|
color: hsl(var(--text-strong));
|
||||||
box-shadow: 0 10px 18px -14px hsl(var(--foreground) / 28%);
|
box-shadow: 0 10px 18px -14px hsl(var(--foreground) / 28%);
|
||||||
transform: translateY(-1px);
|
transform: translateY(-1px);
|
||||||
@@ -570,7 +730,7 @@ const save = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.model-modal__ability-chip.is-disabled {
|
.model-modal__ability-chip.is-disabled {
|
||||||
cursor: not-allowed;
|
cursor: default;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
opacity: 0.56;
|
opacity: 0.56;
|
||||||
transform: none;
|
transform: none;
|
||||||
@@ -581,9 +741,13 @@ const save = async () => {
|
|||||||
opacity: 0.88;
|
opacity: 0.88;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.model-modal__ability-loading {
|
||||||
|
margin-inline-start: var(--space-1);
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
}
|
||||||
|
|
||||||
.model-modal__ability-chip.is-active.is-tone-embeddingModel,
|
.model-modal__ability-chip.is-active.is-tone-embeddingModel,
|
||||||
.model-modal__ability-chip.is-active.is-tone-thinking,
|
.model-modal__ability-chip.is-active.is-tone-thinking {
|
||||||
.model-modal__ability-chip.is-active.is-tone-toolMessage {
|
|
||||||
color: hsl(var(--primary));
|
color: hsl(var(--primary));
|
||||||
background: hsl(var(--primary) / 10%);
|
background: hsl(var(--primary) / 10%);
|
||||||
border-color: hsl(var(--primary) / 18%);
|
border-color: hsl(var(--primary) / 18%);
|
||||||
@@ -598,21 +762,56 @@ const save = async () => {
|
|||||||
box-shadow: inset 0 0 0 1px hsl(var(--warning) / 14%);
|
box-shadow: inset 0 0 0 1px hsl(var(--warning) / 14%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.model-modal__ability-chip.is-active.is-tone-image,
|
.model-modal__ability-chip.is-active.is-tone-image {
|
||||||
.model-modal__ability-chip.is-active.is-tone-imageB64 {
|
|
||||||
color: hsl(var(--success));
|
color: hsl(var(--success));
|
||||||
background: hsl(var(--success) / 12%);
|
background: hsl(var(--success) / 12%);
|
||||||
border-color: hsl(var(--success) / 18%);
|
border-color: hsl(var(--success) / 18%);
|
||||||
box-shadow: inset 0 0 0 1px hsl(var(--success) / 14%);
|
box-shadow: inset 0 0 0 1px hsl(var(--success) / 14%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.model-modal__ability-chip.is-active.is-tone-audio,
|
.model-modal__advanced {
|
||||||
.model-modal__ability-chip.is-active.is-tone-video,
|
display: flex;
|
||||||
.model-modal__ability-chip.is-active.is-tone-free {
|
flex-direction: column;
|
||||||
color: hsl(var(--danger));
|
gap: var(--space-3);
|
||||||
background: hsl(var(--danger) / 10%);
|
}
|
||||||
border-color: hsl(var(--danger) / 16%);
|
|
||||||
box-shadow: inset 0 0 0 1px hsl(var(--danger) / 12%);
|
.model-modal__advanced-toggle {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
padding: var(--space-2) var(--space-3);
|
||||||
|
font-size: 13px;
|
||||||
|
color: hsl(var(--text-muted));
|
||||||
|
cursor: pointer;
|
||||||
|
background: hsl(var(--surface-contrast-soft) / 68%);
|
||||||
|
border: 1px solid hsl(var(--divider-faint) / 56%);
|
||||||
|
border-radius: var(--radius-control);
|
||||||
|
transition:
|
||||||
|
color var(--motion-duration-base) var(--motion-ease-standard),
|
||||||
|
border-color var(--motion-duration-base) var(--motion-ease-standard),
|
||||||
|
background var(--motion-duration-base) var(--motion-ease-standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__advanced-toggle:hover,
|
||||||
|
.model-modal__advanced-toggle:focus-visible {
|
||||||
|
color: hsl(var(--text-strong));
|
||||||
|
background: hsl(var(--surface-contrast-soft));
|
||||||
|
border-color: hsl(var(--divider-faint));
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__advanced-body :deep(.el-form-item) {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__advanced-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-modal__advanced-body :deep(.el-select) {
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const formData = reactive({
|
|||||||
|
|
||||||
const resultTitle = computed(() => {
|
const resultTitle = computed(() => {
|
||||||
if (verifyStatus.value === 'success') {
|
if (verifyStatus.value === 'success') {
|
||||||
return '验证成功';
|
return '验证通过';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verifyStatus.value === 'error') {
|
if (verifyStatus.value === 'error') {
|
||||||
@@ -41,7 +41,7 @@ const resultTitle = computed(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (verifyStatus.value === 'warning') {
|
if (verifyStatus.value === 'warning') {
|
||||||
return '流式不可用';
|
return '验证通过';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '等待验证';
|
return '等待验证';
|
||||||
@@ -145,7 +145,7 @@ const save = async () => {
|
|||||||
<section class="verify-modal__section">
|
<section class="verify-modal__section">
|
||||||
<div class="verify-modal__section-head">
|
<div class="verify-modal__section-head">
|
||||||
<h3>1. 选择待验证模型</h3>
|
<h3>1. 选择待验证模型</h3>
|
||||||
<p>会用当前保存的配置检查基础连接和流式响应。</p>
|
<p>使用当前保存的配置验证模型。</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ElForm
|
<ElForm
|
||||||
|
|||||||
@@ -96,6 +96,9 @@ const handleVerifyLlm = async (llm: llmType) => {
|
|||||||
const res = await verifyModelConfig(modelId);
|
const res = await verifyModelConfig(modelId);
|
||||||
|
|
||||||
const feedback = resolveModelVerificationFeedback(res, llm.modelType);
|
const feedback = resolveModelVerificationFeedback(res, llm.modelType);
|
||||||
|
if (typeof res.data?.supportTool === 'boolean') {
|
||||||
|
llm.supportTool = res.data.supportTool;
|
||||||
|
}
|
||||||
setVerifyStatus(modelId, feedback.status);
|
setVerifyStatus(modelId, feedback.status);
|
||||||
|
|
||||||
if (feedback.status === 'success') {
|
if (feedback.status === 'success') {
|
||||||
|
|||||||
@@ -184,19 +184,15 @@ const upstreamModelName = computed(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const capabilityTags = computed(() => {
|
const capabilityTags = computed(() => {
|
||||||
const tags = ['文本', '流式'];
|
const tags = ['文本'];
|
||||||
|
if (selectedModel.value?.supportThinking) {
|
||||||
|
tags.push('推理');
|
||||||
|
}
|
||||||
if (selectedModel.value?.supportImage) {
|
if (selectedModel.value?.supportImage) {
|
||||||
tags.push(
|
tags.push('视觉');
|
||||||
selectedModel.value?.supportImageB64Only
|
|
||||||
? '图片输入(Base64)'
|
|
||||||
: '图片输入',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (selectedModel.value?.supportTool) {
|
if (selectedModel.value?.supportTool) {
|
||||||
tags.push('tools');
|
tags.push('工具');
|
||||||
}
|
|
||||||
if (selectedModel.value?.supportToolMessage) {
|
|
||||||
tags.push('tool 消息');
|
|
||||||
}
|
}
|
||||||
return tags;
|
return tags;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import { getDefaultModelAbility, handleTagClick } from '../model-ability';
|
||||||
|
|
||||||
|
describe('model ability labels', () => {
|
||||||
|
it('只保留当前可用的视觉、推理和工具能力', () => {
|
||||||
|
const abilities = getDefaultModelAbility();
|
||||||
|
|
||||||
|
expect(abilities.map((item) => item.field)).toEqual([
|
||||||
|
'supportThinking',
|
||||||
|
'supportTool',
|
||||||
|
'supportImage',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('支持手动切换自动识别的能力', () => {
|
||||||
|
const abilities = getDefaultModelAbility();
|
||||||
|
const toolAbility = abilities.find((item) => item.field === 'supportTool');
|
||||||
|
const formData = {
|
||||||
|
supportImage: false,
|
||||||
|
supportThinking: false,
|
||||||
|
supportTool: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(toolAbility).toBeDefined();
|
||||||
|
if (!toolAbility) {
|
||||||
|
throw new Error('缺少工具能力标签');
|
||||||
|
}
|
||||||
|
|
||||||
|
handleTagClick(toolAbility, formData);
|
||||||
|
|
||||||
|
expect(toolAbility.selected).toBe(true);
|
||||||
|
expect(formData.supportTool).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '../model-verification';
|
} from '../model-verification';
|
||||||
|
|
||||||
describe('model verification helpers', () => {
|
describe('model verification helpers', () => {
|
||||||
it('双阶段通过时返回成功状态', () => {
|
it('验证通过时只返回统一成功文案', () => {
|
||||||
expect(
|
expect(
|
||||||
resolveModelVerificationFeedback(
|
resolveModelVerificationFeedback(
|
||||||
{
|
{
|
||||||
@@ -17,12 +17,12 @@ describe('model verification helpers', () => {
|
|||||||
),
|
),
|
||||||
).toEqual({
|
).toEqual({
|
||||||
dimension: undefined,
|
dimension: undefined,
|
||||||
message: '验证成功',
|
message: '验证通过',
|
||||||
status: 'success',
|
status: 'success',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('基础连接通过但流式失败时返回警告状态', () => {
|
it('旧版部分通过结果也收敛为统一成功文案', () => {
|
||||||
const feedback = resolveModelVerificationFeedback(
|
const feedback = resolveModelVerificationFeedback(
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
@@ -34,9 +34,9 @@ describe('model verification helpers', () => {
|
|||||||
'chatModel',
|
'chatModel',
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(feedback.status).toBe('warning');
|
expect(feedback.status).toBe('success');
|
||||||
expect(feedback.message).toContain('流式响应不可用');
|
expect(feedback.message).toBe('验证通过');
|
||||||
expect(getVerifyButtonText('warning')).toBe('流式不可用');
|
expect(getVerifyButtonText('warning')).toBe('验证通过');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('向量模型验证保留维度结果', () => {
|
it('向量模型验证保留维度结果', () => {
|
||||||
@@ -47,7 +47,7 @@ describe('model verification helpers', () => {
|
|||||||
),
|
),
|
||||||
).toEqual({
|
).toEqual({
|
||||||
dimension: 1024,
|
dimension: 1024,
|
||||||
message: '验证成功,向量维度:1024',
|
message: '验证通过',
|
||||||
status: 'success',
|
status: 'success',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
export type BooleanField =
|
export type BooleanField = 'supportImage' | 'supportThinking' | 'supportTool';
|
||||||
| 'supportAudio'
|
|
||||||
| 'supportImage'
|
|
||||||
| 'supportImageB64Only'
|
|
||||||
| 'supportThinking'
|
|
||||||
| 'supportTool'
|
|
||||||
| 'supportToolMessage'
|
|
||||||
| 'supportVideo';
|
|
||||||
|
|
||||||
export interface ModelAbilityItem {
|
export interface ModelAbilityItem {
|
||||||
activeType: 'danger' | 'info' | 'primary' | 'success' | 'warning';
|
activeType: 'danger' | 'info' | 'primary' | 'success' | 'warning';
|
||||||
@@ -39,14 +32,6 @@ export const getDefaultModelAbility = (): ModelAbilityItem[] => [
|
|||||||
selected: false,
|
selected: false,
|
||||||
field: 'supportTool',
|
field: 'supportTool',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: $t('llm.modelAbility.supportVideo'),
|
|
||||||
value: 'video',
|
|
||||||
defaultType: 'info',
|
|
||||||
activeType: 'success',
|
|
||||||
selected: false,
|
|
||||||
field: 'supportVideo',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: $t('llm.modelAbility.supportImage'),
|
label: $t('llm.modelAbility.supportImage'),
|
||||||
value: 'image',
|
value: 'image',
|
||||||
@@ -55,30 +40,6 @@ export const getDefaultModelAbility = (): ModelAbilityItem[] => [
|
|||||||
selected: false,
|
selected: false,
|
||||||
field: 'supportImage',
|
field: 'supportImage',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: $t('llm.modelAbility.supportAudio'),
|
|
||||||
value: 'audio',
|
|
||||||
defaultType: 'info',
|
|
||||||
activeType: 'success',
|
|
||||||
selected: false,
|
|
||||||
field: 'supportAudio',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: $t('llm.modelAbility.supportImageB64Only'),
|
|
||||||
value: 'imageB64',
|
|
||||||
defaultType: 'info',
|
|
||||||
activeType: 'success',
|
|
||||||
selected: false,
|
|
||||||
field: 'supportImageB64Only',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: $t('llm.modelAbility.supportToolMessage'),
|
|
||||||
value: 'toolMessage',
|
|
||||||
defaultType: 'info',
|
|
||||||
activeType: 'success',
|
|
||||||
selected: true,
|
|
||||||
field: 'supportToolMessage',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +69,7 @@ export const getTagsSelectedStatus = (
|
|||||||
*/
|
*/
|
||||||
export const syncTagSelectedStatus = (
|
export const syncTagSelectedStatus = (
|
||||||
modelAbility: ModelAbilityItem[],
|
modelAbility: ModelAbilityItem[],
|
||||||
formData: Record<BooleanField, boolean>,
|
formData: Record<BooleanField, boolean | null>,
|
||||||
): void => {
|
): void => {
|
||||||
modelAbility.forEach((tag) => {
|
modelAbility.forEach((tag) => {
|
||||||
tag.selected = formData[tag.field] ?? false;
|
tag.selected = formData[tag.field] ?? false;
|
||||||
@@ -121,9 +82,8 @@ export const syncTagSelectedStatus = (
|
|||||||
* @param formData 表单数据对象
|
* @param formData 表单数据对象
|
||||||
*/
|
*/
|
||||||
export const handleTagClick = (
|
export const handleTagClick = (
|
||||||
// modelAbility: ModelAbilityItem[],
|
|
||||||
item: ModelAbilityItem,
|
item: ModelAbilityItem,
|
||||||
formData: Record<BooleanField, boolean>,
|
formData: Record<BooleanField, boolean | null>,
|
||||||
): void => {
|
): void => {
|
||||||
// 切换标签选中状态
|
// 切换标签选中状态
|
||||||
item.selected = !item.selected;
|
item.selected = !item.selected;
|
||||||
@@ -152,7 +112,4 @@ export const getAllBooleanFields = (): BooleanField[] => [
|
|||||||
'supportThinking',
|
'supportThinking',
|
||||||
'supportTool',
|
'supportTool',
|
||||||
'supportImage',
|
'supportImage',
|
||||||
'supportImageB64Only',
|
|
||||||
'supportVideo',
|
|
||||||
'supportAudio',
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -19,12 +19,9 @@ interface ModelVerificationResponse {
|
|||||||
message?: string;
|
message?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const STREAMING_UNAVAILABLE_MESSAGE =
|
|
||||||
'连接成功,流式响应不可用,可关闭智能体的模型流式响应。';
|
|
||||||
|
|
||||||
export function resolveModelVerificationFeedback(
|
export function resolveModelVerificationFeedback(
|
||||||
response: ModelVerificationResponse,
|
response: ModelVerificationResponse,
|
||||||
modelType: string,
|
_modelType: string,
|
||||||
): ModelVerificationFeedback {
|
): ModelVerificationFeedback {
|
||||||
if (response.errorCode !== 0) {
|
if (response.errorCode !== 0) {
|
||||||
return {
|
return {
|
||||||
@@ -33,13 +30,6 @@ export function resolveModelVerificationFeedback(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.data?.status === 'PARTIAL') {
|
|
||||||
return {
|
|
||||||
message: response.data.message || STREAMING_UNAVAILABLE_MESSAGE,
|
|
||||||
status: 'warning',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.data?.status === 'FAILED') {
|
if (response.data?.status === 'FAILED') {
|
||||||
return {
|
return {
|
||||||
message: response.data.message || '验证失败',
|
message: response.data.message || '验证失败',
|
||||||
@@ -50,10 +40,7 @@ export function resolveModelVerificationFeedback(
|
|||||||
const dimension = response.data?.dimension;
|
const dimension = response.data?.dimension;
|
||||||
return {
|
return {
|
||||||
dimension,
|
dimension,
|
||||||
message:
|
message: '验证通过',
|
||||||
modelType === 'embeddingModel' && dimension
|
|
||||||
? `验证成功,向量维度:${dimension}`
|
|
||||||
: response.data?.message || '验证成功',
|
|
||||||
status: 'success',
|
status: 'success',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -63,10 +50,10 @@ export function getVerifyButtonText(status: VerifyButtonStatus): string {
|
|||||||
return '验证中';
|
return '验证中';
|
||||||
}
|
}
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
return '验证成功';
|
return '验证通过';
|
||||||
}
|
}
|
||||||
if (status === 'warning') {
|
if (status === 'warning') {
|
||||||
return '流式不可用';
|
return '验证通过';
|
||||||
}
|
}
|
||||||
if (status === 'error') {
|
if (status === 'error') {
|
||||||
return '验证失败';
|
return '验证失败';
|
||||||
|
|||||||
Reference in New Issue
Block a user