renderPrompt should single pass substitute placeholders like GenAI.buildChatPrompt
Categories
(Core :: Machine Learning: General, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox162 | --- | fixed |
People
(Reporter: Mardak, Assigned: Mardak)
References
(Blocks 1 open bug)
Details
(Whiteboard: [aiasst])
Attachments
(1 external file)
renderPrompt in browser/components/aiwindow/models/Utils.sys.mjs fills each key with its own replace call over the result of the previous ones:
for (const [orig, repl] of Object.entries(stringsToReplace)) {
const regex = new RegExp(`{${orig}}`, "g");
finalPromptContent = finalPromptContent.replace(regex, () => repl);
}
So the output depends on key order: text that matches a later key placeholder inside an earlier value is replaced too. For example, generateConversationStartersSidebar fills current_tab before date, so a tab titled "Notes for {date}" reaches the model with today date in its title instead of the literal text.
GenAI.buildChatPrompt in browser/components/genai/GenAI.sys.mjs fills all placeholders in a single template.replace(regex, callback), so inserted values are never scanned again.
renderPrompt could do the same after handling {#key}...{/key} sections:
return finalPromptContent.replace(/\{(\w+)\}/g, (match, key) =>
Object.hasOwn(stringsToReplace, key) ? String(stringsToReplace[key]) : match
);
Output is unchanged except when a value contains another key placeholder. Unknown placeholders are still left as they are, and $ in values stays literal because the replacement is a callback. An xpcshell test where one value contains another key placeholder would cover it.
Updated•6 days ago
|
| Assignee | ||
Comment 1•6 days ago
|
||
use regex replace with callback instead of looping
Updated•6 days ago
|
Description
•