Skip to content

Commit 54a0c8d

Browse files
committed
Akeneo and LLMWhisperer apps
1 parent 3d6ce07 commit 54a0c8d

File tree

4 files changed

+29
-55
lines changed

4 files changed

+29
-55
lines changed

components/akeneo/actions/create-a-new-product-media-file/create-a-new-product-media-file.mjs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import app from "../../akeneo.app.mjs";
2-
import utils from "../../common/utils.mjs";
3-
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
ConfigurationError, getFileStream,
4+
} from "@pipedream/platform";
45
import FormData from "form-data";
5-
import fs from "fs";
66

77
export default {
88
type: "action",
99
key: "akeneo-create-a-new-product-media-file",
10-
version: "0.0.1",
10+
version: "0.1.0",
1111
name: "Create A New Product Media File",
1212
description: "Allows you to create a new media file and associate it to an attribute value of a given product or product model. [See the docs](https://api.akeneo.com/api-reference.html#post_media_files)",
1313
props: {
@@ -32,18 +32,15 @@ export default {
3232
},
3333
filename: {
3434
type: "string",
35-
label: "File",
36-
description: "The file to be uploaded, please provide a file from `/tmp`. To upload a file to `/tmp` folder, please follow the doc [here](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
35+
label: "File Path or URL",
36+
description: "The file to be uploaded. Provide either the path to a file in the `/tmp` directory (e.g. `/tmp/myFile.ext`) or a file URL. [See the documentation on working with files](https://pipedream.com/docs/workflows/building-workflows/code/nodejs/working-with-files/)",
3737
},
3838
},
3939
async run ({ $ }) {
4040
if (!this.productId && !this.productModelCode) {
4141
throw new ConfigurationError("Either `Product Identifier` or `Product Model Code` should be set!");
4242
}
43-
const path = utils.checkTmp(this.filename);
44-
if (!fs.existsSync(path)) {
45-
throw new ConfigurationError("File does not exist!");
46-
}
43+
4744
const payload = {
4845
attribute: this.mediaFileAttributeCode,
4946
scope: null,
@@ -57,9 +54,10 @@ export default {
5754
payload.code = this.productModelCode;
5855
data.append("product_model", JSON.stringify(payload));
5956
}
60-
const file = fs.readFileSync(path);
61-
const fileParts = path.split("/");
62-
data.append("file", file, fileParts[fileParts.length - 1]);
57+
58+
const fileStream = await getFileStream(this.filename);
59+
const fileParts = this.filename.split("/");
60+
data.append("file", fileStream, fileParts[fileParts.length - 1]);
6361
const contentLength = data.getLengthSync();
6462
await this.app.createProductMediaFile({
6563
$,

components/akeneo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/akeneo",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Akeneo Components",
55
"main": "akeneo.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/akeneo",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^1.3.0",
13+
"@pipedream/platform": "^3.0.1",
1414
"form-data": "^4.0.0"
1515
},
1616
"publishConfig": {

components/llmwhisperer/actions/extract-text/extract-text.mjs

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import fs from "fs";
1+
import { getFileStream } from "@pipedream/platform";
22
import app from "../../llmwhisperer.app.mjs";
33

44
export default {
55
key: "llmwhisperer-extract-text",
66
name: "Extract Text",
77
description: "Convert your PDF/scanned documents to text format which can be used by LLMs. [See the documentation](https://docs.unstract.com/llm_whisperer/apis/llm_whisperer_text_extraction_api)",
8-
version: "0.0.1",
8+
version: "0.1.0",
99
type: "action",
1010
props: {
1111
app,
@@ -91,40 +91,18 @@ export default {
9191
description: "Factor by which a horizontal stretch has to applied. It defaults to `1.0`. A stretch factor of `1.1` would mean at 10% stretch factor applied. Normally this factor need not be adjusted. You might want to use this parameter when multi column layouts back into each other. For example in a two column layout, the two columns get merged into one.",
9292
optional: true,
9393
},
94-
urlInPost: {
95-
type: "boolean",
96-
label: "URL In Post",
97-
description: "If set to `true`, the headers will be set to `text/plain`. If set to `false`, the headers will be set to `application/octet-stream`.",
98-
reloadProps: true,
99-
default: true,
94+
data: {
95+
type: "string",
96+
label: "File Path or URL",
97+
description: "The document to process. Provide either the path to a file in the `/tmp` directory (e.g. `/tmp/myFile.ext`) or a file URL. [See the documentation on working with files](https://pipedream.com/docs/workflows/building-workflows/code/nodejs/working-with-files/)",
10098
},
10199
},
102-
additionalProps() {
103-
const { urlInPost } = this;
104-
return {
105-
data: {
106-
type: "string",
107-
label: urlInPost
108-
? "Document URL"
109-
: "Document Path",
110-
description: urlInPost
111-
? "The URL of the document to process."
112-
: "Document path of the file previously downloaded in Pipedream E.g. (`/tmp/my-file.txt`). [Download a file to the `/tmp` directory](https://pipedream.com/docs/code/nodejs/http-requests/#download-a-file-to-the-tmp-directory)",
113-
},
114-
};
115-
},
116100
methods: {
117-
getHeaders(urlInPost) {
118-
return {
119-
"Content-Type": urlInPost
120-
? "text/plain"
121-
: "application/octet-stream",
122-
};
123-
},
124-
getData(urlInPost, data) {
125-
return urlInPost
126-
? data
127-
: fs.readFileSync(data);
101+
getHeaders() {
102+
return "application/octet-stream";
103+
},
104+
async getData(data) {
105+
return getFileStream(data);
128106
},
129107
extractText(args = {}) {
130108
return this.app.post({
@@ -138,7 +116,6 @@ export default {
138116
extractText,
139117
getHeaders,
140118
getData,
141-
urlInPost,
142119
processingMode,
143120
outputMode,
144121
pageSeperator,
@@ -156,9 +133,9 @@ export default {
156133

157134
const response = await extractText({
158135
$,
159-
headers: getHeaders(urlInPost),
136+
headers: getHeaders(),
160137
params: {
161-
url_in_post: urlInPost,
138+
url_in_post: false,
162139
processing_mode: processingMode,
163140
output_mode: outputMode,
164141
page_seperator: pageSeperator,
@@ -172,7 +149,7 @@ export default {
172149
line_splitter_tolerance: lineSplitterTolerance,
173150
horizontal_stretch_factor: horizontalStretchFactor,
174151
},
175-
data: getData(urlInPost, data),
152+
data: await getData(data),
176153
});
177154

178155
$.export("$summary", "Successfully extracted text from document.");

components/llmwhisperer/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/llmwhisperer",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream LLMWhisperer Components",
55
"main": "llmwhisperer.app.mjs",
66
"keywords": [
@@ -13,7 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.0",
17-
"fs": "^0.0.1-security"
16+
"@pipedream/platform": "^3.1.0"
1817
}
1918
}

0 commit comments

Comments
 (0)