Skip to content

Commit 5766ea9

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth-bulk-ai-flow
2 parents f3f7822 + 04a148e commit 5766ea9

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

custom/VisionTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<Input
7474
type="number"
7575
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
76-
class="w-full "
76+
class="w-full min-w-[80px]"
7777
:fullWidth="true"
7878
/>
7979
</div>

index.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
289289
Do NOT return array of objects. Do NOT include any Markdown, code blocks, explanations, or extra text. Only return valid JSON.
290290
Each object must contain the following fields: ${JSON.stringify(compiledOutputFields)} Use the exact field names.
291291
If it's number field - return only number.`;
292-
const { content: chatResponse } = await this.options.textCompleteAdapter.complete(prompt, [], 500);
292+
//send prompt to OpenAI and get response
293+
const numberOfTokens = this.options.fillPlainFieldsMaxTokens ? this.options.fillPlainFieldsMaxTokens : 1000;
294+
const { content: chatResponse } = await this.options.textCompleteAdapter.complete(prompt, [], numberOfTokens);
295+
293296
const resp: any = (chatResponse as any).response;
294297
const topLevelError = (chatResponse as any).error;
295298
if (topLevelError || resp?.error) {
@@ -382,6 +385,35 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
382385
}
383386
}
384387
}
388+
try {
389+
const AuditLogPlugin = this.adminforth.getPluginByClassName('AuditLogPlugin');
390+
if (AuditLogPlugin) {
391+
392+
for (const [key, value] of Object.entries(oldRecord)) {
393+
if (!(key in fieldsToUpdate[idx])) {
394+
delete oldRecord[key];
395+
}
396+
}
397+
398+
const reorderedOldRecord = Object.keys(fieldsToUpdate[idx]).reduce((acc, key) => {
399+
if (key in oldRecord) {
400+
acc[key] = oldRecord[key];
401+
}
402+
return acc;
403+
}, {} as Record<string, unknown>);
404+
405+
AuditLogPlugin.logCustomAction({
406+
resourceId: this.resourceConfig.resourceId,
407+
recordId: ID,
408+
actionId: 'Bulk-ai-flow',
409+
oldData: reorderedOldRecord,
410+
data: fieldsToUpdate[idx],
411+
user: adminUser,
412+
headers: headers
413+
});
414+
}
415+
} catch (error) { }
416+
385417
return this.adminforth.resource(this.resourceConfig.resourceId).update(ID, fieldsToUpdate[idx])
386418
});
387419
await Promise.all(updates);

types.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
1-
import { ImageVisionAdapter, AdminUser, IAdminForth, StorageAdapter, ImageGenerationAdapter, CompletionAdapter } from "adminforth";
1+
import { ImageVisionAdapter, ImageGenerationAdapter, CompletionAdapter } from "adminforth";
22

33

44
export interface PluginOptions {
5+
/**
6+
* Name of the action in three dots menu.
7+
*/
58
actionName: string,
9+
10+
/**
11+
* The adapter to use for scaning images and filling fields basing on the image content.
12+
*/
613
visionAdapter?: ImageVisionAdapter,
14+
15+
/**
16+
* The adapter to use for text->text generation.
17+
*/
718
textCompleteAdapter?: CompletionAdapter,
19+
820
/**
921
* The adapter to use for image generation.
1022
*/
1123
imageGenerationAdapter?: ImageGenerationAdapter,
24+
25+
/**
26+
* List of fields that should be filled based on the image content analysis.
27+
*/
1228
fillFieldsFromImages?: Record<string, string>, // can analyze what is on image and fill fields, typical tasks "find dominant color", "describe what is on image", "clasify to one enum item, e.g. what is on image dog/cat/plant"
29+
30+
/**
31+
* List of fields that should be filled based on the text.
32+
*/
1333
fillPlainFields?: Record<string, string>,
34+
35+
/**
36+
* Number of tokens to generate (Only for text completion adapter). Default is 1000. 1 token ~= ¾ words
37+
*/
38+
fillPlainFieldsMaxTokens?: number,
39+
40+
/**
41+
* If you want to generate fields or images based on the image content attached images
42+
*/
1443
attachFiles?: ({ record }: {
1544
record: any,
1645
}) => string[] | Promise<string[]>,
1746

47+
/**
48+
* List of image fields, that should be filled.
49+
*/
1850
generateImages?: Record<
1951
string, {
2052
// can generate from images or just from another fields, e.g. "remove text from images", "improve image quality", "turn image into ghibli style"
@@ -43,6 +75,10 @@ export interface PluginOptions {
4375
*/
4476
countToGenerate: number,
4577
}>,
78+
79+
/**
80+
* Rate limits for each action.
81+
*/
4682
rateLimits?: {
4783
fillFieldsFromImages?: string, // e.g. 5/1d - 5 requests per day
4884
fillPlainFields?: string,

0 commit comments

Comments
 (0)