feat: add Pick placeholder for random selection from list
This commit is contained in:
@@ -25,3 +25,7 @@ Get a random word from a WordList. can be used as a Macro or a Placeholder. Macr
|
|||||||
### Shuffle
|
### Shuffle
|
||||||
|
|
||||||
Shuffle a list of values. can be used as Placeholder only. Placeholder format: `%%Shuffle::Value1::Value2::Value3;;separator%%`. Example: `%%Shuffle::Value1::Value2::Value3;;, %%` will return `Value3, Value1, Value2`.
|
Shuffle a list of values. can be used as Placeholder only. Placeholder format: `%%Shuffle::Value1::Value2::Value3;;separator%%`. Example: `%%Shuffle::Value1::Value2::Value3;;, %%` will return `Value3, Value1, Value2`.
|
||||||
|
|
||||||
|
### Pick
|
||||||
|
|
||||||
|
Pick a random value from a list of values. can be used as Placeholder only. Placeholder format: `%%Pick::Value1::Value2::Value3%%`. Example: `%%Pick::Red::Blue::Green%%` will return one of `Red`, `Blue`, or `Green` randomly.
|
||||||
|
|||||||
11
bun.lock
11
bun.lock
@@ -1,14 +1,9 @@
|
|||||||
{
|
{
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 0,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"name": "st-randomness-helpers",
|
"name": "st-randomness-helpers",
|
||||||
"dependencies": {
|
|
||||||
"react": "^19.1.1",
|
|
||||||
"react-dom": "^19.1.1",
|
|
||||||
"zod": "^4.0.17",
|
|
||||||
"zustand": "^5.0.7",
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.1.4",
|
"@biomejs/biome": "2.1.4",
|
||||||
"@commitlint/cli": "^19.8.1",
|
"@commitlint/cli": "^19.8.1",
|
||||||
@@ -17,6 +12,10 @@
|
|||||||
"@types/react-dom": "^19.1.7",
|
"@types/react-dom": "^19.1.7",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"lint-staged": "^16.1.5",
|
"lint-staged": "^16.1.5",
|
||||||
|
"react": "^19.1.1",
|
||||||
|
"react-dom": "^19.1.1",
|
||||||
|
"zod": "^4.0.17",
|
||||||
|
"zustand": "^5.0.7",
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5",
|
"typescript": "^5",
|
||||||
|
|||||||
116
dist/index.js
vendored
116
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,9 +1,11 @@
|
|||||||
|
import { setupPickPlaceholders } from '@/services/pick'
|
||||||
import { setupRandomWordPlaceholders } from '@/services/randomWord'
|
import { setupRandomWordPlaceholders } from '@/services/randomWord'
|
||||||
import { setupShufflePlaceholders } from '@/services/shuffle'
|
import { setupShufflePlaceholders } from '@/services/shuffle'
|
||||||
|
|
||||||
const initializePlaceholders = () => {
|
const initializePlaceholders = () => {
|
||||||
setupRandomWordPlaceholders()
|
setupRandomWordPlaceholders()
|
||||||
setupShufflePlaceholders()
|
setupShufflePlaceholders()
|
||||||
|
setupPickPlaceholders()
|
||||||
}
|
}
|
||||||
|
|
||||||
export default initializePlaceholders
|
export default initializePlaceholders
|
||||||
|
|||||||
19
src/services/pick.ts
Normal file
19
src/services/pick.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import type { generationData } from '@/types/SillyTavern'
|
||||||
|
|
||||||
|
const pickPlaceholderRegex = /%%pick::([\w\W]*?)%%/g
|
||||||
|
|
||||||
|
export const setupPickPlaceholders = () => {
|
||||||
|
const { eventTypes, eventSource } = SillyTavern.getContext()
|
||||||
|
eventSource.on(eventTypes.GENERATE_AFTER_DATA, (chat: generationData) => {
|
||||||
|
chat.prompt = chat.prompt.replaceAll(
|
||||||
|
pickPlaceholderRegex,
|
||||||
|
(_, optionsString: string) => {
|
||||||
|
const options = optionsString.split('::')
|
||||||
|
if (options.length === 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return options[Math.floor(Math.random() * options.length)] ?? ''
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user