File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,20 @@ export default class TextCompletePlugin extends AdminForthPlugin {
121
121
} else {
122
122
123
123
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` +
125
138
"No quotes. Don't talk to me. Just write text\n" ;
126
139
} else {
127
140
content = `Fill text/string field "${ this . options . fieldName } " in the table "${ resLabel } "\n` +
You can’t perform that action at this time.
0 commit comments