Skip to content

Commit 90369cb

Browse files
authored
Merge branch 'master' into issue-13863
2 parents e9312db + fec33ab commit 90369cb

File tree

6 files changed

+165
-8
lines changed

6 files changed

+165
-8
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import FormData from "form-data";
3+
import fs from "fs";
4+
import {
5+
checkTmp, parseObject,
6+
} from "../../common/utils.mjs";
7+
import gptzeroDetectAi from "../../gptzero_detect_ai.app.mjs";
8+
9+
export default {
10+
key: "gptzero_detect_ai-scan-file",
11+
name: "Scan File for AI Detection",
12+
description: "This endpoint takes in file(s) input and returns the model's result. [See the documentation](https://gptzero.stoplight.io/docs/gptzero-api/0a8e7efa751a6-ai-detection-on-an-array-of-files)",
13+
version: "0.0.1",
14+
type: "action",
15+
props: {
16+
gptzeroDetectAi,
17+
alert: {
18+
type: "alert",
19+
alertType: "info",
20+
content: `By default, the maximum number of files that can be submitted simultaneously is **50**.
21+
\nThe maximum file size for all files combined is **15 MB**.
22+
\nEach file's document will be truncated to **50,000** characters.`,
23+
},
24+
files: {
25+
type: "string[]",
26+
label: "Files",
27+
description: "A list of paths to files in the `/tmp` directory to analyze. Each file's document will be truncated to 50,000 characters. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).",
28+
},
29+
},
30+
async run({ $ }) {
31+
if (this.files.length > 50) {
32+
throw new ConfigurationError("The maximum number of files that can be submitted simultaneously is 50.");
33+
}
34+
35+
const data = new FormData();
36+
for (const filePath of parseObject(this.files)) {
37+
const file = fs.createReadStream(checkTmp(filePath));
38+
data.append("files", file);
39+
}
40+
41+
const response = await this.gptzeroDetectAi.detectFiles({
42+
$,
43+
data,
44+
headers: data.getHeaders(),
45+
});
46+
47+
$.export("$summary", `Successfully scanned ${this.files.length} file(s) for AI detection`);
48+
return response;
49+
},
50+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import gptzeroDetectAi from "../../gptzero_detect_ai.app.mjs";
2+
3+
export default {
4+
key: "gptzero_detect_ai-scan-text",
5+
name: "Scan Text for AI Detection",
6+
description: "This endpoint takes in a single text input and runs AI detection. The document will be truncated to 50,000 characters. [See the documentation](https://gptzero.stoplight.io/docs/gptzero-api/d2144a785776b-ai-detection-on-single-string)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
gptzeroDetectAi,
11+
document: {
12+
type: "string",
13+
label: "Document",
14+
description: "The text you want to analyze. The text will be truncated to 50,000 characters.",
15+
},
16+
multilingual: {
17+
type: "boolean",
18+
label: "Multilingual",
19+
description: "When this option is `true`, a special multilingual AI detection model will be used. Currently supported languages are French and Spanish.",
20+
optional: true,
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.gptzeroDetectAi.detectText({
25+
$,
26+
data: {
27+
document: this.document,
28+
multilingual: this.multilingual,
29+
},
30+
});
31+
32+
$.export("$summary", "Successfully ran AI detection on the document.");
33+
return response;
34+
},
35+
};
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+
};
Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "gptzero_detect_ai",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return "https://api.gptzero.me/v2/predict";
9+
},
10+
_headers(headers = {}) {
11+
return {
12+
"Accept": "application/json",
13+
"Content-Type": "application/json",
14+
"x-api-key": `${this.$auth.api_key}`,
15+
...headers,
16+
};
17+
},
18+
_makeRequest({
19+
$ = this, path, headers, ...opts
20+
}) {
21+
return axios($, {
22+
url: this._baseUrl() + path,
23+
headers: this._headers(headers),
24+
...opts,
25+
});
26+
},
27+
detectFiles(opts = {}) {
28+
return this._makeRequest({
29+
method: "POST",
30+
path: "/files",
31+
...opts,
32+
});
33+
},
34+
detectText(opts = {}) {
35+
return this._makeRequest({
36+
method: "POST",
37+
path: "/text",
38+
...opts,
39+
});
940
},
1041
},
11-
};
42+
};

components/gptzero_detect_ai/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/gptzero_detect_ai",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream GPTZero: Detect AI Components",
55
"main": "gptzero_detect_ai.app.mjs",
66
"keywords": [
@@ -11,5 +11,10 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1",
17+
"form-data": "^4.0.0"
1418
}
15-
}
19+
}
20+

pnpm-lock.yaml

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)