Skip to content

Commit 5d5d955

Browse files
committed
[Components] ragie #15183
Sources - New Document - New Connection Actions - Create Document - Update Document File
1 parent a148f75 commit 5d5d955

File tree

13 files changed

+284
-589
lines changed

13 files changed

+284
-589
lines changed

components/ragie/actions/create-document/create-document.mjs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import FormData from "form-data";
2+
import fs from "fs";
3+
import { checkTmp } from "../../common/utils.mjs";
14
import ragie from "../../ragie.app.mjs";
2-
import { axios } from "@pipedream/platform";
35

46
export default {
57
key: "ragie-create-document",
68
name: "Create Document",
79
description: "Creates a new document in Ragie. [See the documentation](https://docs.ragie.ai/reference/createdocument)",
8-
version: "0.0.{{ts}}",
10+
version: "0.0.1",
911
type: "action",
1012
props: {
1113
ragie,
@@ -23,42 +25,44 @@ export default {
2325
optional: true,
2426
},
2527
metadata: {
26-
propDefinition: [
27-
ragie,
28-
"createDocumentMetadata",
29-
],
28+
type: "object",
29+
label: "Metadata",
30+
description: "Metadata for the document. Keys must be strings. Values may be strings, numbers, booleans, or lists of strings.",
3031
optional: true,
3132
},
3233
externalId: {
33-
propDefinition: [
34-
ragie,
35-
"createDocumentExternalId",
36-
],
34+
type: "string",
35+
label: "External ID",
36+
description: "An optional identifier for the document. A common value might be an ID in an external system or the URL where the source file may be found.",
3737
optional: true,
3838
},
3939
name: {
40-
propDefinition: [
41-
ragie,
42-
"createDocumentName",
43-
],
40+
type: "string",
41+
label: "Name",
42+
description: "An optional name for the document. If set, the document will have this name. Otherwise, it will default to the file's name.",
4443
optional: true,
4544
},
4645
partition: {
4746
propDefinition: [
4847
ragie,
49-
"createDocumentPartition",
48+
"partition",
5049
],
5150
optional: true,
5251
},
5352
},
5453
async run({ $ }) {
54+
const data = new FormData();
55+
data.append("file", fs.createReadStream(checkTmp(this.file)));
56+
if (this.mode) data.append("mode", this.mode);
57+
if (this.metadata) data.append("metadata", JSON.stringify(this.metadata));
58+
if (this.externalId) data.append("external_id", this.externalId);
59+
if (this.name) data.append("name", this.name);
60+
if (this.partition) data.append("partition", this.partition);
61+
5562
const response = await this.ragie.createDocument({
56-
createDocumentFile: this.file,
57-
createDocumentMode: this.mode,
58-
createDocumentMetadata: this.metadata,
59-
createDocumentExternalId: this.externalId,
60-
createDocumentName: this.name,
61-
createDocumentPartition: this.partition,
63+
$,
64+
data,
65+
headers: data.getHeaders(),
6266
});
6367

6468
$.export("$summary", `Created document: ${response.name} (ID: ${response.id})`);

components/ragie/actions/create-instruction/create-instruction.mjs

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1+
import FormData from "form-data";
2+
import fs from "fs";
3+
import { checkTmp } from "../../common/utils.mjs";
14
import ragie from "../../ragie.app.mjs";
2-
import { axios } from "@pipedream/platform";
35

46
export default {
57
key: "ragie-update-document-file",
68
name: "Update Document File",
7-
description: "Updates an existing document file in Ragie. [See the documentation]().",
8-
version: "0.0.{{ts}}",
9+
description: "Updates an existing document file in Ragie. [See the documentation](https://docs.ragie.ai/reference/updatedocumentfile).",
10+
version: "0.0.1",
911
type: "action",
1012
props: {
1113
ragie,
12-
updateDocumentId: {
14+
documentId: {
1315
propDefinition: [
1416
ragie,
15-
"updateDocumentId",
17+
"documentId",
1618
],
1719
},
18-
updateDocumentFile: {
20+
mode: {
1921
propDefinition: [
2022
ragie,
21-
"updateDocumentFile",
22-
],
23-
},
24-
updateDocumentMode: {
25-
propDefinition: [
26-
ragie,
27-
"updateDocumentMode",
23+
"createDocumentMode",
2824
],
2925
optional: true,
3026
},
31-
updateDocumentPartition: {
27+
file: {
3228
propDefinition: [
3329
ragie,
34-
"updateDocumentPartition",
30+
"createDocumentFile",
3531
],
36-
optional: true,
3732
},
3833
},
3934
async run({ $ }) {
35+
const data = new FormData();
36+
data.append("file", fs.createReadStream(checkTmp(this.file)));
37+
if (this.mode) data.append("mode", this.mode);
38+
4039
const response = await this.ragie.updateDocumentFile({
41-
updateDocumentId: this.updateDocumentId,
42-
updateDocumentFile: this.updateDocumentFile,
43-
updateDocumentMode: this.updateDocumentMode,
44-
updateDocumentPartition: this.updateDocumentPartition,
40+
$,
41+
documentId: this.documentId,
42+
data,
43+
headers: data.getHeaders(),
4544
});
46-
$.export("$summary", `Successfully updated document file with ID: ${this.updateDocumentId}`);
45+
$.export("$summary", `Successfully updated document file with ID: ${this.documentId}`);
4746
return response;
4847
},
4948
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const SCOPE_OPTIONS = [
2+
{
3+
label: "Document",
4+
value: "document",
5+
},
6+
{
7+
label: "Chunk",
8+
value: "chunk",
9+
},
10+
];
11+
12+
export const DOCUMENT_MODE_OPTIONS = [
13+
"hi_res",
14+
"fast",
15+
];

components/ragie/common/utils.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const checkTmp = (filename) => {
2+
if (!filename.startsWith("/tmp")) {
3+
return `/tmp/${filename}`;
4+
}
5+
return filename;
6+
};
7+
8+
export const parseObject = (obj) => {
9+
if (!obj) return undefined;
10+
11+
if (Array.isArray(obj)) {
12+
return obj.map((item) => {
13+
if (typeof item === "string") {
14+
try {
15+
return JSON.parse(item);
16+
} catch (e) {
17+
return item;
18+
}
19+
}
20+
return item;
21+
});
22+
}
23+
if (typeof obj === "string") {
24+
try {
25+
return JSON.parse(obj);
26+
} catch (e) {
27+
return obj;
28+
}
29+
}
30+
return obj;
31+
};

components/ragie/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/ragie",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Ragie Components",
55
"main": "ragie.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}

0 commit comments

Comments
 (0)