63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
const AGENT_AUTO_MODEL_KEY = "agentAutoModel";
|
|
|
|
function toRecord(value: unknown): Record<string, unknown> | null {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
return null;
|
|
}
|
|
return value as Record<string, unknown>;
|
|
}
|
|
|
|
export function isAiModelAgentAuto(input: {
|
|
defaultParams?: unknown;
|
|
capabilities?: unknown;
|
|
modelId?: string | null;
|
|
displayName?: string | null;
|
|
supportsVision?: boolean | null;
|
|
supportsImageGen?: boolean | null;
|
|
}): boolean {
|
|
const defaultParams = toRecord(input.defaultParams);
|
|
if (typeof defaultParams?.[AGENT_AUTO_MODEL_KEY] === "boolean") {
|
|
return defaultParams[AGENT_AUTO_MODEL_KEY] as boolean;
|
|
}
|
|
|
|
const capabilities = toRecord(input.capabilities);
|
|
if (typeof capabilities?.[AGENT_AUTO_MODEL_KEY] === "boolean") {
|
|
return capabilities[AGENT_AUTO_MODEL_KEY] as boolean;
|
|
}
|
|
|
|
const supportsVision = Boolean(input.supportsVision);
|
|
const supportsImageGen = Boolean(input.supportsImageGen);
|
|
if (!supportsVision || supportsImageGen) {
|
|
return false;
|
|
}
|
|
|
|
const modelText = `${input.modelId || ""} ${input.displayName || ""}`.toLowerCase();
|
|
const isQwenLikeModel =
|
|
modelText.includes("qwen") || modelText.includes("通义");
|
|
const isVisionLikeModel =
|
|
modelText.includes("vl") ||
|
|
modelText.includes("vision") ||
|
|
modelText.includes("多模态");
|
|
|
|
if (isQwenLikeModel && isVisionLikeModel) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
export function withAgentAutoModelFlag(
|
|
defaultParams: unknown,
|
|
enabled: boolean
|
|
): Record<string, unknown> | null {
|
|
const next = { ...(toRecord(defaultParams) || {}) };
|
|
|
|
if (enabled) {
|
|
next[AGENT_AUTO_MODEL_KEY] = true;
|
|
} else {
|
|
delete next[AGENT_AUTO_MODEL_KEY];
|
|
}
|
|
|
|
return Object.keys(next).length > 0 ? next : null;
|
|
}
|