Fix DashScope env loading for scene image generation
This commit is contained in:
@@ -9,6 +9,7 @@ const ENABLE_LLM_DEBUG_LOG = Boolean(ENV.DEV) || ENV.VITE_LLM_DEBUG_LOG === 'tru
|
||||
export interface PlainTextCompletionOptions {
|
||||
timeoutMs?: number;
|
||||
debugLabel?: string;
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
export class LlmConnectivityError extends Error {
|
||||
@@ -71,7 +72,9 @@ async function requestMessageContent(
|
||||
) {
|
||||
const timeoutMs = options.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
||||
const debugLabel = options.debugLabel ?? 'chat';
|
||||
const externalSignal = options.signal;
|
||||
const controller = new AbortController();
|
||||
const handleExternalAbort = () => controller.abort();
|
||||
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
||||
const startedAt = performance.now();
|
||||
const requestBody = {
|
||||
@@ -83,6 +86,16 @@ async function requestMessageContent(
|
||||
};
|
||||
const rawPromptText = `[System]\n${systemPrompt}\n\n[User]\n${userPrompt}`;
|
||||
|
||||
if (externalSignal) {
|
||||
if (externalSignal.aborted) {
|
||||
handleExternalAbort();
|
||||
} else {
|
||||
externalSignal.addEventListener('abort', handleExternalAbort, {
|
||||
once: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
logLlmDebug(`[LLM:${debugLabel}] prompt text`, rawPromptText);
|
||||
|
||||
@@ -119,6 +132,11 @@ async function requestMessageContent(
|
||||
|
||||
return content.trim();
|
||||
} catch (error) {
|
||||
if (externalSignal?.aborted) {
|
||||
throw externalSignal.reason instanceof Error
|
||||
? externalSignal.reason
|
||||
: new DOMException('The LLM request was aborted.', 'AbortError');
|
||||
}
|
||||
console.error(`[LLM:${debugLabel}] completion failed`, {
|
||||
model: MODEL,
|
||||
elapsedMs: Math.round(performance.now() - startedAt),
|
||||
@@ -128,6 +146,7 @@ async function requestMessageContent(
|
||||
return normalizeLlmError(error);
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
externalSignal?.removeEventListener('abort', handleExternalAbort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user