Skip to content

Commit 3934be8

Browse files
committed
docs: enhance Bulk AI Flow documentation and update plugin integration for image handling
1 parent 1efdc19 commit 3934be8

File tree

1 file changed

+85
-45
lines changed

1 file changed

+85
-45
lines changed

adminforth/documentation/docs/tutorial/07-Plugins/17-bulk-ai-flow.md

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Bulk AI Flow
2-
This plugin allows filling fields in records based on data from other fields using AI.
2+
3+
This plugin allows filling fields in multiple selected records based on data from other fields using LLM.
4+
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.
35

46
## Installation
57

@@ -16,8 +18,16 @@ npm install @adminforth/image-vision-adapter-openai --save
1618
```
1719

1820

19-
## Setup
20-
Add a column for storing the URL or path to the image in the database, add this statement to the `./schema.prisma`:
21+
## Vision mode
22+
23+
This mode covers next generations:
24+
25+
```
26+
- Image(one or many fields) -> to -> Text/Number/Enum/Boolean(one or many fields)
27+
- Image(one or many fields) + Text/Number/Enum/Boolean(one or many fields) -> to -> Text/Number/Enum/Boolean(one or many fields)
28+
```
29+
30+
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`:
2131

2232
```ts title="./schema.prisma"
2333
model apartments {
@@ -32,7 +42,7 @@ model apartments {
3242
listed Boolean
3343
realtor_id String?
3444
//diff-add
35-
image_url String?
45+
apartment_image String?
3646
}
3747
```
3848
@@ -42,6 +52,9 @@ Migrate prisma schema:
4252
npm run makemigration -- --name add-apartment-image-url ; npm run migrate:local
4353
```
4454
55+
We will also attach [upload plugin](/docs/tutorial/Plugins/upload/) to this field.
56+
57+
4558
Add credentials in your `.env.local` file:
4659
```ts title=".env"
4760
...
@@ -69,7 +82,7 @@ export const admin = new AdminForth({
6982
//diff-add
7083
{
7184
//diff-add
72-
name: 'image_url',
85+
name: 'apartment_image',
7386
//diff-add
7487
label: 'Image',
7588
//diff-add
@@ -82,46 +95,73 @@ export const admin = new AdminForth({
8295
...
8396
//diff-add
8497
plugins: [
85-
//diff-add
86-
new BulkAiFlowPlugin({
87-
//diff-add
88-
actionName: 'Analyze',
89-
//diff-add
90-
attachFiles: async ({ record }: { record: any }) => {
91-
//diff-add
92-
return [record.image_url];
93-
//diff-add
94-
},
95-
//diff-add
96-
adapter: new AdminForthImageVisionAdapterOpenAi(
97-
//diff-add
98-
{
99-
//diff-add
100-
openAiApiKey: process.env.OPENAI_API_KEY as string,
101-
//diff-add
102-
model: 'gpt-4.1-mini',
103-
//diff-add
104-
}
105-
//diff-add
106-
),
107-
//diff-add
108-
outputFields: [{
109-
//diff-add
110-
'description': 'describe what is in the image, also include fact that price is {{price}}',
111-
//diff-add
112-
'country': 'In which country it can be located?',
113-
//diff-add
114-
'number_of_rooms': 'How many rooms are in the apartment? If you do not know, just guess',
115-
//diff-add
116-
'square_meter': 'What is the square of the apartment in square meters? If you do not know, just guess',
117-
//diff-add
118-
'listed': 'Is the apartment should be listed for sale? If you do not know, just guess, return boolean value',
119-
//diff-add
120-
}],
121-
//diff-add
122-
}),
123-
//diff-add
124-
],
98+
//diff-add
99+
new UploadPlugin({
100+
//diff-add
101+
storageAdapter: new AdminForthAdapterS3Storage({
102+
//diff-add
103+
bucket: process.env.AWS_BUCKET_NAME,
104+
//diff-add
105+
region: process.env.AWS_REGION,
106+
//diff-add
107+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
108+
//diff-add
109+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
110+
//diff-add
111+
s3ACL: 'public-read',
112+
//diff-add
113+
}),
114+
//diff-add
115+
pathColumnName: 'apartment_image',
116+
//diff-add
117+
allowedFileExtensions: ['jpg', 'jpeg', 'png', 'gif', 'webm', 'webp'],
118+
//diff-add
119+
filePath: ({originalFilename, originalExtension, contentType}) =>
120+
//diff-add
121+
`aparts/${new Date().getFullYear()}/${uuid()}-${originalFilename}.${originalExtension}`,
122+
//diff-add
123+
}),
124+
125+
//diff-add
126+
new BulkAiFlowPlugin({
127+
//diff-add
128+
actionName: 'Analyze',
129+
//diff-add
130+
attachFiles: async ({ record }: { record: any }) => {
131+
//diff-add
132+
return [`https://tmpbucket-adminforth.s3.eu-central-1.amazonaws.com/${record.apartment_image}`];
133+
//diff-add
134+
},
135+
//diff-add
136+
adapter: new AdminForthImageVisionAdapterOpenAi(
137+
//diff-add
138+
{
139+
//diff-add
140+
openAiApiKey: process.env.OPENAI_API_KEY as string,
141+
//diff-add
142+
model: 'gpt-4.1-mini',
143+
//diff-add
144+
}
145+
//diff-add
146+
),
147+
//diff-add
148+
outputFields: [{
149+
//diff-add
150+
'description': 'describe what is in the image, also take into account that price is {{price}}',
151+
//diff-add
152+
'country': 'In which country it can be located?',
153+
//diff-add
154+
'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',
155+
//diff-add
156+
'square_meter': 'Try to guess what is the typical square of the apartment in square meters? If you do not know, just guess',
157+
//diff-add
158+
'listed': 'Is the apartment should be listed for sale? If you do not know, just guess, return boolean value',
159+
//diff-add
160+
}],
161+
//diff-add
162+
}),
163+
//diff-add
164+
],
125165

126166

127167
...

0 commit comments

Comments
 (0)