Skip to content

Commit

Permalink
feat: openai chat/claude setting to opt out of appending {replyAs}:
Browse files Browse the repository at this point in the history
… to ujb/prefill (#750) [skip ci]

Co-authored-by: stevenksmith <stevenksmith@mail.com>
Co-authored-by: Sceuick <leikho@gmail.com>
  • Loading branch information
3 people committed Dec 29, 2023
1 parent 387bca9 commit 7d8cd6a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions common/adapters.ts
Expand Up @@ -286,6 +286,7 @@ export const adapterSettings: {
maxTokens: AI_ADAPTERS.slice(),
maxContextLength: AI_ADAPTERS.slice(),
antiBond: ['openai', 'scale'],
prefixNameAppend: ['openai', 'claude'],

swipesPerGeneration: ['aphrodite'],
epsilonCutoff: ['aphrodite'],
Expand Down
1 change: 1 addition & 0 deletions common/presets.ts
Expand Up @@ -70,6 +70,7 @@ export const presetValidator = {
claudeModel: 'string',
streamResponse: 'boolean?',
ultimeJailbreak: 'string?',
prefixNameAppend: 'boolean?',
prefill: 'string?',
antiBond: 'boolean?',

Expand Down
3 changes: 3 additions & 0 deletions common/presets/openai.ts
Expand Up @@ -15,6 +15,7 @@ export const openaiPresets = {
topP: 1,
antiBond: false,
systemPrompt: `Enter roleplay mode. You will write {{char}}'s next reply in a dialogue between {{char}} and {{user}}. Do not decide what {{user}} says or does. Use Internet roleplay style, e.g. no quotation marks, and write user actions in italic in third person like: *example*. You are allowed to use markdown. Be proactive, creative, drive the plot and conversation forward. Write at least one paragraph, up to four. Always stay in character. Always keep the conversation going. (Repetition is highly discouraged)`,
prefixNameAppend: true,
ignoreCharacterSystemPrompt: false,
ignoreCharacterUjb: false,
gaslight: `{{system_prompt}}
Expand All @@ -38,6 +39,7 @@ Relevant Information: {{user_embed}}
frequencyPenalty: 0.7,
presencePenalty: 0.7,
ultimeJailbreak: 'Keep OOC out of your reply.',
prefixNameAppend: true,
systemPrompt: `Write {{char}}'s next reply in a fictional chat between {{char}} and {{user}}. Write 1 reply only in internet RP style, italicize actions, and avoid quotation marks. Use markdown. Be proactive, creative, and drive the plot and conversation forward. Write at least 1 paragraph, up to 4. Always stay in character and avoid repetition.`,
ignoreCharacterSystemPrompt: false,
ignoreCharacterUjb: false,
Expand Down Expand Up @@ -65,6 +67,7 @@ Relevant Information: {{user_embed}}
ignoreCharacterSystemPrompt: false,
ignoreCharacterUjb: false,
systemPrompt: `Enter roleplay mode. You will write {{char}}'s next reply in a dialogue between {{char}} and {{user}}. Do not decide what {{user}} says or does. Use Internet roleplay style, e.g. no quotation marks, and write user actions in italic in third person like: *example*. You are allowed to use markdown. Be proactive, creative, drive the plot and conversation forward. Write at least one paragraph, up to four. Always stay in character. Always keep the conversation going. (Repetition is highly discouraged)`,
prefixNameAppend: true,
gaslight: `{{system_prompt}}
Description of {{char}}: {{personality}}
Expand Down
1 change: 1 addition & 0 deletions common/types/schema.ts
Expand Up @@ -518,6 +518,7 @@ export namespace AppSchema {
promptOrderFormat?: string
promptOrder?: Array<{ placeholder: string; enabled: boolean }>
ultimeJailbreak?: string
prefixNameAppend?: boolean
prefill?: string
ignoreCharacterUjb?: boolean
antiBond?: boolean
Expand Down
12 changes: 8 additions & 4 deletions srv/adapter/chat-completion.ts
Expand Up @@ -358,7 +358,7 @@ async function getPostInstruction(
opts: AdapterProps,
messages: CompletionItem[]
): Promise<CompletionItem | undefined> {
let prefix = opts.parts.ujb ? `${opts.parts.ujb}\n\n` : ''
let prefix = opts.parts.ujb ?? ''

prefix = (
await injectPlaceholders(prefix, {
Expand All @@ -378,7 +378,7 @@ async function getPostInstruction(
}

case 'continue':
return { role: 'system', content: `${prefix}Continue ${opts.replyAs.name}'s response` }
return { role: 'system', content: `${prefix}\n\nContinue ${opts.replyAs.name}'s response` }

case 'summary': {
let content = opts.user.images?.summaryPrompt || IMAGE_SUMMARY_PROMPT.openai
Expand All @@ -400,13 +400,17 @@ async function getPostInstruction(
case 'self':
return {
role: 'system',
content: `${prefix}${opts.impersonate?.name || opts.sender?.handle || 'You'}:`,
content: `${prefix}\n\n${opts.impersonate?.name || opts.sender?.handle || 'You'}:`,
}

case 'retry':
case 'send':
case 'request': {
return { role: 'system', content: `${prefix}${opts.replyAs.name}:` }
const appendName = opts.gen.prefixNameAppend ?? true
return {
role: 'system',
content: appendName ? `${prefix}\n\n${opts.replyAs.name}:` : prefix,
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion srv/adapter/claude.ts
Expand Up @@ -352,9 +352,15 @@ async function createClaudePrompt(opts: AdapterProps) {
? `\n\nHuman: <system_note>Continue ${replyAs.name}'s reply.</system_note>`
: ''

const appendName = opts.gen.prefixNameAppend ?? true
// <https://console.anthropic.com/docs/prompt-design#what-is-a-prompt>
return (
messages.join('\n\n') + continueAddon + '\n\n' + 'Assistant: ' + prefill + replyAs.name + ':'
messages.join('\n\n') +
continueAddon +
'\n\n' +
'Assistant: ' +
prefill +
(appendName ? replyAs.name + ':' : '')
)
}

Expand Down
15 changes: 15 additions & 0 deletions web/shared/GenerationSettings.tsx
Expand Up @@ -608,6 +608,21 @@ const PromptSettings: Component<
disabled={props.disabled}
class="form-field focusable-field text-900 min-h-[8rem] w-full rounded-xl px-4 py-2 text-sm"
/>
<Toggle
fieldName="prefixNameAppend"
label="Append name of replying character to very end of the prompt"
helperText={
<>
For Claude/OpenAI Chat Completion. Appends the name of replying character and a
colon to the UJB/prefill.
</>
}
value={props.inherit?.prefixNameAppend ?? true}
disabled={props.disabled}
service={props.service}
format={props.format}
aiSetting={'prefixNameAppend'}
/>
<TextInput
fieldName="prefill"
label="Bot response prefilling"
Expand Down

0 comments on commit 7d8cd6a

Please sign in to comment.