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
63 changes: 63 additions & 0 deletions components/hathr_ai/actions/chat/chat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import hathrAi from "../../hathr_ai.app.mjs";

export default {
key: "hathr_ai-chat",
name: "Send Chat Message",
description: "Sends a chat message using Hathr AI. [See the documentation](https://drive.google.com/drive/folders/1jtoSXqzhe-iwf9kfUwTCVQBu4iXVJO2x?usp=sharing)",
version: "0.0.1",
type: "action",
props: {
hathrAi,
message: {
type: "string",
label: "Message",
description: "The message to send in the chat request",
},
documents: {
propDefinition: [
hathrAi,
"documents",
],
},
temperature: {
type: "string",
label: "Temperature",
description: "Controls randomness (Optional, default: 0.2, range: 0-2.0)",
optional: true,
},
topP: {
type: "string",
label: "Top P",
description: "Controls diversity (Optional, default: 1.0, range: 0-1.0)",
optional: true,
},
},
async run({ $ }) {
const opts = {
$,
data: {
messages: [
{
role: "user",
text: this.message,
},
],
temperature: this.temperature,
topP: this.topP,
},
};
const { response } = this.documents
? await this.hathrAi.chatWithDocuments({
...opts,
data: {
...opts.data,
documents: this.documents,
},
})
: await this.hathrAi.chat(opts);

$.export("$summary", `Chat request sent successfully with message: "${this.message}"`);

return response;
},
};
21 changes: 21 additions & 0 deletions components/hathr_ai/actions/list-documents/list-documents.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import hathrAi from "../../hathr_ai.app.mjs";

export default {
key: "hathr_ai-list-documents",
name: "List Documents",
description: "Retrieves a list of all available documents. [See the documentation](https://drive.google.com/drive/folders/1jtoSXqzhe-iwf9kfUwTCVQBu4iXVJO2x?usp=sharing)",
version: "0.0.1",
type: "action",
props: {
hathrAi,
},
async run({ $ }) {
const { response: { documents } } = await this.hathrAi.listDocuments({
$,
});
$.export("$summary", `Successfully retrieved ${documents.length} document${documents.length === 1
? ""
: "s"}`);
return documents;
},
};
51 changes: 51 additions & 0 deletions components/hathr_ai/actions/upload-document/upload-document.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import hathrAi from "../../hathr_ai.app.mjs";
import { axios } from "@pipedream/platform";
import { checkTmp } from "../../common/utils.mjs";
import mime from "mime-types";
import fs from "fs";

export default {
key: "hathr_ai-upload-document",
name: "Upload Document",
description: "Uploads a document that can be used in future chat requests. [See the documentation](https://drive.google.com/drive/folders/1jtoSXqzhe-iwf9kfUwTCVQBu4iXVJO2x?usp=sharing)",
version: "0.0.1",
type: "action",
props: {
hathrAi,
filePath: {
type: "string",
label: "File Path",
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
},
filename: {
type: "string",
label: "Filename",
description: "The name of the file to be uploaded",
},
},
async run({ $ }) {
const filePath = checkTmp(this.filePath);
const fileBuffer = fs.readFileSync(filePath);
const mimeType = mime.lookup(filePath);

const { response: { signedUrl } } = await this.hathrAi.getUploadUrl({
$,
data: {
filename: this.filename,
type: mimeType,
},
});

await axios($, {
method: "PUT",
url: signedUrl,
data: fileBuffer,
headers: {
"Content-Type": mimeType,
},
});

$.export("$summary", "Successfully uploaded document.");
return signedUrl;
},
};
6 changes: 6 additions & 0 deletions components/hathr_ai/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const checkTmp = (filename) => {
if (!filename.startsWith("/tmp")) {
return `/tmp/${filename}`;
}
return filename;
};
58 changes: 54 additions & 4 deletions components/hathr_ai/hathr_ai.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "hathr_ai",
propDefinitions: {},
propDefinitions: {
documents: {
type: "string[]",
label: "Documents",
description: "Array of document names to use as context",
optional: true,
async options() {
const { response: { documents } } = await this.listDocuments();
return documents?.map(({ name }) => name ) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.hathr.ai/v1";
},
_makeRequest({
$ = this, path, ...otherOpts
}) {
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
});
},
listDocuments(opts = {}) {
return this._makeRequest({
path: "/document/list",
...opts,
});
},
chat(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/chat",
...opts,
});
},
chatWithDocuments(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/document/chat",
...opts,
});
},
getUploadUrl(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/document/upload",
...opts,
});
},
},
};
8 changes: 6 additions & 2 deletions components/hathr_ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/hathr_ai",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Hathr AI Components",
"main": "hathr_ai.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3",
"mime-types": "^3.0.1"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import hathrAi from "../../hathr_ai.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
key: "hathr_ai-new-document-created",
name: "New Document Created",
description: "Emit new event when a new document is created. [See the documentation](https://drive.google.com/drive/folders/1jtoSXqzhe-iwf9kfUwTCVQBu4iXVJO2x?usp=sharing)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
hathrAi,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
generateMeta(doc) {
return {
id: doc.name,
summary: `New Document Created: ${doc.name}`,
ts: Date.now(),
};
},
},
async run() {
const { response: { documents } } = await this.hathrAi.listDocuments();
for (const doc of documents) {
const meta = this.generateMeta(doc);
this.$emit(doc, meta);
}
},
};
9 changes: 8 additions & 1 deletion pnpm-lock.yaml

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

Loading