fix(canvas): decouple text detection from image provider
This commit is contained in:
parent
4b5540f3c2
commit
f95c6b2b2b
@ -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;
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user