feat: add Pick placeholder for random selection from list
This commit is contained in:
@@ -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