Merge branch 'staging' into qr-popout-hide
| @@ -2437,7 +2437,7 @@ | |||
| 2437 | <option value="claude">Claude</option> | 2437 | <option value="claude">Claude</option> |
| 2438 | <option value="cohere">Cohere</option> | 2438 | <option value="cohere">Cohere</option> |
| 2439 | <option value="groq">Groq</option> | 2439 | <option value="groq">Groq</option> |
| 2440 | <option value="makersuite">Google MakerSuite</option> | 2440 | <option value="makersuite">Google AI Studio</option> |
| 2441 | <option value="mistralai">MistralAI</option> | 2441 | <option value="mistralai">MistralAI</option> |
| 2442 | <option value="openrouter">OpenRouter</option> | 2442 | <option value="openrouter">OpenRouter</option> |
| 2443 | <option value="perplexity">Perplexity</option> | 2443 | <option value="perplexity">Perplexity</option> |
| @@ -2800,7 +2800,7 @@ | |||
| 2800 | </div> | 2800 | </div> |
| 2801 | </form> | 2801 | </form> |
| 2802 | <form id="makersuite_form" data-source="makersuite" action="javascript:void(null);" method="post" enctype="multipart/form-data"> | 2802 | <form id="makersuite_form" data-source="makersuite" action="javascript:void(null);" method="post" enctype="multipart/form-data"> |
| 2803 | <h4 data-i18n="MakerSuite API Key">MakerSuite API Key</h4> | 2803 | <h4 data-i18n="Google AI Studio API Key">Google AI Studio API Key</h4> |
| 2804 | <div class="flex-container"> | 2804 | <div class="flex-container"> |
| 2805 | <input id="api_key_makersuite" name="api_key_makersuite" class="text_pole flex1" maxlength="500" value="" type="text" autocomplete="off"> | 2805 | <input id="api_key_makersuite" name="api_key_makersuite" class="text_pole flex1" maxlength="500" value="" type="text" autocomplete="off"> |
| 2806 | <div title="Clear your API key" data-i18n="[title]Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_makersuite"></div> | 2806 | <div title="Clear your API key" data-i18n="[title]Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_makersuite"></div> |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "طريقة بديلة", | 390 | "Alt Method": "طريقة بديلة", |
| 391 | "AI21 API Key": "مفتاح API لـ AI21", | 391 | "AI21 API Key": "مفتاح API لـ AI21", |
| 392 | "AI21 Model": "نموذج AI21", | 392 | "AI21 Model": "نموذج AI21", |
| 393 | "MakerSuite API Key": "مفتاح واجهة برمجة تطبيقات MakerSuite", | 393 | "Google AI Studio API Key": "مفتاح واجهة برمجة تطبيقات Google AI Studio", |
| 394 | "Google Model": "نموذج جوجل", | 394 | "Google Model": "نموذج جوجل", |
| 395 | "MistralAI API Key": "مفتاح واجهة برمجة التطبيقات MistralAI", | 395 | "MistralAI API Key": "مفتاح واجهة برمجة التطبيقات MistralAI", |
| 396 | "MistralAI Model": "نموذج ميسترال آي آي", | 396 | "MistralAI Model": "نموذج ميسترال آي آي", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Alternative Methode", | 390 | "Alt Method": "Alternative Methode", |
| 391 | "AI21 API Key": "AI21 API-Schlüssel", | 391 | "AI21 API Key": "AI21 API-Schlüssel", |
| 392 | "AI21 Model": "AI21-Modell", | 392 | "AI21 Model": "AI21-Modell", |
| 393 | "MakerSuite API Key": "MakerSuite API-Schlüssel", | 393 | "Google AI Studio API Key": "Google AI Studio API-Schlüssel", |
| 394 | "Google Model": "Google-Modell", | 394 | "Google Model": "Google-Modell", |
| 395 | "MistralAI API Key": "MistralAI API-Schlüssel", | 395 | "MistralAI API Key": "MistralAI API-Schlüssel", |
| 396 | "MistralAI Model": "MistralAI-Modell", | 396 | "MistralAI Model": "MistralAI-Modell", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Método alternativo", | 390 | "Alt Method": "Método alternativo", |
| 391 | "AI21 API Key": "Clave API de AI21", | 391 | "AI21 API Key": "Clave API de AI21", |
| 392 | "AI21 Model": "Modelo de AI21", | 392 | "AI21 Model": "Modelo de AI21", |
| 393 | "MakerSuite API Key": "Clave API de MakerSuite", | 393 | "Google AI Studio API Key": "Clave API de Google AI Studio", |
| 394 | "Google Model": "Modelo de Google", | 394 | "Google Model": "Modelo de Google", |
| 395 | "MistralAI API Key": "Clave API de MistralAI", | 395 | "MistralAI API Key": "Clave API de MistralAI", |
| 396 | "MistralAI Model": "Modelo MistralAI", | 396 | "MistralAI Model": "Modelo MistralAI", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Méthode alternative", | 390 | "Alt Method": "Méthode alternative", |
| 391 | "AI21 API Key": "Clé API AI21", | 391 | "AI21 API Key": "Clé API AI21", |
| 392 | "AI21 Model": "Modèle AI21", | 392 | "AI21 Model": "Modèle AI21", |
| 393 | "MakerSuite API Key": "Clé API MakerSuite", | 393 | "Google AI Studio API Key": "Clé API Google AI Studio", |
| 394 | "Google Model": "Modèle Google", | 394 | "Google Model": "Modèle Google", |
| 395 | "MistralAI API Key": "Clé API MistralAI", | 395 | "MistralAI API Key": "Clé API MistralAI", |
| 396 | "MistralAI Model": "Modèle MistralAI", | 396 | "MistralAI Model": "Modèle MistralAI", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Aðferð Bakmenn", | 390 | "Alt Method": "Aðferð Bakmenn", |
| 391 | "AI21 API Key": "Lykill API fyrir AI21", | 391 | "AI21 API Key": "Lykill API fyrir AI21", |
| 392 | "AI21 Model": "AI21 Módel", | 392 | "AI21 Model": "AI21 Módel", |
| 393 | "MakerSuite API Key": "MakerSuite API lykill", | 393 | "Google AI Studio API Key": "Google AI Studio API lykill", |
| 394 | "Google Model": "Google líkan", | 394 | "Google Model": "Google líkan", |
| 395 | "MistralAI API Key": "MistralAI API lykill", | 395 | "MistralAI API Key": "MistralAI API lykill", |
| 396 | "MistralAI Model": "MistralAI líkan", | 396 | "MistralAI Model": "MistralAI líkan", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Metodo alternativo", | 390 | "Alt Method": "Metodo alternativo", |
| 391 | "AI21 API Key": "Chiave API di AI21", | 391 | "AI21 API Key": "Chiave API di AI21", |
| 392 | "AI21 Model": "Modello AI21", | 392 | "AI21 Model": "Modello AI21", |
| 393 | "MakerSuite API Key": "Chiave API MakerSuite", | 393 | "Google AI Studio API Key": "Chiave API Google AI Studio", |
| 394 | "Google Model": "Modello Google", | 394 | "Google Model": "Modello Google", |
| 395 | "MistralAI API Key": "Chiave API MistralAI", | 395 | "MistralAI API Key": "Chiave API MistralAI", |
| 396 | "MistralAI Model": "Modello MistralAI", | 396 | "MistralAI Model": "Modello MistralAI", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "代替手法", | 390 | "Alt Method": "代替手法", |
| 391 | "AI21 API Key": "AI21のAPIキー", | 391 | "AI21 API Key": "AI21のAPIキー", |
| 392 | "AI21 Model": "AI21モデル", | 392 | "AI21 Model": "AI21モデル", |
| 393 | "MakerSuite API Key": "MakerSuite APIキー", | 393 | "Google AI Studio API Key": "Google AI Studio APIキー", |
| 394 | "Google Model": "Google モデル", | 394 | "Google Model": "Google モデル", |
| 395 | "MistralAI API Key": "MistralAI API キー", | 395 | "MistralAI API Key": "MistralAI API キー", |
| 396 | "MistralAI Model": "MistralAI モデル", | 396 | "MistralAI Model": "MistralAI モデル", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "대체 방법", | 390 | "Alt Method": "대체 방법", |
| 391 | "AI21 API Key": "AI21 API 키", | 391 | "AI21 API Key": "AI21 API 키", |
| 392 | "AI21 Model": "AI21 모델", | 392 | "AI21 Model": "AI21 모델", |
| 393 | "MakerSuite API Key": "MakerSuite API 키", | 393 | "Google AI Studio API Key": "Google AI Studio API 키", |
| 394 | "Google Model": "구글 모델", | 394 | "Google Model": "구글 모델", |
| 395 | "MistralAI API Key": "MistralAI API 키", | 395 | "MistralAI API Key": "MistralAI API 키", |
| 396 | "MistralAI Model": "MistralAI 모델", | 396 | "MistralAI Model": "MistralAI 모델", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Método Alternativo", | 390 | "Alt Method": "Método Alternativo", |
| 391 | "AI21 API Key": "Chave da API AI21", | 391 | "AI21 API Key": "Chave da API AI21", |
| 392 | "AI21 Model": "Modelo AI21", | 392 | "AI21 Model": "Modelo AI21", |
| 393 | "MakerSuite API Key": "Chave API MakerSuite", | 393 | "Google AI Studio API Key": "Chave API Google AI Studio", |
| 394 | "Google Model": "Modelo Google", | 394 | "Google Model": "Modelo Google", |
| 395 | "MistralAI API Key": "Chave de API MistralAI", | 395 | "MistralAI API Key": "Chave de API MistralAI", |
| 396 | "MistralAI Model": "Modelo MistralAI", | 396 | "MistralAI Model": "Modelo MistralAI", |
| @@ -722,7 +722,7 @@ | |||
| 722 | "Proxy Server URL": "Адрес прокси-сервера", | 722 | "Proxy Server URL": "Адрес прокси-сервера", |
| 723 | "MistralAI Model": "Модель MistralAI", | 723 | "MistralAI Model": "Модель MistralAI", |
| 724 | "MistralAI API Key": "Ключ от API MistralAI", | 724 | "MistralAI API Key": "Ключ от API MistralAI", |
| 725 | "MakerSuite API Key": "Ключ от API MakerSuite", | 725 | "Google AI Studio API Key": "Ключ от API Google AI Studio", |
| 726 | "Google Model": "Модель Google", | 726 | "Google Model": "Модель Google", |
| 727 | "Cohere API Key": "Ключ от API Cohere", | 727 | "Cohere API Key": "Ключ от API Cohere", |
| 728 | "Cohere Model": "Модель Cohere", | 728 | "Cohere Model": "Модель Cohere", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Альтернативний метод", | 390 | "Alt Method": "Альтернативний метод", |
| 391 | "AI21 API Key": "Ключ API для AI21", | 391 | "AI21 API Key": "Ключ API для AI21", |
| 392 | "AI21 Model": "Модель AI21", | 392 | "AI21 Model": "Модель AI21", |
| 393 | "MakerSuite API Key": "Ключ API MakerSuite", | 393 | "Google AI Studio API Key": "Ключ API Google AI Studio", |
| 394 | "Google Model": "Модель Google", | 394 | "Google Model": "Модель Google", |
| 395 | "MistralAI API Key": "Ключ API MistralAI", | 395 | "MistralAI API Key": "Ключ API MistralAI", |
| 396 | "MistralAI Model": "Модель MistralAI", | 396 | "MistralAI Model": "Модель MistralAI", |
| @@ -390,7 +390,7 @@ | |||
| 390 | "Alt Method": "Phương pháp thay thế", | 390 | "Alt Method": "Phương pháp thay thế", |
| 391 | "AI21 API Key": "Khóa API của AI21", | 391 | "AI21 API Key": "Khóa API của AI21", |
| 392 | "AI21 Model": "Mô hình AI21", | 392 | "AI21 Model": "Mô hình AI21", |
| 393 | "MakerSuite API Key": "Khóa API MakerSuite", | 393 | "Google AI Studio API Key": "Khóa API Google AI Studio", |
| 394 | "Google Model": "Mô hình Google", | 394 | "Google Model": "Mô hình Google", |
| 395 | "MistralAI API Key": "Khóa API MistralAI", | 395 | "MistralAI API Key": "Khóa API MistralAI", |
| 396 | "MistralAI Model": "Mô hình MistralAI", | 396 | "MistralAI Model": "Mô hình MistralAI", |
| @@ -406,7 +406,7 @@ | |||
| 406 | "Alt Method": "备用方法", | 406 | "Alt Method": "备用方法", |
| 407 | "AI21 API Key": "AI21 API 密钥", | 407 | "AI21 API Key": "AI21 API 密钥", |
| 408 | "AI21 Model": "AI21 模型", | 408 | "AI21 Model": "AI21 模型", |
| 409 | "MakerSuite API Key": "MakerSuite API 密钥", | 409 | "Google AI Studio API Key": "Google AI Studio API 密钥", |
| 410 | "Google Model": "Google 模型", | 410 | "Google Model": "Google 模型", |
| 411 | "MistralAI API Key": "MistralAI API 密钥", | 411 | "MistralAI API Key": "MistralAI API 密钥", |
| 412 | "MistralAI Model": "MistralAI 模型", | 412 | "MistralAI Model": "MistralAI 模型", |
| @@ -391,7 +391,7 @@ | |||
| 391 | "Alt Method": "替代方法", | 391 | "Alt Method": "替代方法", |
| 392 | "AI21 API Key": "AI21 API 金鑰", | 392 | "AI21 API Key": "AI21 API 金鑰", |
| 393 | "AI21 Model": "AI21 模型", | 393 | "AI21 Model": "AI21 模型", |
| 394 | "MakerSuite API Key": "MakerSuite API 金鑰", | 394 | "Google AI Studio API Key": "Google AI Studio API 金鑰", |
| 395 | "Google Model": "Google 模型", | 395 | "Google Model": "Google 模型", |
| 396 | "MistralAI API Key": "MistralAI API 金鑰", | 396 | "MistralAI API Key": "MistralAI API 金鑰", |
| 397 | "MistralAI Model": "MistralAI 模型", | 397 | "MistralAI Model": "MistralAI 模型", |
| @@ -242,7 +242,7 @@ import { DragAndDropHandler } from './scripts/dragdrop.js'; | |||
| 242 | import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'; | 242 | import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'; |
| 243 | import { initDynamicStyles } from './scripts/dynamic-styles.js'; | 243 | import { initDynamicStyles } from './scripts/dynamic-styles.js'; |
| 244 | import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js'; | 244 | import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js'; |
| 245 | import { enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js'; | 245 | import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 246 | 246 | ||
| 247 | //exporting functions and vars for mods | 247 | //exporting functions and vars for mods |
| 248 | export { | 248 | export { |
| @@ -1879,8 +1879,12 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId) { | |||
| 1879 | } | 1879 | } |
| 1880 | 1880 | ||
| 1881 | if (Number(messageId) === 0 && !isSystem && !isUser) { | 1881 | if (Number(messageId) === 0 && !isSystem && !isUser) { |
| 1882 | const mesBeforeReplace = mes; | ||
| 1883 | const chatMessage = chat[messageId]; | ||
| 1882 | mes = substituteParams(mes, undefined, ch_name); | 1884 | mes = substituteParams(mes, undefined, ch_name); |
| 1883 | chat[messageId] && (chat[messageId].mes = mes); | 1885 | if (chatMessage && chatMessage.mes === mesBeforeReplace && chatMessage.extra?.display_text !== mesBeforeReplace) { |
| 1886 | chatMessage.mes = mes; | ||
| 1887 | } | ||
| 1884 | } | 1888 | } |
| 1885 | 1889 | ||
| 1886 | mesForShowdownParse = mes; | 1890 | mesForShowdownParse = mes; |
| @@ -8380,6 +8384,12 @@ const CONNECT_API_MAP = { | |||
| 8380 | button: '#api_button_openai', | 8384 | button: '#api_button_openai', |
| 8381 | source: chat_completion_sources.OPENAI, | 8385 | source: chat_completion_sources.OPENAI, |
| 8382 | }, | 8386 | }, |
| 8387 | // Google alias | ||
| 8388 | 'google': { | ||
| 8389 | selected: 'openai', | ||
| 8390 | button: '#api_button_openai', | ||
| 8391 | source: chat_completion_sources.MAKERSUITE, | ||
| 8392 | }, | ||
| 8383 | // OpenRouter special naming, to differentiate between chat comp and text comp | 8393 | // OpenRouter special naming, to differentiate between chat comp and text comp |
| 8384 | 'openrouter': { | 8394 | 'openrouter': { |
| 8385 | selected: 'openai', | 8395 | selected: 'openai', |
| @@ -8465,7 +8475,7 @@ async function disableInstructCallback() { | |||
| 8465 | /** | 8475 | /** |
| 8466 | * @param {string} text API name | 8476 | * @param {string} text API name |
| 8467 | */ | 8477 | */ |
| 8468 | async function connectAPISlash(_, text) { | 8478 | async function connectAPISlash(args, text) { |
| 8469 | if (!text.trim()) { | 8479 | if (!text.trim()) { |
| 8470 | for (const [key, config] of Object.entries(CONNECT_API_MAP)) { | 8480 | for (const [key, config] of Object.entries(CONNECT_API_MAP)) { |
| 8471 | if (config.selected !== main_api) continue; | 8481 | if (config.selected !== main_api) continue; |
| @@ -8488,12 +8498,15 @@ async function connectAPISlash(_, text) { | |||
| 8488 | 8498 | ||
| 8489 | return key; | 8499 | return key; |
| 8490 | } | 8500 | } |
| 8501 | |||
| 8502 | console.error('FIXME: The current API is not in the API map'); | ||
| 8503 | return ''; | ||
| 8491 | } | 8504 | } |
| 8492 | 8505 | ||
| 8493 | const apiConfig = CONNECT_API_MAP[text.toLowerCase()]; | 8506 | const apiConfig = CONNECT_API_MAP[text.toLowerCase()]; |
| 8494 | if (!apiConfig) { | 8507 | if (!apiConfig) { |
| 8495 | toastr.error(`Error: ${text} is not a valid API`); | 8508 | toastr.error(`Error: ${text} is not a valid API`); |
| 8496 | return; | 8509 | return ''; |
| 8497 | } | 8510 | } |
| 8498 | 8511 | ||
| 8499 | $(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true); | 8512 | $(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true); |
| @@ -8513,14 +8526,18 @@ async function connectAPISlash(_, text) { | |||
| 8513 | $(apiConfig.button).trigger('click'); | 8526 | $(apiConfig.button).trigger('click'); |
| 8514 | } | 8527 | } |
| 8515 | 8528 | ||
| 8516 | toastr.info(`API set to ${text}, trying to connect..`); | 8529 | const quiet = isTrueBoolean(args?.quiet); |
| 8530 | const toast = quiet ? jQuery() : toastr.info(`API set to ${text}, trying to connect..`); | ||
| 8517 | 8531 | ||
| 8518 | try { | 8532 | try { |
| 8519 | await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100); | 8533 | await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100); |
| 8520 | console.log('Connection successful'); | 8534 | console.log('Connection successful'); |
| 8521 | } catch { | 8535 | } catch { |
| 8522 | console.log('Could not connect after 5 seconds, skipping.'); | 8536 | console.log('Could not connect after 10 seconds, skipping.'); |
| 8523 | } | 8537 | } |
| 8538 | |||
| 8539 | toastr.clear(toast); | ||
| 8540 | return text; | ||
| 8524 | } | 8541 | } |
| 8525 | 8542 | ||
| 8526 | /** | 8543 | /** |
| @@ -8979,6 +8996,15 @@ jQuery(async function () { | |||
| 8979 | name: 'api', | 8996 | name: 'api', |
| 8980 | callback: connectAPISlash, | 8997 | callback: connectAPISlash, |
| 8981 | returns: 'the current API', | 8998 | returns: 'the current API', |
| 8999 | namedArgumentList: [ | ||
| 9000 | SlashCommandNamedArgument.fromProps({ | ||
| 9001 | name: 'quiet', | ||
| 9002 | description: 'Suppress the toast message on connection', | ||
| 9003 | typeList: [ARGUMENT_TYPE.BOOLEAN], | ||
| 9004 | defaultValue: 'false', | ||
| 9005 | enumList: commonEnumProviders.boolean('trueFalse')(), | ||
| 9006 | }), | ||
| 9007 | ], | ||
| 8982 | unnamedArgumentList: [ | 9008 | unnamedArgumentList: [ |
| 8983 | SlashCommandArgument.fromProps({ | 9009 | SlashCommandArgument.fromProps({ |
| 8984 | description: 'API to connect to', | 9010 | description: 'API to connect to', |
| @@ -20,7 +20,7 @@ | |||
| 20 | <option value="zerooneai">01.AI (Yi)</option> | 20 | <option value="zerooneai">01.AI (Yi)</option> |
| 21 | <option value="anthropic">Anthropic</option> | 21 | <option value="anthropic">Anthropic</option> |
| 22 | <option value="custom" data-i18n="Custom (OpenAI-compatible)">Custom (OpenAI-compatible)</option> | 22 | <option value="custom" data-i18n="Custom (OpenAI-compatible)">Custom (OpenAI-compatible)</option> |
| 23 | <option value="google">Google MakerSuite</option> | 23 | <option value="google">Google AI Studio</option> |
| 24 | <option value="koboldcpp">KoboldCpp</option> | 24 | <option value="koboldcpp">KoboldCpp</option> |
| 25 | <option value="llamacpp">llama.cpp</option> | 25 | <option value="llamacpp">llama.cpp</option> |
| 26 | <option value="ollama">Ollama</option> | 26 | <option value="ollama">Ollama</option> |
| @@ -1,4 +1,4 @@ | |||
| 1 | import { getStringHash, debounce, waitUntilCondition, extractAllWords } from '../../utils.js'; | 1 | import { getStringHash, debounce, waitUntilCondition, extractAllWords, isTrueBoolean } from '../../utils.js'; |
| 2 | import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js'; | 2 | import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 3 | import { | 3 | import { |
| 4 | activateSendButtons, | 4 | activateSendButtons, |
| @@ -26,6 +26,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js'; | |||
| 26 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js'; | 26 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js'; |
| 27 | import { MacrosParser } from '../../macros.js'; | 27 | import { MacrosParser } from '../../macros.js'; |
| 28 | import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js'; | 28 | import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js'; |
| 29 | import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; | ||
| 29 | export { MODULE_NAME }; | 30 | export { MODULE_NAME }; |
| 30 | 31 | ||
| 31 | const MODULE_NAME = '1_memory'; | 32 | const MODULE_NAME = '1_memory'; |
| @@ -456,7 +457,12 @@ async function onChatEvent() { | |||
| 456 | } | 457 | } |
| 457 | } | 458 | } |
| 458 | 459 | ||
| 459 | async function forceSummarizeChat() { | 460 | /** |
| 461 | * Forces a summary generation for the current chat. | ||
| 462 | * @param {boolean} quiet If an informational toast should be displayed | ||
| 463 | * @returns {Promise<string>} Summarized text | ||
| 464 | */ | ||
| 465 | async function forceSummarizeChat(quiet) { | ||
| 460 | if (extension_settings.memory.source === summary_sources.extras) { | 466 | if (extension_settings.memory.source === summary_sources.extras) { |
| 461 | toastr.warning('Force summarization is not supported for Extras API'); | 467 | toastr.warning('Force summarization is not supported for Extras API'); |
| 462 | return; | 468 | return; |
| @@ -471,7 +477,7 @@ async function forceSummarizeChat() { | |||
| 471 | return ''; | 477 | return ''; |
| 472 | } | 478 | } |
| 473 | 479 | ||
| 474 | const toast = toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 }); | 480 | const toast = quiet ? jQuery() : toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 }); |
| 475 | const value = extension_settings.memory.source === summary_sources.main | 481 | const value = extension_settings.memory.source === summary_sources.main |
| 476 | ? await summarizeChatMain(context, true, skipWIAN) | 482 | ? await summarizeChatMain(context, true, skipWIAN) |
| 477 | : await summarizeChatWebLLM(context, true); | 483 | : await summarizeChatWebLLM(context, true); |
| @@ -494,9 +500,10 @@ async function forceSummarizeChat() { | |||
| 494 | async function summarizeCallback(args, text) { | 500 | async function summarizeCallback(args, text) { |
| 495 | text = text.trim(); | 501 | text = text.trim(); |
| 496 | 502 | ||
| 497 | // Using forceSummarizeChat to summarize the current chat | 503 | // Summarize the current chat if no text provided |
| 498 | if (!text) { | 504 | if (!text) { |
| 499 | return await forceSummarizeChat(); | 505 | const quiet = isTrueBoolean(args.quiet); |
| 506 | return await forceSummarizeChat(quiet); | ||
| 500 | } | 507 | } |
| 501 | 508 | ||
| 502 | const source = args.source || extension_settings.memory.source; | 509 | const source = args.source || extension_settings.memory.source; |
| @@ -1005,7 +1012,7 @@ function setupListeners() { | |||
| 1005 | $('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput); | 1012 | $('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput); |
| 1006 | $('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput); | 1013 | $('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput); |
| 1007 | $('#memory_prompt').off('click').on('input', onMemoryPromptInput); | 1014 | $('#memory_prompt').off('click').on('input', onMemoryPromptInput); |
| 1008 | $('#memory_force_summarize').off('click').on('click', forceSummarizeChat); | 1015 | $('#memory_force_summarize').off('click').on('click', () => forceSummarizeChat(false)); |
| 1009 | $('#memory_template').off('click').on('input', onMemoryTemplateInput); | 1016 | $('#memory_template').off('click').on('input', onMemoryTemplateInput); |
| 1010 | $('#memory_depth').off('click').on('input', onMemoryDepthInput); | 1017 | $('#memory_depth').off('click').on('input', onMemoryDepthInput); |
| 1011 | $('#memory_role').off('click').on('input', onMemoryRoleInput); | 1018 | $('#memory_role').off('click').on('input', onMemoryRoleInput); |
| @@ -1055,6 +1062,13 @@ jQuery(async function () { | |||
| 1055 | typeList: [ARGUMENT_TYPE.STRING], | 1062 | typeList: [ARGUMENT_TYPE.STRING], |
| 1056 | defaultValue: '', | 1063 | defaultValue: '', |
| 1057 | }), | 1064 | }), |
| 1065 | SlashCommandNamedArgument.fromProps({ | ||
| 1066 | name: 'quiet', | ||
| 1067 | description: 'suppress the toast message when summarizing the chat', | ||
| 1068 | typeList: [ARGUMENT_TYPE.BOOLEAN], | ||
| 1069 | defaultValue: 'false', | ||
| 1070 | enumList: commonEnumProviders.boolean('trueFalse')(), | ||
| 1071 | }), | ||
| 1058 | ], | 1072 | ], |
| 1059 | unnamedArgumentList: [ | 1073 | unnamedArgumentList: [ |
| 1060 | new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''), | 1074 | new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''), |
| @@ -141,7 +141,7 @@ function throwIfInvalidModel(useReverseProxy) { | |||
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | if (extension_settings.caption.multimodal_api === 'google' && !secret_state[SECRET_KEYS.MAKERSUITE] && !useReverseProxy) { | 143 | if (extension_settings.caption.multimodal_api === 'google' && !secret_state[SECRET_KEYS.MAKERSUITE] && !useReverseProxy) { |
| 144 | throw new Error('MakerSuite API key is not set.'); | 144 | throw new Error('Google AI Studio API key is not set.'); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | if (extension_settings.caption.multimodal_api === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]) { | 147 | if (extension_settings.caption.multimodal_api === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]) { |
| @@ -12,7 +12,7 @@ | |||
| 12 | <select id="vectors_source" class="text_pole"> | 12 | <select id="vectors_source" class="text_pole"> |
| 13 | <option value="cohere">Cohere</option> | 13 | <option value="cohere">Cohere</option> |
| 14 | <option value="extras">Extras</option> | 14 | <option value="extras">Extras</option> |
| 15 | <option value="palm">Google MakerSuite</option> | 15 | <option value="palm">Google AI Studio</option> |
| 16 | <option value="llamacpp">llama.cpp</option> | 16 | <option value="llamacpp">llama.cpp</option> |
| 17 | <option value="transformers" data-i18n="Local (Transformers)">Local (Transformers)</option> | 17 | <option value="transformers" data-i18n="Local (Transformers)">Local (Transformers)</option> |
| 18 | <option value="mistral">MistralAI</option> | 18 | <option value="mistral">MistralAI</option> |
| @@ -4473,7 +4473,7 @@ async function onConnectButtonClick(e) { | |||
| 4473 | } | 4473 | } |
| 4474 | 4474 | ||
| 4475 | if (!secret_state[SECRET_KEYS.MAKERSUITE] && !oai_settings.reverse_proxy) { | 4475 | if (!secret_state[SECRET_KEYS.MAKERSUITE] && !oai_settings.reverse_proxy) { |
| 4476 | console.log('No secret key saved for MakerSuite'); | 4476 | console.log('No secret key saved for Google AI Studio'); |
| 4477 | return; | 4477 | return; |
| 4478 | } | 4478 | } |
| 4479 | } | 4479 | } |
| @@ -259,7 +259,7 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 259 | const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MAKERSUITE); | 259 | const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MAKERSUITE); |
| 260 | 260 | ||
| 261 | if (!request.body.reverse_proxy && !apiKey) { | 261 | if (!request.body.reverse_proxy && !apiKey) { |
| 262 | console.log('MakerSuite API key is missing.'); | 262 | console.log('Google AI Studio API key is missing.'); |
| 263 | return response.status(400).send({ error: true }); | 263 | return response.status(400).send({ error: true }); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| @@ -326,7 +326,7 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | const body = isGemini ? getGeminiBody() : getBisonBody(); | 328 | const body = isGemini ? getGeminiBody() : getBisonBody(); |
| 329 | console.log('MakerSuite request:', body); | 329 | console.log('Google AI Studio request:', body); |
| 330 | 330 | ||
| 331 | try { | 331 | try { |
| 332 | const controller = new AbortController(); | 332 | const controller = new AbortController(); |
| @@ -362,7 +362,7 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 362 | } | 362 | } |
| 363 | } else { | 363 | } else { |
| 364 | if (!generateResponse.ok) { | 364 | if (!generateResponse.ok) { |
| 365 | console.log(`MakerSuite API returned error: ${generateResponse.status} ${generateResponse.statusText} ${await generateResponse.text()}`); | 365 | console.log(`Google AI Studio API returned error: ${generateResponse.status} ${generateResponse.statusText} ${await generateResponse.text()}`); |
| 366 | return response.status(generateResponse.status).send({ error: true }); | 366 | return response.status(generateResponse.status).send({ error: true }); |
| 367 | } | 367 | } |
| 368 | 368 | ||
| @@ -370,7 +370,7 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 370 | 370 | ||
| 371 | const candidates = generateResponseJson?.candidates; | 371 | const candidates = generateResponseJson?.candidates; |
| 372 | if (!candidates || candidates.length === 0) { | 372 | if (!candidates || candidates.length === 0) { |
| 373 | let message = 'MakerSuite API returned no candidate'; | 373 | let message = 'Google AI Studio API returned no candidate'; |
| 374 | console.log(message, generateResponseJson); | 374 | console.log(message, generateResponseJson); |
| 375 | if (generateResponseJson?.promptFeedback?.blockReason) { | 375 | if (generateResponseJson?.promptFeedback?.blockReason) { |
| 376 | message += `\nPrompt was blocked due to : ${generateResponseJson.promptFeedback.blockReason}`; | 376 | message += `\nPrompt was blocked due to : ${generateResponseJson.promptFeedback.blockReason}`; |
| @@ -381,19 +381,19 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 381 | const responseContent = candidates[0].content ?? candidates[0].output; | 381 | const responseContent = candidates[0].content ?? candidates[0].output; |
| 382 | const responseText = typeof responseContent === 'string' ? responseContent : responseContent?.parts?.[0]?.text; | 382 | const responseText = typeof responseContent === 'string' ? responseContent : responseContent?.parts?.[0]?.text; |
| 383 | if (!responseText) { | 383 | if (!responseText) { |
| 384 | let message = 'MakerSuite Candidate text empty'; | 384 | let message = 'Google AI Studio Candidate text empty'; |
| 385 | console.log(message, generateResponseJson); | 385 | console.log(message, generateResponseJson); |
| 386 | return response.send({ error: { message } }); | 386 | return response.send({ error: { message } }); |
| 387 | } | 387 | } |
| 388 | 388 | ||
| 389 | console.log('MakerSuite response:', responseText); | 389 | console.log('Google AI Studio response:', responseText); |
| 390 | 390 | ||
| 391 | // Wrap it back to OAI format | 391 | // Wrap it back to OAI format |
| 392 | const reply = { choices: [{ 'message': { 'content': responseText } }] }; | 392 | const reply = { choices: [{ 'message': { 'content': responseText } }] }; |
| 393 | return response.send(reply); | 393 | return response.send(reply); |
| 394 | } | 394 | } |
| 395 | } catch (error) { | 395 | } catch (error) { |
| 396 | console.log('Error communicating with MakerSuite API: ', error); | 396 | console.log('Error communicating with Google AI Studio API: ', error); |
| 397 | if (!response.headersSent) { | 397 | if (!response.headersSent) { |
| 398 | return response.status(500).send({ error: true }); | 398 | return response.status(500).send({ error: true }); |
| 399 | } | 399 | } |
| @@ -44,7 +44,7 @@ router.post('/caption-image', jsonParser, async (request, response) => { | |||
| 44 | 44 | ||
| 45 | if (!result.ok) { | 45 | if (!result.ok) { |
| 46 | const error = await result.json(); | 46 | const error = await result.json(); |
| 47 | console.log(`MakerSuite API returned error: ${result.status} ${result.statusText}`, error); | 47 | console.log(`Google AI Studio API returned error: ${result.status} ${result.statusText}`, error); |
| 48 | return response.status(result.status).send({ error: true }); | 48 | return response.status(result.status).send({ error: true }); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| @@ -23,8 +23,8 @@ async function getMakerSuiteVector(text, directories) { | |||
| 23 | const key = readSecret(directories, SECRET_KEYS.MAKERSUITE); | 23 | const key = readSecret(directories, SECRET_KEYS.MAKERSUITE); |
| 24 | 24 | ||
| 25 | if (!key) { | 25 | if (!key) { |
| 26 | console.log('No MakerSuite key found'); | 26 | console.log('No Google AI Studio key found'); |
| 27 | throw new Error('No MakerSuite key found'); | 27 | throw new Error('No Google AI Studio key found'); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/embedding-gecko-001:embedText?key=${key}`, { | 30 | const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/embedding-gecko-001:embedText?key=${key}`, { |
| @@ -39,8 +39,8 @@ async function getMakerSuiteVector(text, directories) { | |||
| 39 | 39 | ||
| 40 | if (!response.ok) { | 40 | if (!response.ok) { |
| 41 | const text = await response.text(); | 41 | const text = await response.text(); |
| 42 | console.log('MakerSuite request failed', response.statusText, text); | 42 | console.log('Google AI Studio request failed', response.statusText, text); |
| 43 | throw new Error('MakerSuite request failed'); | 43 | throw new Error('Google AI Studio request failed'); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | const data = await response.json(); | 46 | const data = await response.json(); |