Merge branch 'staging' into tool-calling

This commit is contained in:
Cohee 2024-10-03 22:36:02 +03:00
commit 576352817e
9 changed files with 76 additions and 16 deletions

View File

@ -2954,16 +2954,31 @@
</div> </div>
<h4 data-i18n="Groq Model">Groq Model</h4> <h4 data-i18n="Groq Model">Groq Model</h4>
<select id="model_groq_select"> <select id="model_groq_select">
<option value="llama-3.1-405b-reasoning">llama-3.1-405b-reasoning</option> <optgroup label="Llama 3.2">
<option value="llama-3.1-70b-versatile">llama-3.1-70b-versatile</option> <option value="llama-3.2-1b-preview">llama-3.2-1b-preview</option>
<option value="llama-3.1-8b-instant">llama-3.1-8b-instant</option> <option value="llama-3.2-3b-preview">llama-3.2-3b-preview</option>
<option value="llama3-groq-70b-8192-tool-use-preview">llama3-groq-70b-8192-tool-use-preview</option> <option value="llama-3.2-11b-vision-preview">llama-3.2-11b-vision-preview</option>
<option value="llama3-groq-8b-8192-tool-use-preview">llama3-groq-8b-8192-tool-use-preview</option> <option value="llama-3.2-90b-vision-preview">llama-3.2-90b-vision-preview</option>
<option value="llama3-8b-8192">llama3-8b-8192</option> </optgroup>
<option value="llama3-70b-8192">llama3-70b-8192</option> <optgroup label="Llama 3.1">
<option value="mixtral-8x7b-32768">mixtral-8x7b-32768</option> <option value="llama-3.1-8b-instant">llama-3.1-8b-instant</option>
<option value="gemma-7b-it">gemma-7b-it</option> <option value="llama-3.1-70b-versatile">llama-3.1-70b-versatile</option>
<option value="gemma2-9b-it">gemma2-9b-it</option> <option value="llama-3.1-405b-reasoning">llama-3.1-405b-reasoning</option>
</optgroup>
<optgroup label="Llama 3">
<option value="llama3-groq-8b-8192-tool-use-preview">llama3-groq-8b-8192-tool-use-preview</option>
<option value="llama3-groq-70b-8192-tool-use-preview">llama3-groq-70b-8192-tool-use-preview</option>
<option value="llama3-8b-8192">llama3-8b-8192</option>
<option value="llama3-70b-8192">llama3-70b-8192</option>
</optgroup>
<optgroup label="Gemma">
<option value="gemma-7b-it">gemma-7b-it</option>
<option value="gemma2-9b-it">gemma2-9b-it</option>
</optgroup>
<optgroup label="Other">
<option value="mixtral-8x7b-32768">mixtral-8x7b-32768</option>
<option value="llava-v1.5-7b-4096-preview">llava-v1.5-7b-4096-preview</option>
</optgroup>
</select> </select>
</div> </div>
<div id="perplexity_form" data-source="perplexity"> <div id="perplexity_form" data-source="perplexity">

View File

