Merge branch 'staging' into webpack

f5bdb52c251bc3eebeea1a70d1214c05ff2e279d

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

12 files changed, +86 -7Showing whitespace changes
package-lock.json+2 -2
@@ -1,12 +1,12 @@
11{
22 "name": "sillytavern",
33 "version": "1.12.67",
44 "lockfileVersion": 3,
55 "requires": true,
66 "packages": {
77 "": {
88 "name": "sillytavern",
99 "version": "1.12.67",
1010 "hasInstallScript": true,
1111 "license": "AGPL-3.0",
1212 "dependencies": {
package.json+1 -1
@@ -84,7 +84,7 @@
8484 "type": "git",
8585 "url": "https://github.com/SillyTavern/SillyTavern.git"
8686 },
8787 "version": "1.12.67",
8888 "scripts": {
8989 "start": "node server.js",
9090 "start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js",
public/index.html+2 -0
@@ -2797,6 +2797,8 @@
27972797 <h4 data-i18n="Claude Model">Claude Model</h4>
27982798 <select id="model_claude_select">
27992799 <optgroup label="Versions">
2800+ <option value="claude-3-5-sonnet-latest">claude-3-5-sonnet-latest</option>
2801+ <option value="claude-3-5-sonnet-20241022">claude-3-5-sonnet-20241022</option>
28002802 <option value="claude-3-5-sonnet-20240620">claude-3-5-sonnet-20240620</option>
28012803 <option value="claude-3-opus-20240229">claude-3-opus-20240229</option>
28022804 <option value="claude-3-sonnet-20240229">claude-3-sonnet-20240229</option>
public/script.js+6 -2
@@ -2577,7 +2577,7 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re
25772577 if (_replaceCharacterCard) {
25782578 const fields = getCharacterCardFields();
25792579 environment.charPrompt = fields.system || '';
25802580 environment.charInstruction = environment.charJailbreak = fields.jailbreak || '';
25812581 environment.description = fields.description || '';
25822582 environment.personality = fields.personality || '';
25832583 environment.scenario = fields.scenario || '';
@@ -3847,7 +3847,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
38473847 if (addUserAlignment) {
38483848 const alignmentMessage = {
38493849 name: name1,
38503850 mes: substituteParams(power_user.instruct.user_alignment_message),
38513851 is_user: true,
38523852 };
38533853 userAlignmentMessage = formatMessageHistoryItem(alignmentMessage, isInstruct, force_output_sequence.FIRST);
@@ -8225,6 +8225,10 @@ window['SillyTavern'].getContext = function () {
82258225 substituteParams,
82268226 substituteParamsExtended,
82278227 SlashCommandParser,
8228+ SlashCommand,
8229+ SlashCommandArgument,
8230+ SlashCommandNamedArgument,
8231+ ARGUMENT_TYPE,
82288232 executeSlashCommandsWithOptions,
82298233 /** @deprecated Use SlashCommandParser.addCommandObject() instead */
82308234 registerSlashCommand: registerSlashCommand,
public/scripts/chats.js+1 -0
@@ -1458,6 +1458,7 @@ jQuery(function () {
14581458 wrapper.classList.add('height100p', 'wide100p', 'flex-container');
14591459 wrapper.classList.add('flexFlowColumn', 'justifyCenter', 'alignitemscenter');
14601460 const textarea = document.createElement('textarea');
1461+ textarea.dataset.for = broId;
14611462 textarea.value = String(contentEditable ? bro[0].innerText : bro.val());
14621463 textarea.classList.add('height100p', 'wide100p', 'maximized_textarea');
14631464 bro.hasClass('monospace') && textarea.classList.add('monospace');
public/scripts/extensions/caption/settings.html+2 -0
@@ -43,6 +43,8 @@
4343 <option data-type="openai" value="gpt-4o">gpt-4o</option>
4444 <option data-type="openai" value="gpt-4o-mini">gpt-4o-mini</option>
4545 <option data-type="openai" value="chatgpt-4o-latest">chatgpt-4o-latest</option>
46+ <option data-type="anthropic" value="claude-3-5-sonnet-latest">claude-3-5-sonnet-latest</option>
47+ <option data-type="anthropic" value="claude-3-5-sonnet-20241022">claude-3-5-sonnet-20241022</option>
4648 <option data-type="anthropic" value="claude-3-5-sonnet-20240620">claude-3-5-sonnet-20240620</option>
4749 <option data-type="anthropic" value="claude-3-opus-20240229">claude-3-opus-20240229</option>
4850 <option data-type="anthropic" value="claude-3-sonnet-20240229">claude-3-sonnet-20240229</option>
public/scripts/secrets.js+1 -0
@@ -35,6 +35,7 @@ export const SECRET_KEYS = {
3535 STABILITY: 'api_key_stability',
3636 BLOCKENTROPY: 'api_key_blockentropy',
3737 CUSTOM_OPENAI_TTS: 'api_key_custom_openai_tts',
38+ TAVILY: 'api_key_tavily',
3839};
3940
4041const INPUT_MAP = {
public/scripts/slash-commands.js+9 -1
@@ -1398,6 +1398,13 @@ export function initDefaultSlashCommands() {
13981398 returns: 'popup text',
13991399 namedArgumentList: [
14001400 SlashCommandNamedArgument.fromProps({
1401+ name: 'scroll',
1402+ description: 'allows vertical scrolling of the content',
1403+ typeList: [ARGUMENT_TYPE.BOOLEAN],
1404+ enumList: commonEnumProviders.boolean('trueFalse')(),
1405+ defaultValue: 'true',
1406+ }),
1407+ SlashCommandNamedArgument.fromProps({
14011408 name: 'large',
14021409 description: 'show large popup',
14031410 typeList: [ARGUMENT_TYPE.BOOLEAN],
@@ -2093,7 +2100,7 @@ async function buttonsCallback(args, text) {
20932100 popupContainer.innerHTML = safeValue;
20942101 popupContainer.appendChild(buttonContainer);
20952102
20962103 popup = new Popup(popupContainer, POPUP_TYPE.TEXT, '', { okButton: 'Cancel', allowVerticalScrolling: true });
20972104 popup.show()
20982105 .then((result => resolve(typeof result === 'number' ? resultToButtonMap.get(result) ?? '' : '')))
20992106 .catch(() => resolve(''));
@@ -2110,6 +2117,7 @@ async function popupCallback(args, value) {
21102117
21112118 /** @type {import('./popup.js').PopupOptions} */
21122119 const popupOptions = {
2120+ allowVerticalScrolling: !isFalseBoolean(args?.scroll),
21132121 large: isTrueBoolean(args?.large),
21142122 wide: isTrueBoolean(args?.wide),
21152123 wider: isTrueBoolean(args?.wider),
public/scripts/templates/macros.html+1 -1
@@ -9,7 +9,7 @@
99 <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>
1010 <li><tt>&lcub;&lcub;input&rcub;&rcub;</tt> – <span data-i18n="help_macros_6">the user input</span></li>
1111 <li><tt>&lcub;&lcub;charPrompt&rcub;&rcub;</tt> – <span data-i18n="help_macros_7">the Character's Main Prompt override</span></li>
1212 <li><tt>&lcub;&lcub;charJailbreakcharInstruction&rcub;&rcub;</tt> – <span data-i18n="help_macros_8">the Character's JailbreakPost-History PromptInstructions override</span></li>
1313 <li><tt>&lcub;&lcub;description&rcub;&rcub;</tt> – <span data-i18n="help_macros_9">the Character's Description</span></li>
1414 <li><tt>&lcub;&lcub;personality&rcub;&rcub;</tt> – <span data-i18n="help_macros_10">the Character's Personality</span></li>
1515 <li><tt>&lcub;&lcub;scenario&rcub;&rcub;</tt> – <span data-i18n="help_macros_11">the Character's Scenario</span></li>
src/endpoints/search.js+48 -0
@@ -206,6 +206,54 @@ router.post('/searxng', jsonParser, async (request, response) => {
206206 }
207207});
208208
209+router.post('/tavily', jsonParser, async (request, response) => {
210+ try {
211+ const apiKey = readSecret(request.user.directories, SECRET_KEYS.TAVILY);
212+
213+ if (!apiKey) {
214+ console.log('No Tavily key found');
215+ return response.sendStatus(400);
216+ }
217+
218+ const { query } = request.body;
219+
220+ const body = {
221+ query: query,
222+ api_key: apiKey,
223+ search_depth: 'basic',
224+ topic: 'general',
225+ include_answer: true,
226+ include_raw_content: false,
227+ include_images: false,
228+ include_image_descriptions: false,
229+ include_domains: [],
230+ max_results: 10,
231+ };
232+
233+ const result = await fetch('https://api.tavily.com/search', {
234+ method: 'POST',
235+ headers: {
236+ 'Content-Type': 'application/json',
237+ },
238+ body: JSON.stringify(body),
239+ });
240+
241+ console.log('Tavily query', query);
242+
243+ if (!result.ok) {
244+ const text = await result.text();
245+ console.log('Tavily request failed', result.statusText, text);
246+ return response.status(500).send(text);
247+ }
248+
249+ const data = await result.json();
250+ return response.json(data);
251+ } catch (error) {
252+ console.log(error);
253+ return response.sendStatus(500);
254+ }
255+});
256+
209257router.post('/visit', jsonParser, async (request, response) => {
210258 try {
211259 const url = request.body.url;
src/endpoints/secrets.js+1 -0
@@ -47,6 +47,7 @@ export const SECRET_KEYS = {
4747 STABILITY: 'api_key_stability',
4848 BLOCKENTROPY: 'api_key_blockentropy',
4949 CUSTOM_OPENAI_TTS: 'api_key_custom_openai_tts',
50+ TAVILY: 'api_key_tavily',
5051};
5152
5253// These are the keys that are safe to expose, even if allowKeysExposure is false
src/prompt-converters.js+12 -0
@@ -396,11 +396,23 @@ export function convertGooglePrompt(messages, model, useSysPrompt = false, charN
396396
397397 // similar story as claude
398398 if (message.name) {
399+ if (userName && message.name === 'example_user') {
400+ message.name = userName;
401+ }
402+ if (charName && message.name === 'example_assistant') {
403+ message.name = charName;
404+ }
405+
399406 if (Array.isArray(message.content)) {
407+ if (!message.content[0].text.startsWith(`${message.name}: `)) {
400408 message.content[0].text = `${message.name}: ${message.content[0].text}`;
409+ }
401410 } else {
411+ if (!message.content.startsWith(`${message.name}: `)) {
402412 message.content = `${message.name}: ${message.content}`;
403413 }
414+ }
415+
404416 delete message.name;
405417 }
406418