feat: add Pick placeholder for random selection from list

This commit is contained in:
2025-12-01 23:58:27 -06:00
parent a45b56fa93
commit cfef4fd73d
5 changed files with 88 additions and 64 deletions
+19
View 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)] ?? ''
}
)
})
}