@adminforth/text-complete 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.log +1 -1
- package/dist/index.js +12 -1
- package/index.ts +14 -1
- package/package.json +1 -1
package/build.log
CHANGED
package/dist/index.js
CHANGED
|
@@ -92,7 +92,18 @@ export default class TextCompletePlugin extends AdminForthPlugin {
|
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
94
|
if (this.options.initialPrompt) {
|
|
95
|
-
|
|
95
|
+
// initial prompt might have mustache syntax for current record value (several fields)
|
|
96
|
+
// use regex to replace it with current record value
|
|
97
|
+
const regex = /{{([^}]+)}}/g;
|
|
98
|
+
const interpretedPrompt = this.options.initialPrompt.replace(regex, (match, p1) => {
|
|
99
|
+
const fieldName = p1.trim();
|
|
100
|
+
const fieldValue = record[fieldName];
|
|
101
|
+
if (fieldValue) {
|
|
102
|
+
return fieldValue;
|
|
103
|
+
}
|
|
104
|
+
return match;
|
|
105
|
+
});
|
|
106
|
+
content = `${interpretedPrompt}\n` +
|
|
96
107
|
"No quotes. Don't talk to me. Just write text\n";
|
|
97
108
|
}
|
|
98
109
|
else {
|
package/index.ts
CHANGED
|
@@ -121,7 +121,20 @@ export default class TextCompletePlugin extends AdminForthPlugin {
|
|
|
121
121
|
} else {
|
|
122
122
|
|
|
123
123
|
if (this.options.initialPrompt) {
|
|
124
|
-
|
|
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` +
|