Skip to content

Commit 25e54b0

Browse files
authored
Merge pull request #3 from devforth/AdminForth/703
feat: use label prompt if exist
2 parents b4ad04c + a034f6e commit 25e54b0

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,18 @@ export default class TextCompletePlugin extends AdminForthPlugin {
108108
currentVal = currentVal.slice(-promptLimit);
109109
}
110110

111-
const resLabel = this.resourceConfig.label;
112-
111+
const fieldLabel = this.resourceConfig?.columns.find(c => c.name === this.options.fieldName)?.label || this.options.fieldName;
112+
const resLabel = this.resourceConfig!.label;
113+
113114
let content;
114-
115+
115116
if (currentVal) {
116-
content = `Continue writing for text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
117+
content = `Continue writing for text/string field "${fieldLabel}" in the table "${resLabel}"\n` +
117118
(Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
118119
`Current field value: ${currentVal}\n` +
119120
"Don't talk to me. Just write text. No quotes. Don't repeat current field value, just write completion\n";
120-
121121
} else {
122-
123122
if (this.options.initialPrompt) {
124-
// initial prompt might have mustache syntax for current record value (several fields)
125-
// use regex to replace it with current record value
126123
const regex = /{{([^}]+)}}/g;
127124
const interpretedPrompt = this.options.initialPrompt.replace(regex, (match, p1) => {
128125
const fieldName = p1.trim();
@@ -133,11 +130,10 @@ export default class TextCompletePlugin extends AdminForthPlugin {
133130
return match;
134131
});
135132

136-
137133
content = `${interpretedPrompt}\n` +
138134
"No quotes. Don't talk to me. Just write text\n";
139135
} else {
140-
content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
136+
content = `Fill text/string field "${fieldLabel}" in the table "${resLabel}"\n` +
141137
(Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
142138
"Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
143139
}

0 commit comments

Comments
 (0)