adds stop sequences for better UJB/group chat behavior on claude

This commit is contained in:
nai-degen 2023-05-29 13:06:17 -05:00
parent 304893e13d
commit f102f02a65
1 changed files with 16 additions and 3 deletions

View File

@ -111,15 +111,28 @@ function openaiToAnthropic(body: any, req: Request) {
// tokens (https://console.anthropic.com/docs/prompt-design#prompt-length)
// as the cutoff, minus a little bit for safety.
// For smaller prompts we use 1.2 because it's not as cucked as 1.3
// For smaller prompts we use 1.2 because it's not as annoying as 1.3
// For big prompts (v1, auto-selects the latest model) is all we can use.
const model = prompt.length > 25000 ? "claude-v1-100k" : "claude-v1.2";
let stops = rest.stop
? Array.isArray(rest.stop)
? rest.stop
: [rest.stop]
: [];
// Recommended by Anthropic
stops.push("\n\nHuman:");
// Helps with jailbreak prompts that send fake system messages and multi-bot
// chats that prefix bot messages with "System: Respond as <bot name>".
stops.push("\n\nSystem:");
// Remove duplicates
stops = [...new Set(stops)];
return {
...rest,
model,
prompt,
max_tokens_to_sample: rest.max_tokens,
stop_sequences: rest.stop,
stop_sequences: stops,
};
}