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