From a0999bfcde26e0987ab616abcedd136b79a6845b Mon Sep 17 00:00:00 2001 From: 134 Date: Tue, 25 Aug 2026 14:03:25 +0800 Subject: [PATCH] fix(canvas): decouple text detection from image provider --- lib/ai/qwen25-vl.ts | 14 ++++++++------ lib/ai/qwen3-vl.ts | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/ai/qwen25-vl.ts b/lib/ai/qwen25-vl.ts index fe65193aa..215a2aa81 100644 --- a/lib/ai/qwen25-vl.ts +++ b/lib/ai/qwen25-vl.ts @@ -27,14 +27,16 @@ function parseAssistantText(payload: any): string { return ""; } -async function getQwenImageProviderApiKey() { +async function getQwenVisionProviderApiKey() { const providers = await getEnabledAiProviders(); - const provider = providers.find( - (item) => item.type === "alibaba-image" && typeof item.apiKey === "string" && item.apiKey.trim(), - ); + const hasApiKey = (item: (typeof providers)[number]) => + typeof item.apiKey === "string" && Boolean(item.apiKey.trim()); + const provider = + providers.find((item) => item.type === "alibaba" && hasApiKey(item)) || + providers.find((item) => item.type === "alibaba-image" && hasApiKey(item)); if (!provider?.apiKey) { - throw new Error("未配置可用的千问生图 Provider API Key"); + throw new Error("未配置可用的阿里云多模态 Provider API Key"); } return provider.apiKey.trim(); @@ -46,7 +48,7 @@ export async function callQwen25Vl(params: { temperature?: number; maxTokens?: number; }) { - const apiKey = await getQwenImageProviderApiKey(); + const apiKey = await getQwenVisionProviderApiKey(); const endpoint = `${QWEN_COMPAT_BASE_URL}/chat/completions`; let lastError: Error | null = null; diff --git a/lib/ai/qwen3-vl.ts b/lib/ai/qwen3-vl.ts index 2196d77d7..5f1034c14 100644 --- a/lib/ai/qwen3-vl.ts +++ b/lib/ai/qwen3-vl.ts @@ -27,14 +27,16 @@ function parseAssistantText(payload: any): string { return ""; } -async function getQwenImageProviderApiKey() { +async function getQwenVisionProviderApiKey() { const providers = await getEnabledAiProviders(); - const provider = providers.find( - (item) => item.type === "alibaba-image" && typeof item.apiKey === "string" && item.apiKey.trim(), - ); + const hasApiKey = (item: (typeof providers)[number]) => + typeof item.apiKey === "string" && Boolean(item.apiKey.trim()); + const provider = + providers.find((item) => item.type === "alibaba" && hasApiKey(item)) || + providers.find((item) => item.type === "alibaba-image" && hasApiKey(item)); if (!provider?.apiKey) { - throw new Error("未配置可用的千问生图 Provider API Key"); + throw new Error("未配置可用的阿里云多模态 Provider API Key"); } return provider.apiKey.trim(); @@ -50,7 +52,7 @@ export async function callQwen3Vl(params: { timeoutMs?: number; retries?: number; }) { - const apiKey = await getQwenImageProviderApiKey(); + const apiKey = await getQwenVisionProviderApiKey(); const endpoint = `${QWEN_COMPAT_BASE_URL}/chat/completions`; const timeoutMs = Math.max(10000, Math.min(params.timeoutMs ?? 45000, 120000)); const retries = Math.max(0, Math.min(params.retries ?? 1, 2));