Filter out inapplicable stop strings for Chat Completion (#5337) * Stop strings apply to Chat Completions and should not be greyed out. * Revert "Stop strings apply to Chat Completions and should not be greyed out." This reverts commit 51e5cfee41e1298b0005ff9df5d783c08820ed9a. * Stopping strings should only apply to Text Completions https://github.com/SillyTavern/SillyTavern/pull/5337#pullrequestreview-3987164461 * Custom stop strings still apply * Also apply to non-streaming message clean-up * This comment is now misplaced * Oops, wrong file * Revert package-lock change --------- Co-authored-by: user <user@exmaple.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -2917,9 +2917,15 @@ export function substituteParams(content, options = {}) { | |||
| 2917 | * Gets stopping sequences for the prompt. | 2917 | * Gets stopping sequences for the prompt. |
| 2918 | * @param {boolean} isImpersonate A request is made to impersonate a user | 2918 | * @param {boolean} isImpersonate A request is made to impersonate a user |
| 2919 | * @param {boolean} isContinue A request is made to continue the message | 2919 | * @param {boolean} isContinue A request is made to continue the message |
| 2920 | * @param {string} [api] Optional API name to get API-specific stopping sequences for | ||
| 2920 | * @returns {string[]} Array of stopping strings | 2921 | * @returns {string[]} Array of stopping strings |
| 2921 | */ | 2922 | */ |
| 2922 | export function getStoppingStrings(isImpersonate, isContinue) { | 2923 | export function getStoppingStrings(isImpersonate, isContinue, api = main_api) { |
| 2924 | // Only custom stop strings apply to Chat Completion | ||
| 2925 | if (api === 'openai') { | ||
| 2926 | return getCustomStoppingStrings(); | ||
| 2927 | } | ||
| 2928 | |||
| 2923 | const result = []; | 2929 | const result = []; |
| 2924 | 2930 | ||
| 2925 | if (power_user.context.names_as_stop_strings) { | 2931 | if (power_user.context.names_as_stop_strings) { |
| @@ -3744,7 +3750,7 @@ class StreamingProcessor { | |||
| 3744 | // when streaming, we cache the result of getStoppingStrings instead of calling it once per token. | 3750 | // when streaming, we cache the result of getStoppingStrings instead of calling it once per token. |
| 3745 | const isImpersonate = this.type == 'impersonate'; | 3751 | const isImpersonate = this.type == 'impersonate'; |
| 3746 | const isContinue = this.type == 'continue'; | 3752 | const isContinue = this.type == 'continue'; |
| 3747 | this.stoppingStrings = getStoppingStrings(isImpersonate, isContinue); | 3753 | this.stoppingStrings = getStoppingStrings(isImpersonate, isContinue, main_api); |
| 3748 | 3754 | ||
| 3749 | try { | 3755 | try { |
| 3750 | const sw = new Stopwatch(1000 / power_user.streaming_fps); | 3756 | const sw = new Stopwatch(1000 / power_user.streaming_fps); |
| @@ -6317,7 +6323,7 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI | |||
| 6317 | // Allow for caching of stopping strings. getStoppingStrings is an expensive function, especially with macros | 6323 | // Allow for caching of stopping strings. getStoppingStrings is an expensive function, especially with macros |
| 6318 | // enabled, so for streaming, we call it once and then pass it into each cleanUpMessage call. | 6324 | // enabled, so for streaming, we call it once and then pass it into each cleanUpMessage call. |
| 6319 | if (!stoppingStrings) { | 6325 | if (!stoppingStrings) { |
| 6320 | stoppingStrings = getStoppingStrings(isImpersonate, isContinue); | 6326 | stoppingStrings = getStoppingStrings(isImpersonate, isContinue, main_api); |
| 6321 | } | 6327 | } |
| 6322 | 6328 | ||
| 6323 | for (const stoppingString of stoppingStrings) { | 6329 | for (const stoppingString of stoppingStrings) { |