Bulk AI Flow
This plugin allows filling fields in multiple selected records based on data from other fields using LLM. This also supports vision tasks so you can ask it to e.g. detect dominant color on image or describe what is on the image. Plugin supports classification to enum options automatically.
Installation
To install the plugin:
npm install @adminforth/bulk-ai-flow --save
You'll also need an image vision adapter:
npm install @adminforth/image-vision-adapter-openai --save
Vision mode
This mode covers next generations:
- Image(one or many fields) -> to -> Text/Number/Enum/Boolean(one or many fields)
- Image(one or many fields) + Text/Number/Enum/Boolean(one or many fields) -> to -> Text/Number/Enum/Boolean(one or many fields)
Lets try both. Add a column for storing the URL or path to the image in the database, add this statement to the ./schema.prisma
:
./schema.prisma
model apartments {
id String @id
created_at DateTime?
title String
square_meter Float?
price Decimal
number_of_rooms Int?
description String?
country String?
listed Boolean
realtor_id String?
apartment_image String?
}
Migrate prisma schema:
npm run makemigration -- --name add-apartment-image-url ; npm run migrate:local
We will also attach upload plugin to this field.
Add credentials in your .env
file:
.env
...
OPENAI_API_KEY=your_secret_openai_key
...
Add column to aparts
resource configuration:
./resources/apartments.ts
import BulkAiFlowPlugin from '@adminforth/bulk-ai-flow';
import AdminForthImageVisionAdapterOpenAi from '@adminforth/image-vision-adapter-openai';
export const admin = new AdminForth({
...
resourceId: 'aparts',
columns: [
...
{
name: 'apartment_image',
label: 'Image',
showIn: { list: false, create: true, edit: true},
}
...
],
plugins: [
...
new UploadPlugin({
storageAdapter: new AdminForthAdapterS3Storage({
bucket: process.env.AWS_BUCKET_NAME,
region: process.env.AWS_REGION,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
s3ACL: 'public-read',
}),
pathColumnName: 'apartment_image',
allowedFileExtensions: ['jpg', 'jpeg', 'png', 'gif', 'webm', 'webp'],
filePath: ({originalFilename, originalExtension, contentType}) =>
`aparts/${new Date().getFullYear()}/${uuid()}-${originalFilename}.${originalExtension}`,
}),
new BulkAiFlowPlugin({
actionName: 'Analyze',
attachFiles: async ({ record }: { record: any }) => {
return [`https://tmpbucket-adminforth.s3.eu-central-1.amazonaws.com/${record.apartment_image}`];
},
visionAdapter: new AdminForthImageVisionAdapterOpenAi(
{
openAiApiKey: process.env.OPENAI_API_KEY as string,
model: 'gpt-4.1-mini',
}
),
fillFieldsFromImages: {
'description': 'describe what is in the image, also take into account that price is {{price}}',
'country': 'In which country it can be located?',
'number_of_rooms': 'How many rooms are in the apartment? Just try to guess what is a typical one. If you do not know, just guess',
'square_meter': 'Try to guess what is the typical square of the apartment in square meters? If you do not know, just guess',
'listed': 'Is the apartment should be listed for sale? If you do not know, just guess, return boolean value',
},
}),
],
...
});
Usage
- Select fields you want to fill
- Click on the three dots menu
- Click analyze
- Wait for finish analyze
- Check and edit result
- Save changhes