mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-18 21:20:39 +01:00
Export variable manipulation functions to getContext
This commit is contained in:
parent
e3f0a8d35b
commit
1df209c284
@ -69,6 +69,7 @@ import { textgenerationwebui_settings } from './textgen-settings.js';
|
||||
import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js';
|
||||
import { ToolManager } from './tool-calling.js';
|
||||
import { timestampToMoment, uuidv4 } from './utils.js';
|
||||
import { getGlobalVariable, getLocalVariable, setGlobalVariable, setLocalVariable } from './variables.js';
|
||||
|
||||
export function getContext() {
|
||||
return {
|
||||
@ -175,6 +176,16 @@ export function getContext() {
|
||||
humanizedDateTime,
|
||||
updateMessageBlock,
|
||||
appendMediaToMessage,
|
||||
variables: {
|
||||
local: {
|
||||
get: getLocalVariable,
|
||||
set: setLocalVariable,
|
||||
},
|
||||
global: {
|
||||
get: getGlobalVariable,
|
||||
set: setGlobalVariable,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import { isFalseBoolean, convertValueType, isTrueBoolean } from './utils.js';
|
||||
|
||||
const MAX_LOOPS = 100;
|
||||
|
||||
function getLocalVariable(name, args = {}) {
|
||||
export function getLocalVariable(name, args = {}) {
|
||||
if (!chat_metadata.variables) {
|
||||
chat_metadata.variables = {};
|
||||
}
|
||||
@ -45,7 +45,7 @@ function getLocalVariable(name, args = {}) {
|
||||
return (localVariable?.trim?.() === '' || isNaN(Number(localVariable))) ? (localVariable || '') : Number(localVariable);
|
||||
}
|
||||
|
||||
function setLocalVariable(name, value, args = {}) {
|
||||
export function setLocalVariable(name, value, args = {}) {
|
||||
if (!name) {
|
||||
throw new Error('Variable name cannot be empty or undefined.');
|
||||
}
|
||||
@ -80,7 +80,7 @@ function setLocalVariable(name, value, args = {}) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function getGlobalVariable(name, args = {}) {
|
||||
export function getGlobalVariable(name, args = {}) {
|
||||
let globalVariable = extension_settings.variables.global[args.key ?? name];
|
||||
if (args.index !== undefined) {
|
||||
try {
|
||||
@ -102,7 +102,7 @@ function getGlobalVariable(name, args = {}) {
|
||||
return (globalVariable?.trim?.() === '' || isNaN(Number(globalVariable))) ? (globalVariable || '') : Number(globalVariable);
|
||||
}
|
||||
|
||||
function setGlobalVariable(name, value, args = {}) {
|
||||
export function setGlobalVariable(name, value, args = {}) {
|
||||
if (!name) {
|
||||
throw new Error('Variable name cannot be empty or undefined.');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user