"...resnet50_tensorflow.git" did not exist on "4bb13e61632ad108f733f8cade829e9b3cce9c7f"
Commit 3a2f1d56 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

fix: promptTemplate infinite loop

parent a341cfe3
...@@ -472,29 +472,18 @@ export const blobToFile = (blob, fileName) => { ...@@ -472,29 +472,18 @@ export const blobToFile = (blob, fileName) => {
return file; return file;
}; };
// promptTemplate replaces any occurrences of the following in the template with the prompt
// {{prompt}} will be replaced with the prompt
// {{prompt:start:<length>}} will be replaced with the first <length> characters of the prompt
// {{prompt:end:<length>}} will be replaced with the last <length> characters of the prompt
// Character length is used as we don't have the ability to tokenize the prompt
export const promptTemplate = (template: string, prompt: string) => { export const promptTemplate = (template: string, prompt: string) => {
template = template.replace(/{{prompt}}/g, prompt); template = template.replace(/{{prompt}}/g, prompt);
// Replace all instances of {{prompt:start:<length>}} with the first <length> characters of the prompt // Replace all instances of {{prompt:start:<length>}} with the first <length> characters of the prompt
const startRegex = /{{prompt:start:(\d+)}}/g; template = template.replace(/{{prompt:start:(\d+)}}/g, (match, length) =>
let startMatch: RegExpMatchArray | null; prompt.substring(0, parseInt(length))
while ((startMatch = startRegex.exec(template)) !== null) { );
const length = parseInt(startMatch[1]);
template = template.replace(startMatch[0], prompt.substring(0, length));
}
// Replace all instances of {{prompt:end:<length>}} with the last <length> characters of the prompt // Replace all instances of {{prompt:end:<length>}} with the last <length> characters of the prompt
const endRegex = /{{prompt:end:(\d+)}}/g; template = template.replace(/{{prompt:end:(\d+)}}/g, (match, length) =>
let endMatch: RegExpMatchArray | null; prompt.slice(-parseInt(length))
while ((endMatch = endRegex.exec(template)) !== null) { );
const length = parseInt(endMatch[1]);
template = template.replace(endMatch[0], prompt.substring(prompt.length - length));
}
return template; return template;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment