From fd76c424e859a65688a21145720c70860824a628 Mon Sep 17 00:00:00 2001 From: tetsuya-ki <64536338+tetsuya-ki@users.noreply.github.com> Date: Sun, 5 Jan 2025 17:58:30 +0900 Subject: [PATCH] =?UTF-8?q?aichat=E6=A9=9F=E8=83=BD=E3=81=AB=E3=81=A4?= =?UTF-8?q?=E3=81=84=E3=81=A6=E4=BF=AE=E6=AD=A3(=E3=83=87=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AB=E3=83=88=E3=82=92Gemini=20API=20Flash=202.0?= =?UTF-8?q?=20exp=E3=81=AB=E5=A4=89=E6=9B=B4=E3=81=AA=E3=81=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Gemini APIを基本Flash使用に変更 - Flashのバージョンを2.0 expに変更 - Flash, PRO指定時の不正な文章を修正 --- src/modules/aichat/index.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/modules/aichat/index.ts b/src/modules/aichat/index.ts index 636cfbe..cf62ce5 100644 --- a/src/modules/aichat/index.ts +++ b/src/modules/aichat/index.ts @@ -32,9 +32,12 @@ type AiChatHist = { const KIGO = '&'; const TYPE_GEMINI = 'gemini'; +const GEMINI_PRO = 'gemini-pro'; +const GEMINI_FLASH = 'gemini-flash'; const TYPE_PLAMO = 'plamo'; -const GEMINI_15_FLASH_API = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent'; +const GEMINI_20_FLASH_API = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent'; +// const GEMINI_15_FLASH_API = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent'; const GEMINI_15_PRO_API = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent'; const PLAMO_API = 'https://platform.preferredai.jp/api/completion/v1/chat/completions'; @@ -397,11 +400,20 @@ export default class extends Module { if (config.prompt) { prompt = config.prompt; } - const reName = RegExp(this.name, "i"); - const reKigoType = RegExp(KIGO + exist.type, "i"); + const reName = RegExp(this.name, 'i'); + let reKigoType = RegExp(KIGO + exist.type, 'i'); const extractedText = msg.extractedText; if (extractedText == undefined || extractedText.length == 0) return false; + // Gemini API用にAPIのURLと置き換え用タイプを変更 + if (msg.includes([KIGO + GEMINI_FLASH])) { + exist.api = GEMINI_20_FLASH_API; + reKigoType = RegExp(KIGO + GEMINI_FLASH, 'i'); + } else if (msg.includes([KIGO + GEMINI_PRO])) { + exist.api = GEMINI_15_PRO_API; + reKigoType = RegExp(KIGO + GEMINI_PRO, 'i'); + } + const question = extractedText .replace(reName, '') .replace(reKigoType, '') @@ -417,12 +429,12 @@ export default class extends Module { aiChat = { question: question, prompt: prompt, - api: GEMINI_15_PRO_API, + api: GEMINI_20_FLASH_API, key: config.geminiProApiKey, history: exist.history }; - if (msg.includes([KIGO + 'gemini-flash']) || (exist.api && exist.api === GEMINI_15_FLASH_API)) { - aiChat.api = GEMINI_15_FLASH_API; + if (exist.api) { + aiChat.api = exist.api } text = await this.genTextByGemini(aiChat, base64Image); break;