Skip to content

Commit 1efdc19

Browse files
committed
feat: add docs for the bulk-ai-flow
1 parent 58b943e commit 1efdc19

File tree

5 files changed

+142
-1
lines changed

5 files changed

+142
-1
lines changed

adminforth/documentation/docs/tutorial/07-Plugins/05-upload.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ new UploadPlugin({
301301
`aparts/${new Date().getFullYear()}/${uuid()}-${originalFilename}.${originalExtension}`,
302302
})
303303
```
304-
> adminServeBaseUrl defines the public path prefix. If your AdminForth base URL is /admin, files will be accessible under /admin/static/source/<key>.
304+
> adminServeBaseUrl defines the public path prefix. If your AdminForth base URL is /admin, files will be accessible under /admin/static/source/&lt;key&gt;.
305305
306306
307307
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Bulk AI Flow
2+
This plugin allows filling fields in records based on data from other fields using AI.
3+
4+
## Installation
5+
6+
To install the plugin:
7+
8+
```bash
9+
npm install @adminforth/bulk-ai-flow --save
10+
```
11+
12+
You'll also need an image vision adapter:
13+
14+
```bash
15+
npm install @adminforth/image-vision-adapter-openai --save
16+
```
17+
18+
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+
22+
```ts title="./schema.prisma"
23+
model apartments {
24+
id String @id
25+
created_at DateTime?
26+
title String
27+
square_meter Float?
28+
price Decimal
29+
number_of_rooms Int?
30+
description String?
31+
country String?
32+
listed Boolean
33+
realtor_id String?
34+
//diff-add
35+
image_url String?
36+
}
37+
```
38+
39+
Migrate prisma schema:
40+
41+
```bash
42+
npm run makemigration -- --name add-apartment-image-url ; npm run migrate:local
43+
```
44+
45+
Add credentials in your `.env.local` file:
46+
```ts title=".env"
47+
...
48+
49+
//diff-add
50+
OPENAI_API_KEY=your_secret_openai_key
51+
52+
...
53+
```
54+
55+
56+
Add column to `aparts` resource configuration:
57+
58+
```ts title="./resources/apartments.ts"
59+
//diff-add
60+
import BulkAiFlowPlugin from '@adminforth/bulk-ai-flow';
61+
//diff-add
62+
import AdminForthImageVisionAdapterOpenAi from '@adminforth/image-vision-adapter-openai';
63+
64+
export const admin = new AdminForth({
65+
...
66+
resourceId: 'aparts',
67+
columns: [
68+
...
69+
//diff-add
70+
{
71+
//diff-add
72+
name: 'image_url',
73+
//diff-add
74+
label: 'Image',
75+
//diff-add
76+
showIn: { list: false, create: true, edit: true},
77+
//diff-add
78+
}
79+
...
80+
],
81+
plugins: [
82+
...
83+
//diff-add
84+
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+
],
125+
126+
127+
...
128+
129+
});
130+
```
131+
132+
## Usage
133+
1. Select fields you want to fill
134+
2. Click on the three dots menu
135+
3. Click analyze
136+
![alt text](Bulk-vision-1.png)
137+
4. Wait for finish analyze
138+
5. Check and edit result
139+
![alt text](Bulk-vision-2.png)
140+
6. Save changhes
141+
![alt text](Bulk-vision-3.png)
87.6 KB
Loading
225 KB
Loading
62.7 KB
Loading

0 commit comments

Comments
 (0)