mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add support for cycle prompt
This commit is contained in:
@ -469,7 +469,7 @@ function populateDialogueExamples(prompts, chatCompletion) {
|
|||||||
* @param {string} options.quietPrompt - A quiet prompt to be used in the conversation.
|
* @param {string} options.quietPrompt - A quiet prompt to be used in the conversation.
|
||||||
* @param {string} options.type - The type of the chat, can be 'impersonate'.
|
* @param {string} options.type - The type of the chat, can be 'impersonate'.
|
||||||
*/
|
*/
|
||||||
function populateChatCompletion (prompts, chatCompletion, {bias, quietPrompt, type} = {}) {
|
function populateChatCompletion (prompts, chatCompletion, {bias, quietPrompt, type, cyclePrompt} = {}) {
|
||||||
//Helper function for the recurring task of preparing a prompt for the chat completion
|
//Helper function for the recurring task of preparing a prompt for the chat completion
|
||||||
const addToChatCompletion = (source, target = null) => {
|
const addToChatCompletion = (source, target = null) => {
|
||||||
if (false === prompts.has(source)) return;
|
if (false === prompts.has(source)) return;
|
||||||
@ -557,6 +557,18 @@ function populateChatCompletion (prompts, chatCompletion, {bias, quietPrompt, ty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type === 'continue') {
|
||||||
|
const continuePrompt = new Prompt({
|
||||||
|
identifier: 'continueNudge',
|
||||||
|
role: 'system,',
|
||||||
|
content: '[Continue the following message. Do not include ANY parts of the original message. Use capitalization and punctuation as if your reply is a part of the original message:\n\n + ' + cyclePrompt + ']',
|
||||||
|
system_prompt: true
|
||||||
|
});
|
||||||
|
const preparedPrompt = promptManager.preparePrompt(continuePrompt);
|
||||||
|
const continueMessage = Message.fromPrompt(preparedPrompt);
|
||||||
|
chatCompletion.insertAtEnd(continueMessage, 'chatHistory')
|
||||||
|
}
|
||||||
|
|
||||||
// Decide whether dialogue examples should always be added
|
// Decide whether dialogue examples should always be added
|
||||||
if (power_user.pin_examples) {
|
if (power_user.pin_examples) {
|
||||||
populateDialogueExamples(prompts, chatCompletion);
|
populateDialogueExamples(prompts, chatCompletion);
|
||||||
@ -664,7 +676,7 @@ function prepareOpenAIMessages({
|
|||||||
eventSource.emit(event_types.OAI_BEFORE_CHATCOMPLETION, prompts);
|
eventSource.emit(event_types.OAI_BEFORE_CHATCOMPLETION, prompts);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
populateChatCompletion(prompts, chatCompletion, {bias, quietPrompt, type});
|
populateChatCompletion(prompts, chatCompletion, {bias, quietPrompt, type, cyclePrompt});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof TokenBudgetExceededError) {
|
if (error instanceof TokenBudgetExceededError) {
|
||||||
toastr.error('An error occurred while counting tokens: Token budget exceeded.')
|
toastr.error('An error occurred while counting tokens: Token budget exceeded.')
|
||||||
|
Reference in New Issue
Block a user