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..97eb82251709f --- /dev/null +++ b/components/chat_data/actions/create-chatbot/create-chatbot.mjs @@ -0,0 +1,57 @@ +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..8bbf8be34cc2d --- /dev/null +++ b/components/chat_data/actions/get-chatbot-details/get-chatbot-details.mjs @@ -0,0 +1,30 @@ +import app from "../../chat_data.app.mjs"; + +export default { + 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", + 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..5a9c02998f2c2 100644 --- a/components/chat_data/chat_data.app.mjs +++ b/components/chat_data/chat_data.app.mjs @@ -1,11 +1,106 @@ +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: "The employee ID", + 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", + 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..87f8af5c966a2 --- /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 ba71ead05668a..ab8593c57419c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1706,7 +1706,11 @@ importers: specifier: ^1.6.4 version: 1.6.6 - components/chat_data: {} + components/chat_data: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/chatbot: dependencies: