@adminforth/text-complete 1.1.2 → 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/dist/index.js CHANGED
@@ -91,9 +91,26 @@ export default class TextCompletePlugin extends AdminForthPlugin {
91
91
  "Don't talk to me. Just write text. No quotes. Don't repeat current field value, just write completion\n";
92
92
  }
93
93
  else {
94
- content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
95
- (Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
96
- "Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
94
+ if (this.options.initialPrompt) {
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` +
107
+ "No quotes. Don't talk to me. Just write text\n";
108
+ }
109
+ else {
110
+ content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
111
+ (Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
112
+ "Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
113
+ }
97
114
  }
98
115
  process.env.HEAVY_DEBUG && console.log('🪲 OpenAI Prompt 🧠', content);
99
116
  const { content: respContent, finishReason } = yield this.options.adapter.complete(content, (_l = this.options.expert) === null || _l === void 0 ? void 0 : _l.stop, (_m = this.options.expert) === null || _m === void 0 ? void 0 : _m.maxTokens);
package/index.ts CHANGED
@@ -119,9 +119,28 @@ export default class TextCompletePlugin extends AdminForthPlugin {
119
119
  "Don't talk to me. Just write text. No quotes. Don't repeat current field value, just write completion\n";
120
120
 
121
121
  } else {
122
- content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
123
- (Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
124
- "Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
122
+
123
+ 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
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` +
138
+ "No quotes. Don't talk to me. Just write text\n";
139
+ } else {
140
+ content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
141
+ (Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
142
+ "Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
143
+ }
125
144
  }
126
145
 
127
146
  process.env.HEAVY_DEBUG && console.log('🪲 OpenAI Prompt 🧠', content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/text-complete",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "Text completion plugin for adminforth",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/types.ts CHANGED
@@ -6,6 +6,16 @@ export interface PluginOptions {
6
6
  */
7
7
  fieldName: string;
8
8
 
9
+
10
+ /**
11
+ * Initial prompt request when field is empty. Mustache syntax for record context fields is supported.
12
+ * E.g.
13
+ * 'I need to introduce "{{ name }}" technology to my software development company website, I need short but very attractive description if it.'
14
+ *
15
+ * Where `name` is a field name which contains technology name e.g. Vue.js
16
+ */
17
+ initialPrompt?: string;
18
+
9
19
  /**
10
20
  * Expert settings
11
21
  */
@@ -21,6 +31,7 @@ export interface PluginOptions {
21
31
  */
22
32
  debounceTime?: number;
23
33
 
34
+
24
35
  /**
25
36
  * When completion is made, this plugin passes non-empty fields of the record to the LLM model for record context understanding.
26
37
  */