@ -1,3 +1,4 @@
import { event_types, eventSource, saveSettingsDebounced } from '../../../script.js';
import { deleteAttachment, getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment, uploadFileAttachmentToServer } from '../../chats.js'; import { deleteAttachment, getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment, uploadFileAttachmentToServer } from '../../chats.js';
import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js'; import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js';
import { SlashCommand } from '../../slash-commands/SlashCommand.js'; import { SlashCommand } from '../../slash-commands/SlashCommand.js';
@ -196,7 +197,27 @@ async function enableDataBankAttachment(args, value) {
return ''; return '';
} }
function cleanUpAttachments() {
let shouldSaveSettings = false;
if (extension_settings.character_attachments) {
Object.values(extension_settings.character_attachments).flat().filter(a => a.text).forEach(a => {
shouldSaveSettings = true;
delete a.text;
});
}
if (Array.isArray(extension_settings.attachments)) {
extension_settings.attachments.filter(a => a.text).forEach(a => {
shouldSaveSettings = true;
delete a.text;
});
}
if (shouldSaveSettings) {
saveSettingsDebounced();
}
}
jQuery(async () => { jQuery(async () => {
eventSource.on(event_types.APP_READY, cleanUpAttachments);
const manageButton = await renderExtensionTemplateAsync('attachments', 'manage-button', {}); const manageButton = await renderExtensionTemplateAsync('attachments', 'manage-button', {});
const attachButton = await renderExtensionTemplateAsync('attachments', 'attach-button', {}); const attachButton = await renderExtensionTemplateAsync('attachments', 'attach-button', {});
$('#data_bank_wand_container').append(manageButton); $('#data_bank_wand_container').append(manageButton);

View File

@ -403,6 +403,7 @@ jQuery(async function () {
(extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'openai' && (secret_state[SECRET_KEYS.OPENAI] || extension_settings.caption.allow_reverse_proxy)) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'openai' && (secret_state[SECRET_KEYS.OPENAI] || extension_settings.caption.allow_reverse_proxy)) ||
(extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'openrouter' && secret_state[SECRET_KEYS.OPENROUTER]) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'openrouter' && secret_state[SECRET_KEYS.OPENROUTER]) ||
(extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'zerooneai' && secret_state[SECRET_KEYS.ZEROONEAI]) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'zerooneai' && secret_state[SECRET_KEYS.ZEROONEAI]) ||
(extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'groq' && secret_state[SECRET_KEYS.GROQ]) ||
(extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'mistral' && (secret_state[SECRET_KEYS.MISTRALAI] || extension_settings.caption.allow_reverse_proxy)) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'mistral' && (secret_state[SECRET_KEYS.MISTRALAI] || extension_settings.caption.allow_reverse_proxy)) ||
(extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'google' && (secret_state[SECRET_KEYS.MAKERSUITE] || extension_settings.caption.allow_reverse_proxy)) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'google' && (secret_state[SECRET_KEYS.MAKERSUITE] || extension_settings.caption.allow_reverse_proxy)) ||
(extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'anthropic' && (secret_state[SECRET_KEYS.CLAUDE] || extension_settings.caption.allow_reverse_proxy)) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'anthropic' && (secret_state[SECRET_KEYS.CLAUDE] || extension_settings.caption.allow_reverse_proxy)) ||

View File

@ -21,6 +21,7 @@
<option value="anthropic">Anthropic</option> <option value="anthropic">Anthropic</option>
<option value="custom" data-i18n="Custom (OpenAI-compatible)">Custom (OpenAI-compatible)</option> <option value="custom" data-i18n="Custom (OpenAI-compatible)">Custom (OpenAI-compatible)</option>
<option value="google">Google AI Studio</option> <option value="google">Google AI Studio</option>
<option value="groq">Groq</option>
<option value="koboldcpp">KoboldCpp</option> <option value="koboldcpp">KoboldCpp</option>
<option value="llamacpp">llama.cpp</option> <option value="llamacpp">llama.cpp</option>
<option value="mistral">MistralAI</option> <option value="mistral">MistralAI</option>
@ -60,6 +61,9 @@
<option data-type="google" value="gemini-1.5-pro-exp-0801">gemini-1.5-pro-exp-0801</option> <option data-type="google" value="gemini-1.5-pro-exp-0801">gemini-1.5-pro-exp-0801</option>
<option data-type="google" value="gemini-1.5-pro-exp-0827">gemini-1.5-pro-exp-0827</option> <option data-type="google" value="gemini-1.5-pro-exp-0827">gemini-1.5-pro-exp-0827</option>
<option data-type="google" value="gemini-pro-vision">gemini-pro-vision</option> <option data-type="google" value="gemini-pro-vision">gemini-pro-vision</option>
<option data-type="groq" value="llama-3.2-11b-vision-preview">llama-3.2-11b-vision-preview</option>
<option data-type="groq" value="llama-3.2-90b-vision-preview">llama-3.2-90b-vision-preview</option>
<option data-type="groq" value="llava-v1.5-7b-4096-preview">llava-v1.5-7b-4096-preview</option>
<option data-type="openrouter" value="openai/gpt-4-vision-preview">openai/gpt-4-vision-preview</option> <option data-type="openrouter" value="openai/gpt-4-vision-preview">openai/gpt-4-vision-preview</option>
<option data-type="openrouter" value="openai/gpt-4o">openai/gpt-4o</option> <option data-type="openrouter" value="openai/gpt-4o">openai/gpt-4o</option>
<option data-type="openrouter" value="openai/gpt-4o-2024-05-13">openai/gpt-4o-2024-05-13</option> <option data-type="openrouter" value="openai/gpt-4o-2024-05-13">openai/gpt-4o-2024-05-13</option>

