fix(canvas): decouple text detection from image provider
This commit is contained in:
parent
d120e0ddb6
commit
a0999bfcde
@ -27,14 +27,16 @@ function parseAssistantText(payload: any): string {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getQwenImageProviderApiKey() {
|
async function getQwenVisionProviderApiKey() {
|
||||||
const providers = await getEnabledAiProviders();
|
const providers = await getEnabledAiProviders();
|
||||||
const provider = providers.find(
|
const hasApiKey = (item: (typeof providers)[number]) =>
|
||||||
(item) => item.type === "alibaba-image" && typeof item.apiKey === "string" && item.apiKey.trim(),
|
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) {
|
if (!provider?.apiKey) {
|
||||||
throw new Error("未配置可用的千问生图 Provider API Key");
|
throw new Error("未配置可用的阿里云多模态 Provider API Key");
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider.apiKey.trim();
|
return provider.apiKey.trim();
|
||||||
@ -46,7 +48,7 @@ export async function callQwen25Vl(params: {
|
|||||||
temperature?: number;
|
temperature?: number;
|
||||||
maxTokens?: number;
|
maxTokens?: number;
|
||||||
}) {
|
}) {
|
||||||
const apiKey = await getQwenImageProviderApiKey();
|
const apiKey = await getQwenVisionProviderApiKey();
|
||||||
const endpoint = `${QWEN_COMPAT_BASE_URL}/chat/completions`;
|
const endpoint = `${QWEN_COMPAT_BASE_URL}/chat/completions`;
|
||||||
|
|
||||||
let lastError: Error | null = null;
|
let lastError: Error | null = null;
|
||||||
|
|||||||
@ -27,14 +27,16 @@ function parseAssistantText(payload: any): string {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getQwenImageProviderApiKey() {
|
async function getQwenVisionProviderApiKey() {
|
||||||
const providers = await getEnabledAiProviders();
|
const providers = await getEnabledAiProviders();
|
||||||
const provider = providers.find(
|
const hasApiKey = (item: (typeof providers)[number]) =>
|
||||||
(item) => item.type === "alibaba-image" && typeof item.apiKey === "string" && item.apiKey.trim(),
|
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) {
|
if (!provider?.apiKey) {
|
||||||
throw new Error("未配置可用的千问生图 Provider API Key");
|
throw new Error("未配置可用的阿里云多模态 Provider API Key");
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider.apiKey.trim();
|
return provider.apiKey.trim();
|
||||||
@ -50,7 +52,7 @@ export async function callQwen3Vl(params: {
|
|||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
retries?: number;
|
retries?: number;
|
||||||
}) {
|
}) {
|
||||||
const apiKey = await getQwenImageProviderApiKey();
|
const apiKey = await getQwenVisionProviderApiKey();
|
||||||
const endpoint = `${QWEN_COMPAT_BASE_URL}/chat/completions`;
|
const endpoint = `${QWEN_COMPAT_BASE_URL}/chat/completions`;
|
||||||
const timeoutMs = Math.max(10000, Math.min(params.timeoutMs ?? 45000, 120000));
|
const timeoutMs = Math.max(10000, Math.min(params.timeoutMs ?? 45000, 120000));
|
||||||
const retries = Math.max(0, Math.min(params.retries ?? 1, 2));
|
const retries = Math.max(0, Math.min(params.retries ?? 1, 2));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user