From 8087a5a0fdb42434153029020602174a92825db5 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 17 Oct 2024 12:46:57 -0300 Subject: [PATCH 1/5] Added actions --- .../actions/create-chatbot/create-chatbot.mjs | 59 ++++++++++ .../actions/delete-chatbot/delete-chatbot.mjs | 29 +++++ .../get-chatbot-details.mjs | 29 +++++ components/chat_data/chat_data.app.mjs | 106 ++++++++++++++++- components/chat_data/common/constants.mjs | 8 ++ components/chat_data/package.json | 7 +- pnpm-lock.yaml | 107 +++++++++--------- 7 files changed, 286 insertions(+), 59 deletions(-) create mode 100644 components/chat_data/actions/create-chatbot/create-chatbot.mjs create mode 100644 components/chat_data/actions/delete-chatbot/delete-chatbot.mjs create mode 100644 components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs create mode 100644 components/chat_data/common/constants.mjs diff --git a/components/chat_data/actions/create-chatbot/create-chatbot.mjs b/components/chat_data/actions/create-chatbot/create-chatbot.mjs new file mode 100644 index 0000000000000..36a45e5f57a42 --- /dev/null +++ b/components/chat_data/actions/create-chatbot/create-chatbot.mjs @@ -0,0 +1,59 @@ +import app from "../../chat_data.app.mjs"; + +export default { + key: "chat_data-create-chatbot", + name: "Create Chatbot", + description: "Create a chatbot with the specified properties. [See the documentation](https://www.chat-data.com/api-reference#tag/Chatbot-Operations/operation/chatbotCreate)", + version: "0.0.1", + type: "action", + props: { + app, + chatbotName: { + propDefinition: [ + app, + "chatbotName", + ], + }, + sourceText: { + propDefinition: [ + app, + "sourceText", + ], + }, + urlsToScrape: { + propDefinition: [ + app, + "urlsToScrape", + ], + }, + customBackend: { + propDefinition: [ + app, + "customBackend", + ], + }, + model: { + propDefinition: [ + app, + "model", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.createChatbot({ + $, + data: { + chatbotName: this.chatbotName, + sourceText: this.sourceText, + urlsToScrape: this.urlsToScrape, + customBackend: this.customBackend, + model: this.model, + }, + }); + + $.export("$summary", `Successfully created Chatbot with ID '${response.chatbotId}'`); + + return response; + }, +}; diff --git a/components/chat_data/actions/delete-chatbot/delete-chatbot.mjs b/components/chat_data/actions/delete-chatbot/delete-chatbot.mjs new file mode 100644 index 0000000000000..138dbc1ee6787 --- /dev/null +++ b/components/chat_data/actions/delete-chatbot/delete-chatbot.mjs @@ -0,0 +1,29 @@ +import app from "../../chat_data.app.mjs"; + +export default { + key: "chat_data-delete-chatbot", + name: "Delete Chatbot", + description: "Delete a chatbot with the specified ID. [See the documentation](https://www.chat-data.com/api-reference#tag/Chatbot-Operations/operation/chatbotDelete)", + version: "0.0.1", + type: "action", + props: { + app, + chatbotId: { + propDefinition: [ + app, + "chatbotId", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.deleteChatbot({ + $, + chatbotId: this.chatbotId, + }); + + $.export("$summary", `Successfully deleted Chatbot with ID '${this.chatbotId}'`); + + return response; + }, +}; diff --git a/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs b/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs new file mode 100644 index 0000000000000..81cccdea4a668 --- /dev/null +++ b/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs @@ -0,0 +1,29 @@ +import app from "../../chat_data.app.mjs"; + +export default { + key: "chat_data-get-chatbot-status", + name: "Get Chatbot Status", + description: "Get status of the Chatbot with the specified ID. [See the documentation](https://www.chat-data.com/api-reference#tag/Chatbot-Operations/operation/GetChatbotStatus)", + version: "0.0.1", + type: "action", + props: { + app, + chatbotId: { + propDefinition: [ + app, + "chatbotId", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.getChatbotStatus({ + $, + chatbotId: this.chatbotId, + }); + + $.export("$summary", `Successfully retrieved status of the Chatbot with ID '${this.chatbotId}'`); + + return response; + }, +}; diff --git a/components/chat_data/chat_data.app.mjs b/components/chat_data/chat_data.app.mjs index 52c77a8bc7d79..f983b665b8468 100644 --- a/components/chat_data/chat_data.app.mjs +++ b/components/chat_data/chat_data.app.mjs @@ -1,11 +1,107 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "chat_data", - propDefinitions: {}, + propDefinitions: { + chatbotId: { + type: "string", + label: "Employee ID", + description: "ID of the Employee", + async options() { + const response = await this.getChatbots(); + + const chatbotIds = response.chatbots; + + return chatbotIds.map(({ + chatbotId, chatbotName, + }) => ({ + value: chatbotId, + label: chatbotName, + })); + }, + }, + chatbotName: { + type: "string", + label: "Chatbot Name", + description: "Name of the Chatbot", + }, + sourceText: { + type: "string", + label: "Source Text", + description: "Text data for the chatbot, subject to character limits based on your plan. Relevant only if the model is custom-data-upload", + optional: true, + }, + urlsToScrape: { + type: "string[]", + label: "URLs to Scrape", + description: "A list of URLs is for text content extraction by Chat Data, i.e.: `https://www.chat-data.com`. Relevant only if the model is custom-data-upload", + optional: true, + }, + customBackend: { + type: "string", + label: "Custom Backend", + description: "The URL of a customized backend for the chatbot", + optional: true, + }, + model: { + type: "string", + label: "Model", + description: "The chatbot defaults to `custom-data-upload` if the model parameter is not provided", + optional: true, + options: constants.CHATBOT_MODELS, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.chat-data.com/api/v2"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, + }); + }, + async createChatbot(args = {}) { + return this._makeRequest({ + path: "/create-chatbot", + method: "post", + ...args, + }); + }, + async getChatbotStatus({ + chatbotId, ...args + }) { + return this._makeRequest({ + path: `/chatbot/status/${chatbotId}/`, + ...args, + }); + }, + async deleteChatbot({ + chatbotId, ...args + }) { + return this._makeRequest({ + path: `/delete-chatbot/${chatbotId}/`, + method: "delete", + ...args, + }); + }, + async getChatbots(args = {}) { + return this._makeRequest({ + path: "/get-chatbots", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/chat_data/common/constants.mjs b/components/chat_data/common/constants.mjs new file mode 100644 index 0000000000000..86cbdd41950b3 --- /dev/null +++ b/components/chat_data/common/constants.mjs @@ -0,0 +1,8 @@ +export default { + CHATBOT_MODELS: [ + "custom-data-upload", + "medical-chat-human", + "medical-chat-vet", + "custom-model", + ], +}; diff --git a/components/chat_data/package.json b/components/chat_data/package.json index 39d3bcdadbcb0..624df3b499197 100644 --- a/components/chat_data/package.json +++ b/components/chat_data/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/chat_data", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Chat Data Components", "main": "chat_data.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de0e792c04bf2..34499ede71ab5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1587,7 +1587,10 @@ importers: '@pipedream/platform': 1.6.4 components/chat_data: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/chatbot: specifiers: @@ -13066,55 +13069,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: - resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sts': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sts' - - aws-crt - dev: false - /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13350,7 +13304,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 + '@aws-sdk/client-sso-oidc': 3.600.0 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13392,6 +13346,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: + resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' + - aws-crt + dev: false + /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17684,7 +17687,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6 From 1b2baa6c67ad502d96037fc30c2d3752e4740c67 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 24 Oct 2024 18:08:25 -0300 Subject: [PATCH 2/5] Fixed requested changes --- components/chat_data/chat_data.app.mjs | 1 - components/chat_data/common/constants.mjs | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/components/chat_data/chat_data.app.mjs b/components/chat_data/chat_data.app.mjs index f983b665b8468..3410dd8bcad03 100644 --- a/components/chat_data/chat_data.app.mjs +++ b/components/chat_data/chat_data.app.mjs @@ -49,7 +49,6 @@ export default { type: "string", label: "Model", description: "The chatbot defaults to `custom-data-upload` if the model parameter is not provided", - optional: true, options: constants.CHATBOT_MODELS, }, }, diff --git a/components/chat_data/common/constants.mjs b/components/chat_data/common/constants.mjs index 86cbdd41950b3..87f8af5c966a2 100644 --- a/components/chat_data/common/constants.mjs +++ b/components/chat_data/common/constants.mjs @@ -1,8 +1,8 @@ -export default { - CHATBOT_MODELS: [ +export default { + CHATBOT_MODELS: [ "custom-data-upload", "medical-chat-human", "medical-chat-vet", - "custom-model", - ], + "custom-model", + ], }; From cc68bec63c338ef5e1c19ebb7aef212b3532b6a4 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 24 Oct 2024 18:09:10 -0300 Subject: [PATCH 3/5] Fixed requested changes --- components/chat_data/chat_data.app.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chat_data/chat_data.app.mjs b/components/chat_data/chat_data.app.mjs index 3410dd8bcad03..5a9c02998f2c2 100644 --- a/components/chat_data/chat_data.app.mjs +++ b/components/chat_data/chat_data.app.mjs @@ -8,7 +8,7 @@ export default { chatbotId: { type: "string", label: "Employee ID", - description: "ID of the Employee", + description: "The employee ID", async options() { const response = await this.getChatbots(); From 6a4cfd809cca649edf7c75da2ac326601b1029dd Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 27 Nov 2024 12:59:55 -0300 Subject: [PATCH 4/5] Fixed requested changes --- components/chat_data/actions/create-chatbot/create-chatbot.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/chat_data/actions/create-chatbot/create-chatbot.mjs b/components/chat_data/actions/create-chatbot/create-chatbot.mjs index 36a45e5f57a42..97eb82251709f 100644 --- a/components/chat_data/actions/create-chatbot/create-chatbot.mjs +++ b/components/chat_data/actions/create-chatbot/create-chatbot.mjs @@ -51,9 +51,7 @@ export default { model: this.model, }, }); - $.export("$summary", `Successfully created Chatbot with ID '${response.chatbotId}'`); - return response; }, }; From 9c8073260d63c063a79f01531a4b9103f17246c7 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 27 Nov 2024 13:12:21 -0300 Subject: [PATCH 5/5] Update components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs Co-authored-by: Jorge Cortes --- .../actions/get-chatbot-details/get-chatbot-details.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs b/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs index 81cccdea4a668..8bbf8be34cc2d 100644 --- a/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs +++ b/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs @@ -1,7 +1,8 @@ import app from "../../chat_data.app.mjs"; export default { - key: "chat_data-get-chatbot-status", + key: "chat_data-get-chatbot-details", + name: "Get Chatbot Status", description: "Get status of the Chatbot with the specified ID. [See the documentation](https://www.chat-data.com/api-reference#tag/Chatbot-Operations/operation/GetChatbotStatus)", version: "0.0.1",