Skip to content

Commit 0902d86

Browse files
committed
fix: interpret the input in initialPrompt
1 parent e364984 commit 0902d86

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,20 @@ export default class TextCompletePlugin extends AdminForthPlugin {
121121
} else {
122122

123123
if (this.options.initialPrompt) {
124-
content = `${this.options.initialPrompt}\n` +
124+
// initial prompt might have mustache syntax for current record value (several fields)
125+
// use regex to replace it with current record value
126+
const regex = /{{([^}]+)}}/g;
127+
const interpretedPrompt = this.options.initialPrompt.replace(regex, (match, p1) => {
128+
const fieldName = p1.trim();
129+
const fieldValue = record[fieldName];
130+
if (fieldValue) {
131+
return fieldValue;
132+
}
133+
return match;
134+
});
135+
136+
137+
content = `${interpretedPrompt}\n` +
125138
"No quotes. Don't talk to me. Just write text\n";
126139
} else {
127140
content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +

0 commit comments

Comments
 (0)