Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions components/gptzero_detect_ai/actions/scan-file/scan-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ConfigurationError } from "@pipedream/platform";
import FormData from "form-data";
import fs from "fs";
import {
checkTmp, parseObject,
} from "../../common/utils.mjs";
import gptzeroDetectAi from "../../gptzero_detect_ai.app.mjs";

export default {
key: "gptzero_detect_ai-scan-file",
name: "Scan File for AI Detection",
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)",
version: "0.0.1",
type: "action",
props: {
gptzeroDetectAi,
alert: {
type: "alert",
alertType: "info",
content: `By default, the maximum number of files that can be submitted simultaneously is **50**.
\nThe maximum file size for all files combined is **15 MB**.
\nEach file's document will be truncated to **50,000** characters.`,
},
files: {
type: "string[]",
label: "Files",
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).",
},
},
async run({ $ }) {
if (this.files.length > 50) {
throw new ConfigurationError("The maximum number of files that can be submitted simultaneously is 50.");
}

const data = new FormData();
for (const filePath of parseObject(this.files)) {
const file = fs.createReadStream(checkTmp(filePath));
data.append("files", file);
}

const response = await this.gptzeroDetectAi.detectFiles({
$,
data,
headers: data.getHeaders(),
});

$.export("$summary", `Successfully scanned ${this.files.length} file(s) for AI detection`);
return response;
},
};
35 changes: 35 additions & 0 deletions components/gptzero_detect_ai/actions/scan-text/scan-text.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import gptzeroDetectAi from "../../gptzero_detect_ai.app.mjs";

export default {
key: "gptzero_detect_ai-scan-text",
name: "Scan Text for AI Detection",
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)",
version: "0.0.1",
type: "action",
props: {
gptzeroDetectAi,
document: {
type: "string",
label: "Document",
description: "The text you want to analyze. The text will be truncated to 50,000 characters.",
},
multilingual: {
type: "boolean",
label: "Multilingual",
description: "When this option is `true`, a special multilingual AI detection model will be used. Currently supported languages are French and Spanish.",
optional: true,
},
},
async run({ $ }) {
const response = await this.gptzeroDetectAi.detectText({
$,
data: {
document: this.document,
multilingual: this.multilingual,
},
});

$.export("$summary", "Successfully ran AI detection on the document.");
return response;
},
};
31 changes: 31 additions & 0 deletions components/gptzero_detect_ai/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const checkTmp = (filename) => {
if (!filename.startsWith("/tmp")) {
return `/tmp/${filename}`;
}
return filename;
};

export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
41 changes: 36 additions & 5 deletions components/gptzero_detect_ai/gptzero_detect_ai.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "gptzero_detect_ai",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.gptzero.me/v2/predict";
},
_headers(headers = {}) {
return {
"Accept": "application/json",
"Content-Type": "application/json",
"x-api-key": `${this.$auth.api_key}`,
...headers,
};
},
_makeRequest({
$ = this, path, headers, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(headers),
...opts,
});
},
detectFiles(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/files",
...opts,
});
},
detectText(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/text",
...opts,
});
},
},
};
};
9 changes: 7 additions & 2 deletions components/gptzero_detect_ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gptzero_detect_ai",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream GPTZero: Detect AI Components",
"main": "gptzero_detect_ai.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,10 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1",
"form-data": "^4.0.0"
}
}
}

109 changes: 57 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading