Skip to content

chew1976/dynamic-vars

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic Variable Hooks for SillyTavern

This is an extension for SillyTavern that allows you to define pools of variables and use them in your character cards, lorebooks, and messages. The extension will replace placeholders with a randomly chosen value from the corresponding pool for the duration of a chat session.

Features

  • Variable Pools: Define named lists of values (e.g., a list of names, locations, or items).
  • Random Selection: Automatically selects a random value from a pool when a placeholder is encountered.
  • Session Caching: Remembers the chosen value for each variable throughout a single chat session, ensuring consistency.
  • Number Ranges: Generate a random number within a specified range.
  • Inline Randomization: Quickly get a random value from a temporary list without creating a permanent pool.
  • Re-generation: Force a new random value to be selected for a variable that has already been stored in the session.
  • User-Friendly UI: Easily add, edit, and delete your variable pools directly in the SillyTavern extensions menu.
  • Auto-Cleaning: Automatically removes duplicate values from your pools and sorts them for you.

Installation

  1. In SillyTavern, go to the extensions menu (the wand icon on the top right).
  2. Click on "Download Extension".
  3. Paste the URL of this GitHub repository into the text field.
  4. Click "Download".
  5. The extension will be installed. You may need to restart SillyTavern for it to take full effect.

Usage

Once installed, a "Dynamic Variable Hooks" section will appear in your extensions settings panel.

Creating Variable Pools

  1. Expand the "Dynamic Variable Hooks" drawer.
  2. Click "Add Variable" to create a new pool.
  3. In the "Variable Name" field, enter a name for your pool (e.g., name, city).
  4. In the "Comma-separated values" field, enter the possible values, separated by commas (e.g., Alice, Bob, Charlie).

Using Placeholders

You can use your variables in any text field that is processed by SillyTavern (character definitions, lorebooks, chat messages, etc.) using the {{getrand::...}} syntax.

From a Variable Pool

To get a random value from a pool you created, use its name.

My name is {{getrand::name}} and I live in {{getrand::city}}.

From a Number Range

To get a random number within an inclusive range, use the format min-max.

I have {{getrand::1-10}} apples.

From an Inline List (One-off)

For temporary values you don't need to store in a pool, you can provide a pipe-separated list directly in the placeholder. A random value will be chosen from this list and will not be stored for the session.

Let's go to the {{getrand::beach|mountains|city}}.

Re-generating a Stored Value (regetrand)

If you have already used {{getrand::city}} and it has been stored as "New York" for the session, you might want to get a new random city. Use regetrand to force a new value to be selected from the pool, which will then overwrite the stored session value.

I used to live in {{getrand::city}}, but now I'm moving to {{regetrand::city}}!

In this example, the first placeholder might resolve to "New York", and the second might resolve to "Los Angeles". Any future calls to {{getrand::city}} in the same session will now return "Los Angeles".

Example Character Setup

Here is an example of how you can use Dynamic Variable Hooks in a character's "Description" and "First Message" to make them more varied and dynamic each time you start a new chat.

Character Definition Fields

You can place these placeholders directly into the character card fields in SillyTavern.

Description:

Name: {{getrand::char_name}}
Age: {{getrand::18-22}}
Occupation: {{getrand::Student|Barista|Artist|Musician}}

{{getrand::char_name}} is a college student living in {{getrand::city}}. She's known for her {{getrand::positive_trait}} personality but can sometimes be a bit {{getrand::negative_trait}}.

First Message:

*I sit down across from you at the {{getrand::cafe|library|park_bench}}, offering a shy smile.* "Hi, I'm {{getrand::char_name}}. Is this seat taken?"

Corresponding Variable Pools

For the above example to work, you would set up the following pools in the extension's settings:

Variable Name Comma-separated values
char_name Alice, Bella, Chloe, Diana
city Northwood, Silvercreek, Oakhaven, Maple Valley
positive_trait bubbly, thoughtful, creative, adventurous
negative_trait stubborn, forgetful, shy, impulsive

License

This project is licensed under the MIT License.

About

An extension for SillyTavern that allows you to define and use dynamic variables.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published