Skip to content

Commit

Permalink
Update prompt format using template
Browse files Browse the repository at this point in the history
Signed-off-by: Bohan Cheng <[email protected]>
  • Loading branch information
cbh778899 authored Aug 15, 2024
1 parent e1b3de2 commit 1991bbc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/formatContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ process.env.SYSTEM_INSTRUCTION && process.env.SYSTEM_INSTRUCTION !== '*' ? proce
"A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions."

export function formatInferenceContext(history, question = null, system_included = false) {
let context = system_included ? "" : "<|system|>\n"+system_context+"\n";
let context = system_included ? "" : "<|system|>\n"+system_context+"<|end|>\n";
context += history.map(({role, content}) => {
return `<|${role}|>\n${content || ''}`
return `<|${role}|>\n${content || ''}<|end|>`
}).join('\n');
if(question) context += `\n<|user|>\n${question}`
if(question) context += `\n<|user|>\n${question}<|end|>`
context += "\n<|assistant|>\n";
return context;
}

export function formatOpenAIContext(messages) {
return formatInferenceContext(messages, null, true);
}
}

0 comments on commit 1991bbc

Please sign in to comment.