View File

@ -36,7 +36,7 @@ export async function getMultimodalCaption(base64Img, prompt) {
const isVllm = extension_settings.caption.multimodal_api === 'vllm'; const isVllm = extension_settings.caption.multimodal_api === 'vllm';
const base64Bytes = base64Img.length * 0.75; const base64Bytes = base64Img.length * 0.75;
const compressionLimit = 2 * 1024 * 1024; const compressionLimit = 2 * 1024 * 1024;
if ((['google', 'openrouter', 'mistral'].includes(extension_settings.caption.multimodal_api) && base64Bytes > compressionLimit) || isOoba || isKoboldCpp) { if ((['google', 'openrouter', 'mistral', 'groq'].includes(extension_settings.caption.multimodal_api) && base64Bytes > compressionLimit) || isOoba || isKoboldCpp) {
const maxSide = 1024; const maxSide = 1024;
base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg'); base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg');
} }
@ -135,6 +135,10 @@ function throwIfInvalidModel(useReverseProxy) {
throw new Error('01.AI API key is not set.'); throw new Error('01.AI API key is not set.');
} }
if (extension_settings.caption.multimodal_api === 'groq' && !secret_state[SECRET_KEYS.GROQ]) {
throw new Error('Groq API key is not set.');
}
if (extension_settings.caption.multimodal_api === 'google' && !secret_state[SECRET_KEYS.MAKERSUITE] && !useReverseProxy) { if (extension_settings.caption.multimodal_api === 'google' && !secret_state[SECRET_KEYS.MAKERSUITE] && !useReverseProxy) {
throw new Error('Google AI Studio API key is not set.'); throw new Error('Google AI Studio API key is not set.');
} }

View File

@ -466,13 +466,13 @@ async function ingestDataBankAttachments(source) {
} }
// Download and process the file // Download and process the file
file.text = await getFileAttachment(file.url); const fileText = await getFileAttachment(file.url);
console.log(`Vectors: Retrieved file ${file.name} from Data Bank`); console.log(`Vectors: Retrieved file ${file.name} from Data Bank`);
// Convert kilobytes to string length // Convert kilobytes to string length
const thresholdLength = settings.size_threshold_db * 1024; const thresholdLength = settings.size_threshold_db * 1024;
// Use chunk size from settings if file is larger than threshold // Use chunk size from settings if file is larger than threshold
const chunkSize = file.size > thresholdLength ? settings.chunk_size_db : -1; const chunkSize = file.size > thresholdLength ? settings.chunk_size_db : -1;
await vectorizeFile(file.text, file.name, collectionId, chunkSize, settings.overlap_percent_db); await vectorizeFile(fileText, file.name, collectionId, chunkSize, settings.overlap_percent_db);
} }
return dataBankCollectionIds; return dataBankCollectionIds;

View File

