From 26b856114489018e326ed1b27b1d8219337ba443 Mon Sep 17 00:00:00 2001 From: foxhui Date: Fri, 24 Apr 2026 01:12:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EGemini=20=E5=92=8C=20?= =?UTF-8?q?GPT=20=E7=9A=84=E4=B8=B4=E6=97=B6=E5=AF=B9=E8=AF=9D=E5=BC=80?= =?UTF-8?q?=E5=85=B3=20(closes=20#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ src/backend/adapter/chatgpt_text.js | 20 +++++++++++++++++--- src/backend/adapter/gemini.js | 26 ++++++++++++++++++++------ src/backend/adapter/gemini_text.js | 26 ++++++++++++++++++++------ 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e6709a..a76caa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 修复 ChatGPT 缺少系统提示词的问题 - 尝试修复 ChatGPT 选择模型的问题 (目前应该是灰度测试,有些账号界面不一样,并且作者没有会员账号仅为猜测修复) +### ✨ Added +- **WebUI** + - Gemini 和 ChatGPT 的临时对话模式开关(现可以在适配器设置中单独开关) + ## [3.6.6] - 2026-04-12 ### 🐛 Fixed diff --git a/src/backend/adapter/chatgpt_text.js b/src/backend/adapter/chatgpt_text.js index db64389..720f3ad 100644 --- a/src/backend/adapter/chatgpt_text.js +++ b/src/backend/adapter/chatgpt_text.js @@ -16,7 +16,7 @@ import { import { logger } from '../../utils/logger.js'; // --- 配置常量 --- -const TARGET_URL = 'https://chatgpt.com/?temporary-chat=true'; // 感谢 @zhongjianhua163 提供方案 +const TARGET_URL = 'https://chatgpt.com/'; // 基础URL const INPUT_SELECTOR = '.ProseMirror'; /** @@ -85,8 +85,10 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { const sendBtnLocator = page.getByRole('button', { name: 'Send prompt' }); try { + const useTemp = config?.backend?.adapter?.chatgpt_text?.temporaryChat || false; + const targetUrl = useTemp ? 'https://chatgpt.com/?temporary-chat=true' : 'https://chatgpt.com/'; // 感谢 @zhongjianhua163 提供临时对话方案 logger.info('适配器', '开启新会话...', meta); - await gotoWithCheck(page, TARGET_URL); + await gotoWithCheck(page, targetUrl); // 1. 等待输入框加载 await waitForInput(page, INPUT_SELECTOR, { click: false }); @@ -258,9 +260,21 @@ export const manifest = { displayName: 'ChatGPT (文本生成)', description: '使用 ChatGPT 官网生成文本,支持多模型切换和图片上传。需要已登录的 ChatGPT 账户,若需要选择模型,请使用会员账号 (包含 K12 教室认证账号)。', + // 配置项模式 + configSchema: [ + { + key: 'temporaryChat', + label: '临时对话', + type: 'boolean', + default: false, + note: '开启后将使用临时对话模式 (?temporary-chat=true)' + } + ], + // 入口 URL getTargetUrl(config, workerConfig) { - return TARGET_URL; + const useTemp = config?.backend?.adapter?.chatgpt_text?.temporaryChat || false; + return useTemp ? 'https://chatgpt.com/?temporary-chat=true' : 'https://chatgpt.com/'; }, // 模型列表 diff --git a/src/backend/adapter/gemini.js b/src/backend/adapter/gemini.js index aad8f10..3f71e04 100644 --- a/src/backend/adapter/gemini.js +++ b/src/backend/adapter/gemini.js @@ -41,12 +41,15 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { logger.info('适配器', '开启新会话...', meta); await gotoWithCheck(page, TARGET_URL); - try { - logger.debug('适配器', '尝试点击 Temporary chat...', meta); - const tempChatBtn = page.getByRole('button', { name: 'Temporary chat' }); - await safeClick(page, tempChatBtn, { bias: 'button', timeout: 3000 }); - } catch (e) { - logger.debug('适配器', '未找到 Temporary chat 按钮或点击失败,忽略', meta); + const useTempChat = config?.backend?.adapter?.gemini?.temporaryChat || false; + if (useTempChat) { + try { + logger.debug('适配器', '尝试点击 Temporary chat...', meta); + const tempChatBtn = page.getByRole('button', { name: 'Temporary chat' }); + await safeClick(page, tempChatBtn, { bias: 'button', timeout: 3000 }); + } catch (e) { + logger.debug('适配器', '未找到 Temporary chat 按钮或点击失败,忽略', meta); + } } // 1. 等待输入框加载 @@ -226,6 +229,17 @@ export const manifest = { displayName: 'Google Gemini (图片、视频生成)', description: '使用 Google Gemini 官网生成图片和视频,支持参考图片上传。需要已登录的 Google 账户,免费账户图片生成有速率限制,视频生成必须为会员账户才可使用。', + // 配置项模式 + configSchema: [ + { + key: 'temporaryChat', + label: '临时对话', + type: 'boolean', + default: false, + note: '开启后将使用临时对话模式' + } + ], + // 入口 URL getTargetUrl(config, workerConfig) { return TARGET_URL; diff --git a/src/backend/adapter/gemini_text.js b/src/backend/adapter/gemini_text.js index 6c26dd3..698788c 100644 --- a/src/backend/adapter/gemini_text.js +++ b/src/backend/adapter/gemini_text.js @@ -39,12 +39,15 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { logger.info('适配器', '开启新会话...', meta); await gotoWithCheck(page, TARGET_URL); - try { - logger.debug('适配器', '尝试点击 Temporary chat...', meta); - const tempChatBtn = page.getByRole('button', { name: 'Temporary chat' }); - await safeClick(page, tempChatBtn, { bias: 'button', timeout: 3000 }); - } catch (e) { - logger.debug('适配器', '未找到 Temporary chat 按钮或点击失败,忽略', meta); + const useTempChat = config?.backend?.adapter?.gemini_text?.temporaryChat || false; + if (useTempChat) { + try { + logger.debug('适配器', '尝试点击 Temporary chat...', meta); + const tempChatBtn = page.getByRole('button', { name: 'Temporary chat' }); + await safeClick(page, tempChatBtn, { bias: 'button', timeout: 3000 }); + } catch (e) { + logger.debug('适配器', '未找到 Temporary chat 按钮或点击失败,忽略', meta); + } } // 1. 等待输入框加载 @@ -206,6 +209,17 @@ export const manifest = { displayName: 'Google Gemini (文本生成)', description: '使用 Google Gemini 官网生成文本,支持多模型切换和图片上传。需要已登录的 Google 账户。', + // 配置项模式 + configSchema: [ + { + key: 'temporaryChat', + label: '临时对话', + type: 'boolean', + default: false, + note: '开启后将使用临时对话模式' + } + ], + getTargetUrl(config, workerConfig) { return TARGET_URL; },