From 738039142451d34fdcec9f11435632a0a5abc57b Mon Sep 17 00:00:00 2001 From: Sven Olderaan Date: Sun, 16 Mar 2025 16:55:41 +0100 Subject: [PATCH] Make character parameter required when AI character selection is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add character to required parameters when setting is enabled - Update documentation to clarify character is required - Ensure handler logic provides default character if missing - Maintain backward compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- example.html | 6 +++--- index.js | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/example.html b/example.html index 0867eec..75d8aea 100644 --- a/example.html +++ b/example.html @@ -92,12 +92,12 @@ generateChatBubbleImage("I'm thinking...", "thought") The function parameters are: - text: The text to display in the chat bubble (required string) -- character: The character to use for the bubble (optional string: "Example", "Bianca", etc.) +- character: The character to use for the bubble (required string: "Example", "Bianca", etc.) - bubble_type: The type of bubble to use (optional string: "speech" or "thought") -When you want to create a chat bubble, call this function with the text you want to display. +When you want to create a chat bubble, call this function with the text and character. Example usage: -generateChatBubbleImage("Hello world!") +generateChatBubbleImage("Hello world!", "Example") generateChatBubbleImage("Hello from Bianca", "Bianca") generateChatBubbleImage("I'm thinking...", "Example", "thought")

ALTERNATIVE: If the AI can't call the function directly, you can instruct it to respond with Markdown formatted like this:

diff --git a/index.js b/index.js index 52dd9bf..70688fb 100644 --- a/index.js +++ b/index.js @@ -219,12 +219,20 @@ function registerFunctionTool() { description: 'Legacy parameter: The visual style of the chat bubble (default, modern, retro, minimal).' }; + // Define required parameters + const requiredParams = ['text']; + + // Add character to required parameters if enabled + if (extension_settings[extensionName].use_character_param) { + requiredParams.push('character'); + } + // Define parameter schema following JSON schema format const bubbleSchema = Object.freeze({ $schema: 'http://json-schema.org/draft-04/schema#', type: 'object', properties: properties, - required: ['text'] + required: requiredParams }); // Register the function tool using SillyTavern's own API @@ -236,8 +244,16 @@ function registerFunctionTool() { action: async (args) => { if (!args?.text) return ''; - // Only pass character if the setting is enabled - const character = extension_settings[extensionName].use_character_param ? args.character : null; + let character; + + if (extension_settings[extensionName].use_character_param) { + // When the setting is enabled, character is required + // If not provided, use default + character = args.character || extension_settings[extensionName].default_character; + } else { + // When the setting is disabled, always use the default character + character = extension_settings[extensionName].default_character; + } return generateChatBubbleImage(args.text, args.style, character, args.bubble_type); },