Add aggressive stop setting

This commit is contained in:
Webifi 2023-07-25 14:53:29 -05:00
parent b0812796a1
commit 1ef08110c3
3 changed files with 41 additions and 14 deletions

View File

@ -109,20 +109,38 @@ export const runPetalsCompletionRequest = async (
chatResponse.updateFromError(err.message) chatResponse.updateFromError(err.message)
throw err throw err
} }
window.setTimeout(() => { chatResponse.updateFromAsyncResponse(
chatResponse.updateFromAsyncResponse( {
{ model,
model, choices: [{
choices: [{ delta: {
delta: { content: response.outputs,
content: response.outputs, role: 'assistant'
role: 'assistant' },
}, finish_reason: (response.stop ? 'stop' : null)
finish_reason: (response.stop ? 'stop' : null) }]
}] } as any
} as any )
) if (chat.settings.aggressiveStop && !response.stop) {
}, 1) // check if we should've stopped
const message = chatResponse.getMessages()[0]
const pad = 10 // look back 10 characters + stop sequence
if (message) {
const mc = (message.content).trim()
for (let i = 0, l = stopSequences.length; i < l; i++) {
const ss = stopSequences[i].trim()
const ind = mc.slice(0 - (ss.length + pad)).indexOf(ss)
if (ind > -1) {
const offset = (ss.length + pad) - ind
message.content = mc.slice(0, mc.length - offset)
response.stop = true
updateMessages(chat.id)
chatResponse.finish()
ws.close()
}
}
}
}
} }
} }
ws.onclose = () => { ws.onclose = () => {

View File

@ -110,6 +110,7 @@ const defaults:ChatSettings = {
hppWithSummaryPrompt: false, hppWithSummaryPrompt: false,
imageGenerationSize: '', imageGenerationSize: '',
stopSequence: '', stopSequence: '',
aggressiveStop: false,
userMessageStart: '', userMessageStart: '',
assistantMessageStart: '', assistantMessageStart: '',
systemMessageStart: '', systemMessageStart: '',
@ -524,6 +525,13 @@ const chatSettingsList: ChatSetting[] = [
}, },
hide: isNotPetals hide: isNotPetals
}, },
{
key: 'aggressiveStop',
name: 'Use aggressive stop',
title: 'Sometimes generation con continue even after a stop sequence. This will stop generation client side if generation continues after stop sequence.',
type: 'boolean',
hide: isNotPetals
},
{ {
key: 'userMessageStart', key: 'userMessageStart',
name: 'User Message Start Sequence', name: 'User Message Start Sequence',

View File

@ -114,6 +114,7 @@ export type ChatSettings = {
useResponseAlteration?: boolean; useResponseAlteration?: boolean;
responseAlterations?: ResponseAlteration[]; responseAlterations?: ResponseAlteration[];
stopSequence: string; stopSequence: string;
aggressiveStop: boolean;
userMessageStart: string; userMessageStart: string;
assistantMessageStart: string; assistantMessageStart: string;
systemMessageStart: string; systemMessageStart: string;