diff --git a/CHANGELOG.md b/CHANGELOG.md index d24b8b9..1853951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.1] - 2024-11-24 + +### Fixed +- **指定模型** + - 修复因错误的UUID映射导致的 gemini-3-pro-image-preview 模型触发HTTP500的 BUG + ## [1.1.0] - 2024-11-24 diff --git a/lib/lmarena.js b/lib/lmarena.js index e65e28b..ca87ef8 100644 --- a/lib/lmarena.js +++ b/lib/lmarena.js @@ -405,6 +405,7 @@ async function initBrowser(config) { async function generateImage(context, prompt, imgPaths, modelId) { const { page, client, width, height } = context; const textareaSelector = 'textarea'; + let requestHandler = null; try { // 1. 强制开启新会话 (通过URL跳转) @@ -427,33 +428,34 @@ async function generateImage(context, prompt, imgPaths, modelId) { await humanType(page, textareaSelector, prompt); await sleep(800, 1500); - // --- 注入 Fetch 拦截器 --- + // --- 注入 Fetch 拦截器 (Puppeteer Request Interception) --- if (modelId) { - await page.evaluate((targetModelId) => { - const originalFetch = window.fetch; - window.fetch = async (...args) => { - let [resource, config] = args; - // 简单判断 URL - const url = resource instanceof Request ? resource.url : resource.toString(); - - if (url.includes('/nextjs-api/stream/') && config && config.method === 'POST' && config.body) { - try { - const data = JSON.parse(config.body); + await page.setRequestInterception(true); + requestHandler = async (request) => { + const url = request.url(); + if (url.includes('/nextjs-api/stream/') && request.method() === 'POST') { + try { + const postData = request.postData(); + if (postData) { + const data = JSON.parse(postData); console.log(`[Browser] 正在拦截请求。原始 modelAId: ${data.modelAId}`); // 修改 modelAId - data.modelAId = targetModelId; - config.body = JSON.stringify(data); + data.modelAId = modelId; + const newPostData = JSON.stringify(data); console.log(`[Browser] 请求已修改。新 modelAId: ${data.modelAId}`); - } catch (e) { - console.error('[Browser] 拦截失败:', e); + await request.continue({ postData: newPostData }); + return; } + } catch (e) { + console.error('[Browser] 拦截修改失败:', e); } - return originalFetch.apply(window, args); - }; - }, modelId); - console.log(`>>> [Test] 已注入 Fetch 拦截器,目标模型: ${modelId}`); + } + await request.continue(); + }; + page.on('request', requestHandler); + console.log(`>>> [Test] 已启用请求拦截,目标模型: ${modelId}`); } // 4. 发送 @@ -520,6 +522,13 @@ async function generateImage(context, prompt, imgPaths, modelId) { } catch (err) { console.error('>>> [Error] 生成任务失败:', err.message); return { error: err.message }; + } finally { + if (requestHandler) { + page.off('request', requestHandler); + try { + await page.setRequestInterception(false); + } catch (e) { } + } } } diff --git a/lib/models.js b/lib/models.js index 03832c9..f019215 100644 --- a/lib/models.js +++ b/lib/models.js @@ -1,5 +1,5 @@ export const MODEL_MAPPING = { - "gemini-3-pro-image-preview": "019aa208-5c19-7162-ae3b-0a9ddbble16a", + "gemini-3-pro-image-preview": "019aa208-5c19-7162-ae3b-0a9ddbb1e16a", "seedream-4-high-res-fal": "32974d8d-333c-4d2e-abf3-f258c0ac1310", "hunyuan-image-3.0": "7766a45c-1b6b-4fb8-9823-2557291e1ddd", "gemini-2.5-flash-image-preview": "0199ef2a-583f-7088-b704-b75fd169401d",