Merge branch 'staging' into webpack

This commit is contained in:
Cohee 2024-10-26 19:11:29 +03:00
commit f5bdb52c25
12 changed files with 90 additions and 11 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "sillytavern",
"version": "1.12.6",
"version": "1.12.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sillytavern",
"version": "1.12.6",
"version": "1.12.7",
"hasInstallScript": true,
"license": "AGPL-3.0",
"dependencies": {

View File

@ -84,7 +84,7 @@
"type": "git",
"url": "https://github.com/SillyTavern/SillyTavern.git"
},
"version": "1.12.6",
"version": "1.12.7",
"scripts": {
"start": "node server.js",
"start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js",

View File

@ -2797,6 +2797,8 @@
<h4 data-i18n="Claude Model">Claude Model</h4>
<select id="model_claude_select">
<optgroup label="Versions">
<option value="claude-3-5-sonnet-latest">claude-3-5-sonnet-latest</option>
<option value="claude-3-5-sonnet-20241022">claude-3-5-sonnet-20241022</option>
<option value="claude-3-5-sonnet-20240620">claude-3-5-sonnet-20240620</option>
<option value="claude-3-opus-20240229">claude-3-opus-20240229</option>
<option value="claude-3-sonnet-20240229">claude-3-sonnet-20240229</option>

View File

@ -2577,7 +2577,7 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re
if (_replaceCharacterCard) {
const fields = getCharacterCardFields();
environment.charPrompt = fields.system || '';
environment.charJailbreak = fields.jailbreak || '';
environment.charInstruction = environment.charJailbreak = fields.jailbreak || '';
environment.description = fields.description || '';
environment.personality = fields.personality || '';
environment.scenario = fields.scenario || '';
@ -3847,7 +3847,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
if (addUserAlignment) {
const alignmentMessage = {
name: name1,
mes: power_user.instruct.user_alignment_message,
mes: substituteParams(power_user.instruct.user_alignment_message),
is_user: true,
};
userAlignmentMessage = formatMessageHistoryItem(alignmentMessage, isInstruct, force_output_sequence.FIRST);
@ -8225,6 +8225,10 @@ window['SillyTavern'].getContext = function () {
substituteParams,
substituteParamsExtended,
SlashCommandParser,
SlashCommand,
SlashCommandArgument,
SlashCommandNamedArgument,
ARGUMENT_TYPE,
executeSlashCommandsWithOptions,
/** @deprecated Use SlashCommandParser.addCommandObject() instead */
registerSlashCommand: registerSlashCommand,

View File

@ -1458,6 +1458,7 @@ jQuery(function () {
wrapper.classList.add('height100p', 'wide100p', 'flex-container');
wrapper.classList.add('flexFlowColumn', 'justifyCenter', 'alignitemscenter');
const textarea = document.createElement('textarea');
textarea.dataset.for = broId;
textarea.value = String(contentEditable ? bro[0].innerText : bro.val());
textarea.classList.add('height100p', 'wide100p', 'maximized_textarea');
bro.hasClass('monospace') && textarea.classList.add('monospace');

View File

@ -43,6 +43,8 @@
<option data-type="openai" value="gpt-4o">gpt-4o</option>
<option data-type="openai" value="gpt-4o-mini">gpt-4o-mini</option>
<option data-type="openai" value="chatgpt-4o-latest">chatgpt-4o-latest</option>
<option data-type="anthropic" value="claude-3-5-sonnet-latest">claude-3-5-sonnet-latest</option>
<option data-type="anthropic" value="claude-3-5-sonnet-20241022">claude-3-5-sonnet-20241022</option>
<option data-type="anthropic" value="claude-3-5-sonnet-20240620">claude-3-5-sonnet-20240620</option>
<option data-type="anthropic" value="claude-3-opus-20240229">claude-3-opus-20240229</option>
<option data-type="anthropic" value="claude-3-sonnet-20240229">claude-3-sonnet-20240229</option>

View File

@ -35,6 +35,7 @@ export const SECRET_KEYS = {
STABILITY: 'api_key_stability',
BLOCKENTROPY: 'api_key_blockentropy',
CUSTOM_OPENAI_TTS: 'api_key_custom_openai_tts',
TAVILY: 'api_key_tavily',
};
const INPUT_MAP = {

View File

@ -1397,6 +1397,13 @@ export function initDefaultSlashCommands() {
callback: popupCallback,
returns: 'popup text',
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'scroll',
description: 'allows vertical scrolling of the content',
typeList: [ARGUMENT_TYPE.BOOLEAN],
enumList: commonEnumProviders.boolean('trueFalse')(),
defaultValue: 'true',
}),
SlashCommandNamedArgument.fromProps({
name: 'large',
description: 'show large popup',
@ -2093,7 +2100,7 @@ async function buttonsCallback(args, text) {
popupContainer.innerHTML = safeValue;
popupContainer.appendChild(buttonContainer);
popup = new Popup(popupContainer, POPUP_TYPE.TEXT, '', { okButton: 'Cancel' });
popup = new Popup(popupContainer, POPUP_TYPE.TEXT, '', { okButton: 'Cancel', allowVerticalScrolling: true });
popup.show()
.then((result => resolve(typeof result === 'number' ? resultToButtonMap.get(result) ?? '' : '')))
.catch(() => resolve(''));
@ -2110,6 +2117,7 @@ async function popupCallback(args, value) {
/** @type {import('./popup.js').PopupOptions} */
const popupOptions = {
allowVerticalScrolling: !isFalseBoolean(args?.scroll),
large: isTrueBoolean(args?.large),
wide: isTrueBoolean(args?.wide),
wider: isTrueBoolean(args?.wider),

View File

@ -9,7 +9,7 @@
<li><tt>&lcub;&lcub;original&rcub;&rcub;</tt> <span data-i18n="help_macros_5">global prompts defined in API settings. Only valid in Advanced Definitions prompt overrides.</span></li>
<li><tt>&lcub;&lcub;input&rcub;&rcub;</tt> <span data-i18n="help_macros_6">the user input</span></li>
<li><tt>&lcub;&lcub;charPrompt&rcub;&rcub;</tt> <span data-i18n="help_macros_7">the Character's Main Prompt override</span></li>
<li><tt>&lcub;&lcub;charJailbreak&rcub;&rcub;</tt> <span data-i18n="help_macros_8">the Character's Jailbreak Prompt override</span></li>
<li><tt>&lcub;&lcub;charInstruction&rcub;&rcub;</tt> <span data-i18n="help_macros_8">the Character's Post-History Instructions override</span></li>
<li><tt>&lcub;&lcub;description&rcub;&rcub;</tt> <span data-i18n="help_macros_9">the Character's Description</span></li>
<li><tt>&lcub;&lcub;personality&rcub;&rcub;</tt> <span data-i18n="help_macros_10">the Character's Personality</span></li>
<li><tt>&lcub;&lcub;scenario&rcub;&rcub;</tt> <span data-i18n="help_macros_11">the Character's Scenario</span></li>

View File

@ -206,6 +206,54 @@ router.post('/searxng', jsonParser, async (request, response) => {
}
});
router.post('/tavily', jsonParser, async (request, response) => {
try {
const apiKey = readSecret(request.user.directories, SECRET_KEYS.TAVILY);
if (!apiKey) {
console.log('No Tavily key found');
return response.sendStatus(400);
}
const { query } = request.body;
const body = {
query: query,
api_key: apiKey,
search_depth: 'basic',
topic: 'general',
include_answer: true,
include_raw_content: false,
include_images: false,
include_image_descriptions: false,
include_domains: [],
max_results: 10,
};
const result = await fetch('https://api.tavily.com/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
console.log('Tavily query', query);
if (!result.ok) {
const text = await result.text();
console.log('Tavily request failed', result.statusText, text);
return response.status(500).send(text);
}
const data = await result.json();
return response.json(data);
} catch (error) {
console.log(error);
return response.sendStatus(500);
}
});
router.post('/visit', jsonParser, async (request, response) => {
try {
const url = request.body.url;

View File

@ -47,6 +47,7 @@ export const SECRET_KEYS = {
STABILITY: 'api_key_stability',
BLOCKENTROPY: 'api_key_blockentropy',
CUSTOM_OPENAI_TTS: 'api_key_custom_openai_tts',
TAVILY: 'api_key_tavily',
};
// These are the keys that are safe to expose, even if allowKeysExposure is false

View File

@ -396,11 +396,23 @@ export function convertGooglePrompt(messages, model, useSysPrompt = false, charN
// similar story as claude
if (message.name) {
if (Array.isArray(message.content)) {
message.content[0].text = `${message.name}: ${message.content[0].text}`;
} else {
message.content = `${message.name}: ${message.content}`;
if (userName && message.name === 'example_user') {
message.name = userName;
}
if (charName && message.name === 'example_assistant') {
message.name = charName;
}
if (Array.isArray(message.content)) {
if (!message.content[0].text.startsWith(`${message.name}: `)) {
message.content[0].text = `${message.name}: ${message.content[0].text}`;
}
} else {
if (!message.content.startsWith(`${message.name}: `)) {
message.content = `${message.name}: ${message.content}`;
}
}
delete message.name;
}