Merge branch 'staging' into tool-calling

576352817edb7282a3ec31affe134ca90a3e5a82

Cohee <18619528+Cohee1207@users.noreply.github.com>

9 files changed, +76 -16Ignore whitespace
public/index.html+25 -10
@@ -2954,16 +2954,31 @@
29542954 </div>
29552955 <h4 data-i18n="Groq Model">Groq Model</h4>
29562956 <select id="model_groq_select">
2957- <option value="llama-3.1-405b-reasoning">llama-3.1-405b-reasoning</option>
2957+ <optgroup label="Llama 3.2">
29582958 <option value="llama-3.12-70b1b-versatilepreview">llama-3.12-70b1b-versatilepreview</option>
29592959 <option value="llama-3.12-8b3b-instantpreview">llama-3.12-8b3b-instantpreview</option>
29602960 <option value="llama3-groq-70bllama-81923.2-tool11b-usevision-preview">llama3-groq-70bllama-81923.2-tool11b-usevision-preview</option>
29612961 <option value="llama3-groq-8bllama-81923.2-tool90b-usevision-preview">llama3-groq-8bllama-81923.2-tool90b-usevision-preview</option>
2962- <option value="llama3-8b-8192">llama3-8b-8192</option>
2962+ </optgroup>
2963- <option value="llama3-70b-8192">llama3-70b-8192</option>
2963+ <optgroup label="Llama 3.1">
29642964 <option value="mixtralllama-8x7b3.1-327688b-instant">mixtralllama-8x7b3.1-327688b-instant</option>
29652965 <option value="gemmallama-7b3.1-it70b-versatile">gemmallama-7b3.1-it70b-versatile</option>
29662966 <option value="gemma2llama-9b3.1-it405b-reasoning">gemma2llama-9b3.1-it405b-reasoning</option>
2967+ </optgroup>
2968+ <optgroup label="Llama 3">
2969+ <option value="llama3-groq-8b-8192-tool-use-preview">llama3-groq-8b-8192-tool-use-preview</option>
2970+ <option value="llama3-groq-70b-8192-tool-use-preview">llama3-groq-70b-8192-tool-use-preview</option>
2971+ <option value="llama3-8b-8192">llama3-8b-8192</option>
2972+ <option value="llama3-70b-8192">llama3-70b-8192</option>
2973+ </optgroup>
2974+ <optgroup label="Gemma">
2975+ <option value="gemma-7b-it">gemma-7b-it</option>
2976+ <option value="gemma2-9b-it">gemma2-9b-it</option>
2977+ </optgroup>
2978+ <optgroup label="Other">
2979+ <option value="mixtral-8x7b-32768">mixtral-8x7b-32768</option>
2980+ <option value="llava-v1.5-7b-4096-preview">llava-v1.5-7b-4096-preview</option>
2981+ </optgroup>
29672982 </select>
29682983 </div>
29692984 <div id="perplexity_form" data-source="perplexity">
public/scripts/extensions/attachments/index.js+21 -0
@@ -1,3 +1,4 @@
1+import { event_types, eventSource, saveSettingsDebounced } from '../../../script.js';
12import { deleteAttachment, getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment, uploadFileAttachmentToServer } from '../../chats.js';
23import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js';
34import { SlashCommand } from '../../slash-commands/SlashCommand.js';
@@ -196,7 +197,27 @@ async function enableDataBankAttachment(args, value) {
196197 return '';
197198}
198199
200+function cleanUpAttachments() {
201+ let shouldSaveSettings = false;
202+ if (extension_settings.character_attachments) {
203+ Object.values(extension_settings.character_attachments).flat().filter(a => a.text).forEach(a => {
204+ shouldSaveSettings = true;
205+ delete a.text;
206+ });
207+ }
208+ if (Array.isArray(extension_settings.attachments)) {
209+ extension_settings.attachments.filter(a => a.text).forEach(a => {
210+ shouldSaveSettings = true;
211+ delete a.text;
212+ });
213+ }
214+ if (shouldSaveSettings) {
215+ saveSettingsDebounced();
216+ }
217+}
218+
199219jQuery(async () => {
220+ eventSource.on(event_types.APP_READY, cleanUpAttachments);
200221 const manageButton = await renderExtensionTemplateAsync('attachments', 'manage-button', {});
201222 const attachButton = await renderExtensionTemplateAsync('attachments', 'attach-button', {});
202223 $('#data_bank_wand_container').append(manageButton);
public/scripts/extensions/caption/index.js+1 -0
@@ -403,6 +403,7 @@ jQuery(async function () {
403403 (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'openai' && (secret_state[SECRET_KEYS.OPENAI] || extension_settings.caption.allow_reverse_proxy)) ||
404404 (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'openrouter' && secret_state[SECRET_KEYS.OPENROUTER]) ||
405405 (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'zerooneai' && secret_state[SECRET_KEYS.ZEROONEAI]) ||
406+ (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'groq' && secret_state[SECRET_KEYS.GROQ]) ||
406407 (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'mistral' && (secret_state[SECRET_KEYS.MISTRALAI] || extension_settings.caption.allow_reverse_proxy)) ||
407408 (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'google' && (secret_state[SECRET_KEYS.MAKERSUITE] || extension_settings.caption.allow_reverse_proxy)) ||
408409 (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'anthropic' && (secret_state[SECRET_KEYS.CLAUDE] || extension_settings.caption.allow_reverse_proxy)) ||
public/scripts/extensions/caption/settings.html+4 -0
@@ -21,6 +21,7 @@
2121 <option value="anthropic">Anthropic</option>
2222 <option value="custom" data-i18n="Custom (OpenAI-compatible)">Custom (OpenAI-compatible)</option>
2323 <option value="google">Google AI Studio</option>
24+ <option value="groq">Groq</option>
2425 <option value="koboldcpp">KoboldCpp</option>
2526 <option value="llamacpp">llama.cpp</option>
2627 <option value="mistral">MistralAI</option>
@@ -60,6 +61,9 @@
6061 <option data-type="google" value="gemini-1.5-pro-exp-0801">gemini-1.5-pro-exp-0801</option>
6162 <option data-type="google" value="gemini-1.5-pro-exp-0827">gemini-1.5-pro-exp-0827</option>
6263 <option data-type="google" value="gemini-pro-vision">gemini-pro-vision</option>
64+ <option data-type="groq" value="llama-3.2-11b-vision-preview">llama-3.2-11b-vision-preview</option>
65+ <option data-type="groq" value="llama-3.2-90b-vision-preview">llama-3.2-90b-vision-preview</option>
66+ <option data-type="groq" value="llava-v1.5-7b-4096-preview">llava-v1.5-7b-4096-preview</option>
6367 <option data-type="openrouter" value="openai/gpt-4-vision-preview">openai/gpt-4-vision-preview</option>
6468 <option data-type="openrouter" value="openai/gpt-4o">openai/gpt-4o</option>
6569 <option data-type="openrouter" value="openai/gpt-4o-2024-05-13">openai/gpt-4o-2024-05-13</option>
public/scripts/extensions/shared.js+5 -1
@@ -36,7 +36,7 @@ export async function getMultimodalCaption(base64Img, prompt) {
3636 const isVllm = extension_settings.caption.multimodal_api === 'vllm';
3737 const base64Bytes = base64Img.length * 0.75;
3838 const compressionLimit = 2 * 1024 * 1024;
3939 if ((['google', 'openrouter', 'mistral', 'groq'].includes(extension_settings.caption.multimodal_api) && base64Bytes > compressionLimit) || isOoba || isKoboldCpp) {
4040 const maxSide = 1024;
4141 base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg');
4242 }
@@ -135,6 +135,10 @@ function throwIfInvalidModel(useReverseProxy) {
135135 throw new Error('01.AI API key is not set.');
136136 }
137137
138+ if (extension_settings.caption.multimodal_api === 'groq' && !secret_state[SECRET_KEYS.GROQ]) {
139+ throw new Error('Groq API key is not set.');
140+ }
141+
138142 if (extension_settings.caption.multimodal_api === 'google' && !secret_state[SECRET_KEYS.MAKERSUITE] && !useReverseProxy) {
139143 throw new Error('Google AI Studio API key is not set.');
140144 }
public/scripts/extensions/vectors/index.js+2 -2
@@ -466,13 +466,13 @@ async function ingestDataBankAttachments(source) {
466466 }
467467
468468 // Download and process the file
469469 file.textconst fileText = await getFileAttachment(file.url);
470470 console.log(`Vectors: Retrieved file ${file.name} from Data Bank`);
471471 // Convert kilobytes to string length
472472 const thresholdLength = settings.size_threshold_db * 1024;
473473 // Use chunk size from settings if file is larger than threshold
474474 const chunkSize = file.size > thresholdLength ? settings.chunk_size_db : -1;
475475 await vectorizeFile(file.textfileText, file.name, collectionId, chunkSize, settings.overlap_percent_db);
476476 }
477477
478478 return dataBankCollectionIds;
public/scripts/openai.js+4 -1
@@ -4118,7 +4118,10 @@ async function onModelChange() {
41184118 if (oai_settings.max_context_unlocked) {
41194119 $('#openai_max_context').attr('max', unlocked_max);
41204120 }
41214121 else if (oai_settings.groq_model.includes('llama-3.12') && oai_settings.groq_model.includes('-preview')) {
4122+ $('#openai_max_context').attr('max', max_8k);
4123+ }
4124+ else if (oai_settings.groq_model.includes('llama-3.2') || oai_settings.groq_model.includes('llama-3.1')) {
41224125 $('#openai_max_context').attr('max', max_128k);
41234126 }
41244127 else if (oai_settings.groq_model.includes('llama3-groq')) {
src/endpoints/backends/chat-completions.js+6 -2
@@ -107,6 +107,7 @@ async function sendClaudeRequest(request, response) {
107107 }
108108
109109 const requestBody = {
110+ /** @type {any} */ system: '',
110111 messages: convertedPrompt.messages,
111112 model: request.body.model,
112113 max_tokens: request.body.max_tokens,
@@ -120,6 +121,8 @@ async function sendClaudeRequest(request, response) {
120121 requestBody.system = enableSystemPromptCache
121122 ? [{ type: 'text', text: convertedPrompt.systemPrompt, cache_control: { type: 'ephemeral' } }]
122123 : convertedPrompt.systemPrompt;
124+ } else {
125+ delete requestBody.system;
123126 }
124127 /*
125128 if (Array.isArray(request.body.tools) && request.body.tools.length > 0) {
@@ -158,12 +161,13 @@ async function sendClaudeRequest(request, response) {
158161 forwardFetchResponse(generateResponse, response);
159162 } else {
160163 if (!generateResponse.ok) {
161- console.log(color.red(`Claude API returned error: ${generateResponse.status} ${generateResponse.statusText}\n${await generateResponse.text()}\n${divider}`));
164+ const generateResponseText = await generateResponse.text();
165+ console.log(color.red(`Claude API returned error: ${generateResponse.status} ${generateResponse.statusText}\n${generateResponseText}\n${divider}`));
162166 return response.status(generateResponse.status).send({ error: true });
163167 }
164168
165169 const generateResponseJson = await generateResponse.json();
166170 const responseText = generateResponseJson?.content?.[0]?.text || '';
167171 console.log('Claude response:', generateResponseJson);
168172
169173 // Wrap it back to OAI format + save the original content
src/endpoints/openai.js+8 -0
@@ -55,6 +55,10 @@ router.post('/caption-image', jsonParser, async (request, response) => {
5555 key = readSecret(request.user.directories, SECRET_KEYS.MISTRALAI);
5656 }
5757
58+ if (request.body.api === 'groq') {
59+ key = readSecret(request.user.directories, SECRET_KEYS.GROQ);
60+ }
61+
5862 if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp', 'vllm'].includes(request.body.api) === false) {
5963 console.log('No key found for API', request.body.api);
6064 return response.sendStatus(400);
@@ -111,6 +115,10 @@ router.post('/caption-image', jsonParser, async (request, response) => {
111115 apiUrl = 'https://api.01.ai/v1/chat/completions';
112116 }
113117
118+ if (request.body.api === 'groq') {
119+ apiUrl = 'https://api.groq.com/openai/v1/chat/completions';
120+ }
121+
114122 if (request.body.api === 'mistral') {
115123 apiUrl = 'https://api.mistral.ai/v1/chat/completions';
116124 }