@adminforth/bulk-ai-flow 1.15.5 → 1.15.7
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 +9 -2
- package/index.ts +8 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -173,7 +173,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
173
173
|
const compiledOutputFields = yield this.compileOutputFieldsTemplatesNoImage(record, customPrompt);
|
|
174
174
|
const prompt = `Generate the values of fields in object by using next prompts (key is field name, value is prompt):
|
|
175
175
|
${JSON.stringify(compiledOutputFields)} In output object use the same field names (keys) as in input.
|
|
176
|
-
Return a single valid passable JSON object in format like: {
|
|
176
|
+
Return a single valid passable JSON object in format like: {"meta_title": "generated_value"}.
|
|
177
177
|
Do NOT include any Markdown, code blocks, explanations, or extra text. Only return valid JSON.`;
|
|
178
178
|
//send prompt to OpenAI and get response
|
|
179
179
|
const numberOfTokens = this.options.fillPlainFieldsMaxTokens ? this.options.fillPlainFieldsMaxTokens : 1000;
|
|
@@ -193,7 +193,14 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
193
193
|
jobs.set(jobId, { status: 'failed', error: 'AI provider refused to fill fields' });
|
|
194
194
|
return { ok: false, error: 'AI provider refused to fill fields' };
|
|
195
195
|
}
|
|
196
|
-
|
|
196
|
+
let resData;
|
|
197
|
+
try {
|
|
198
|
+
resData = JSON.parse(resp);
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
jobs.set(jobId, { status: 'failed', error: 'AI response is not valid JSON' });
|
|
202
|
+
return { ok: false, error: 'AI response is not valid JSON' };
|
|
203
|
+
}
|
|
197
204
|
const result = resData;
|
|
198
205
|
jobs.set(jobId, { status: 'completed', result });
|
|
199
206
|
return { ok: true };
|
package/index.ts
CHANGED
|
@@ -167,7 +167,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
167
167
|
const compiledOutputFields = await this.compileOutputFieldsTemplatesNoImage(record, customPrompt);
|
|
168
168
|
const prompt = `Generate the values of fields in object by using next prompts (key is field name, value is prompt):
|
|
169
169
|
${JSON.stringify(compiledOutputFields)} In output object use the same field names (keys) as in input.
|
|
170
|
-
Return a single valid passable JSON object in format like: {
|
|
170
|
+
Return a single valid passable JSON object in format like: {"meta_title": "generated_value"}.
|
|
171
171
|
Do NOT include any Markdown, code blocks, explanations, or extra text. Only return valid JSON.`;
|
|
172
172
|
//send prompt to OpenAI and get response
|
|
173
173
|
const numberOfTokens = this.options.fillPlainFieldsMaxTokens ? this.options.fillPlainFieldsMaxTokens : 1000;
|
|
@@ -186,7 +186,13 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
186
186
|
jobs.set(jobId, { status: 'failed', error: 'AI provider refused to fill fields' });
|
|
187
187
|
return { ok: false, error: 'AI provider refused to fill fields' };
|
|
188
188
|
}
|
|
189
|
-
|
|
189
|
+
let resData;
|
|
190
|
+
try {
|
|
191
|
+
resData = JSON.parse(resp);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
jobs.set(jobId, { status: 'failed', error: 'AI response is not valid JSON' });
|
|
194
|
+
return { ok: false, error: 'AI response is not valid JSON' };
|
|
195
|
+
}
|
|
190
196
|
const result = resData;
|
|
191
197
|
jobs.set(jobId, { status: 'completed', result });
|
|
192
198
|
return { ok: true };
|