Skip to content

Commit cc56e6f

Browse files
committed
feat(vlm-run): improve piece
1 parent 4c58472 commit cc56e6f

7 files changed

Lines changed: 56 additions & 7 deletions

File tree

packages/pieces/community/vlm-run/src/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,33 @@ import { analyzeImage } from './lib/actions/analyze-image';
55
import { analyzeVideo } from './lib/actions/analyze-video';
66
import { getFile } from './lib/actions/get-file';
77
import { vlmRunAuth } from './lib/common';
8+
import { createCustomApiCallAction } from '@activepieces/pieces-common';
9+
import { PieceCategory } from '@activepieces/shared';
810

911
export const vlmRun = createPiece({
1012
displayName: 'VLM Run',
1113
description:
1214
'VLM Run is a visual AI platform that extracts data from images, videos, audio, and documents. It helps automate analysis workflows, such as object detection, transcription, image/audio analysis, and document parsing.',
1315
auth: vlmRunAuth,
1416
minimumSupportedRelease: '0.36.1',
17+
categories: [PieceCategory.BUSINESS_INTELLIGENCE, PieceCategory.CONTENT_AND_FILES],
1518
logoUrl: 'https://cdn.activepieces.com/pieces/vlm-run.png',
16-
authors: ['LuizDMM'],
17-
actions: [analyzeAudio, analyzeImage, analyzeDocument, analyzeVideo, getFile],
19+
authors: ['LuizDMM', 'sanket-a11y'],
20+
actions: [
21+
analyzeAudio,
22+
analyzeImage,
23+
analyzeDocument,
24+
analyzeVideo,
25+
getFile,
26+
createCustomApiCallAction({
27+
auth: vlmRunAuth,
28+
baseUrl: () => 'https://api.vlm.run/v1',
29+
authMapping: async (auth) => {
30+
return {
31+
Authorization: `Bearer ${auth}`,
32+
};
33+
},
34+
}),
35+
],
1836
triggers: [],
1937
});

packages/pieces/community/vlm-run/src/lib/actions/analyze-audio.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ export const analyzeAudio = createAction({
1919
file: propsValue.audio,
2020
});
2121

22-
return await vlmRunCommon.analyzeAudio({
22+
const response = await vlmRunCommon.analyzeAudio({
2323
apiKey,
2424
file_id: uploadResponse.id,
2525
});
26+
27+
return await vlmRunCommon.getresponse(apiKey, response.id, response.status);
2628
},
2729
});

packages/pieces/community/vlm-run/src/lib/actions/analyze-document.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export const analyzeDocument = createAction({
2121
file: document,
2222
});
2323

24-
return await vlmRunCommon.analyzeDocument({
24+
const response = await vlmRunCommon.analyzeDocument({
2525
apiKey,
2626
file_id: uploadResponse.id,
2727
domain,
2828
});
29+
30+
return await vlmRunCommon.getresponse(apiKey, response.id, response.status);
2931
},
3032
});

packages/pieces/community/vlm-run/src/lib/actions/analyze-image.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export const analyzeImage = createAction({
1717
const { image, domain } = propsValue;
1818

1919

20-
return await vlmRunCommon.analyzeImage({
20+
const response = await vlmRunCommon.analyzeImage({
2121
apiKey,
2222
images: [image],
2323
domain,
2424
});
25+
26+
return await vlmRunCommon.getresponse(apiKey, response.id, response.status);
2527
},
2628
});

packages/pieces/community/vlm-run/src/lib/actions/analyze-video.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export const analyzeVideo = createAction({
2121
file: video,
2222
});
2323

24-
return await vlmRunCommon.analyzeVideo({
24+
const response = await vlmRunCommon.analyzeVideo({
2525
apiKey,
2626
file_id: uploadResponse.id,
2727
domain,
2828
});
29+
30+
return await vlmRunCommon.getresponse(apiKey, response.id, response.status);
2931
},
3032
});

packages/pieces/community/vlm-run/src/lib/common/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,33 @@ export const vlmRunCommon = {
3030
analyzeImage: '/image/generate',
3131
analyzeDocument: '/document/generate',
3232
analyzeVideo: '/video/generate',
33+
getresponse: '/predictions',
3334
getFile: (fileId: string) => `/files/${fileId}`,
3435
},
3536

3637
// Methods
38+
getresponse: async (apiKey: string, requestId: string, status: string) => {
39+
let statusnow = status;
40+
const timeoutAt = Date.now() + 5 * 60 * 1000;
41+
42+
while (statusnow !== 'completed' && Date.now() < timeoutAt) {
43+
await new Promise((resolve) => setTimeout(resolve, 5000));
44+
45+
const pollRes = await httpClient.sendRequest<any>({
46+
method: HttpMethod.GET,
47+
url: `${vlmRunCommon.baseUrl}${vlmRunCommon.endpoints.getresponse}/${requestId}`,
48+
headers: vlmRunCommon.baseHeaders(apiKey),
49+
});
50+
51+
statusnow = pollRes.body?.status;
52+
console.log('first', statusnow);
53+
if (statusnow === 'completed') {
54+
return pollRes.body.response;
55+
}
56+
}
57+
58+
throw new Error('generation timed out or failed.');
59+
},
3760
uploadFile: async ({ apiKey, file }: UploadFileParams) => {
3861
const formData = new FormData();
3962
formData.append('file', file.data, { filename: file.filename });

packages/pieces/community/vlm-run/src/lib/common/properties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { vlmRunCommon } from '.';
55
export const analyzeAudioProperties = {
66
audio: Property.File({
77
displayName: 'Audio File',
8-
description: 'The audio file to get the transcription from.',
8+
description: 'The audio file to get the transcription from. Only MP3 supported.',
99
required: true,
1010
}),
1111
};

0 commit comments

Comments
 (0)