mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
fix: 修复错误信息、reasoning_content 透传及豆包模型菜单问题
- 修正 Playwright TimeoutError 提示为页面操作超时(非网络问题) - 新增 CLICK_TIMEOUT 错误归一化处理,标记为 retryable - buildChatCompletion/buildChatCompletionChunk 支持 reasoningContent 参数 - doubao_text 模型选择菜单增加重试逻辑(最多 3 次),waitFor 超时从 2s 改为 5s
This commit is contained in:
@@ -60,18 +60,26 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
|
|||||||
.first();
|
.first();
|
||||||
let selectorExists = false;
|
let selectorExists = false;
|
||||||
try {
|
try {
|
||||||
await modelSelectorBtn.waitFor({ state: 'attached', timeout: 1000 });
|
await modelSelectorBtn.waitFor({ state: 'attached', timeout: 5000 });
|
||||||
selectorExists = true;
|
selectorExists = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
selectorExists = false;
|
selectorExists = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectorExists) {
|
if (selectorExists) {
|
||||||
await safeClick(page, modelSelectorBtn, { bias: 'button' });
|
|
||||||
await sleep(300, 500);
|
|
||||||
|
|
||||||
const menuItem = page.getByRole('menuitem', { name: modelMenuName });
|
const menuItem = page.getByRole('menuitem', { name: modelMenuName });
|
||||||
await menuItem.waitFor({ state: 'visible', timeout: 5000 });
|
// 点击模型选择按钮,最多重试 3 次(菜单偶尔不弹出)
|
||||||
|
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||||
|
await sleep(500, 1000);
|
||||||
|
await safeClick(page, modelSelectorBtn, { bias: 'button' });
|
||||||
|
try {
|
||||||
|
await menuItem.waitFor({ state: 'visible', timeout: 3000 });
|
||||||
|
break; // 菜单弹出,退出重试
|
||||||
|
} catch {
|
||||||
|
logger.warn('适配器', `模型菜单未弹出,重试 ${attempt}/3`, meta);
|
||||||
|
if (attempt === 3) throw new Error('模型选择菜单未弹出');
|
||||||
|
}
|
||||||
|
}
|
||||||
await safeClick(page, menuItem, { bias: 'button' });
|
await safeClick(page, menuItem, { bias: 'button' });
|
||||||
await sleep(200, 400);
|
await sleep(200, 400);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,10 +68,15 @@ export function normalizePageError(err, meta = {}) {
|
|||||||
logger.error('适配器', err.message, meta);
|
logger.error('适配器', err.message, meta);
|
||||||
return { error: err.message, code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
|
return { error: err.message, code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
|
||||||
}
|
}
|
||||||
// 兼容原生 TimeoutError (其他地方抛出的)
|
// CLICK_TIMEOUT: safeClick 内部超时
|
||||||
|
if (err.message?.includes('CLICK_TIMEOUT')) {
|
||||||
|
logger.error('适配器', `点击操作超时: ${err.message}`, meta);
|
||||||
|
return { error: err.message, code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
|
||||||
|
}
|
||||||
|
// 兼容原生 TimeoutError (Playwright 元素操作超时等)
|
||||||
if (err.name === 'TimeoutError' || err.message?.includes('Timeout')) {
|
if (err.name === 'TimeoutError' || err.message?.includes('Timeout')) {
|
||||||
logger.error('适配器', '请求超时', meta);
|
logger.error('适配器', `页面操作超时: ${err.message}`, meta);
|
||||||
return { error: '请求超时, 请检查网络或稍后重试', code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
|
return { error: '页面操作超时, 页面可能未正常加载或元素未找到', code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
|
||||||
}
|
}
|
||||||
// PAGE_ERROR_DETECTED: waitApiResponse 页面 UI 中检测到的错误关键词
|
// PAGE_ERROR_DETECTED: waitApiResponse 页面 UI 中检测到的错误关键词
|
||||||
if (err.message?.startsWith('PAGE_ERROR_DETECTED:')) {
|
if (err.message?.startsWith('PAGE_ERROR_DETECTED:')) {
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ export function buildChatCompletion(content, modelName, reasoningContent) {
|
|||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: content
|
content: content
|
||||||
};
|
};
|
||||||
|
|
||||||
if (reasoningContent) {
|
if (reasoningContent) {
|
||||||
message.reasoning_content = reasoningContent;
|
message.reasoning_content = reasoningContent;
|
||||||
}
|
}
|
||||||
@@ -142,7 +141,6 @@ export function buildChatCompletion(content, modelName, reasoningContent) {
|
|||||||
*/
|
*/
|
||||||
export function buildChatCompletionChunk(content, modelName, finishReason = 'stop', reasoningContent) {
|
export function buildChatCompletionChunk(content, modelName, finishReason = 'stop', reasoningContent) {
|
||||||
const delta = { content };
|
const delta = { content };
|
||||||
|
|
||||||
if (reasoningContent) {
|
if (reasoningContent) {
|
||||||
delta.reasoning_content = reasoningContent;
|
delta.reasoning_content = reasoningContent;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user