@ -4118,7 +4118,10 @@ async function onModelChange() {
if (oai_settings.max_context_unlocked) { if (oai_settings.max_context_unlocked) {
$('#openai_max_context').attr('max', unlocked_max); $('#openai_max_context').attr('max', unlocked_max);
} }
else if (oai_settings.groq_model.includes('llama-3.1')) { else if (oai_settings.groq_model.includes('llama-3.2') && oai_settings.groq_model.includes('-preview')) {
$('#openai_max_context').attr('max', max_8k);
}
else if (oai_settings.groq_model.includes('llama-3.2') || oai_settings.groq_model.includes('llama-3.1')) {
$('#openai_max_context').attr('max', max_128k); $('#openai_max_context').attr('max', max_128k);
} }
else if (oai_settings.groq_model.includes('llama3-groq')) { else if (oai_settings.groq_model.includes('llama3-groq')) {

View File

@ -107,6 +107,7 @@ async function sendClaudeRequest(request, response) {
} }
const requestBody = { const requestBody = {
/** @type {any} */ system: '',
messages: convertedPrompt.messages, messages: convertedPrompt.messages,
model: request.body.model, model: request.body.model,
max_tokens: request.body.max_tokens, max_tokens: request.body.max_tokens,
@ -120,6 +121,8 @@ async function sendClaudeRequest(request, response) {
requestBody.system = enableSystemPromptCache requestBody.system = enableSystemPromptCache
? [{ type: 'text', text: convertedPrompt.systemPrompt, cache_control: { type: 'ephemeral' } }] ? [{ type: 'text', text: convertedPrompt.systemPrompt, cache_control: { type: 'ephemeral' } }]
: convertedPrompt.systemPrompt; : convertedPrompt.systemPrompt;
} else {
delete requestBody.system;
} }
/* /*
if (Array.isArray(request.body.tools) && request.body.tools.length > 0) { if (Array.isArray(request.body.tools) && request.body.tools.length > 0) {
@ -158,12 +161,13 @@ async function sendClaudeRequest(request, response) {
forwardFetchResponse(generateResponse, response); forwardFetchResponse(generateResponse, response);
} else { } else {
if (!generateResponse.ok) { if (!generateResponse.ok) {
console.log(color.red(`Claude API returned error: ${generateResponse.status} ${generateResponse.statusText}\n${await generateResponse.text()}\n${divider}`)); const generateResponseText = await generateResponse.text();
console.log(color.red(`Claude API returned error: ${generateResponse.status} ${generateResponse.statusText}\n${generateResponseText}\n${divider}`));
return response.status(generateResponse.status).send({ error: true }); return response.status(generateResponse.status).send({ error: true });
} }
const generateResponseJson = await generateResponse.json(); const generateResponseJson = await generateResponse.json();
const responseText = generateResponseJson.content[0].text; const responseText = generateResponseJson?.content?.[0]?.text || '';
console.log('Claude response:', generateResponseJson); console.log('Claude response:', generateResponseJson);
// Wrap it back to OAI format + save the original content // Wrap it back to OAI format + save the original content

View File

@ -55,6 +55,10 @@ router.post('/caption-image', jsonParser, async (request, response) => {
key = readSecret(request.user.directories, SECRET_KEYS.MISTRALAI); key = readSecret(request.user.directories, SECRET_KEYS.MISTRALAI);
} }
if (request.body.api === 'groq') {
key = readSecret(request.user.directories, SECRET_KEYS.GROQ);
}
if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp', 'vllm'].includes(request.body.api) === false) { if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp', 'vllm'].includes(request.body.api) === false) {
console.log('No key found for API', request.body.api); console.log('No key found for API', request.body.api);
return response.sendStatus(400); return response.sendStatus(400);
@ -111,6 +115,10 @@ router.post('/caption-image', jsonParser, async (request, response) => {
apiUrl = 'https://api.01.ai/v1/chat/completions'; apiUrl = 'https://api.01.ai/v1/chat/completions';
} }
if (request.body.api === 'groq') {
apiUrl = 'https://api.groq.com/openai/v1/chat/completions';
}
if (request.body.api === 'mistral') { if (request.body.api === 'mistral') {
apiUrl = 'https://api.mistral.ai/v1/chat/completions'; apiUrl = 'https://api.mistral.ai/v1/chat/completions';
} }