diff --git a/components/weaviate/actions/create-class/create-class.mjs b/components/weaviate/actions/create-class/create-class.mjs new file mode 100644 index 0000000000000..ae5b9a97993db --- /dev/null +++ b/components/weaviate/actions/create-class/create-class.mjs @@ -0,0 +1,60 @@ +import app from "../../weaviate.app.mjs"; + +export default { + key: "weaviate-create-class", + name: "Create Class", + description: "Create a new class in Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/post/schema)", + version: "0.0.1", + type: "action", + props: { + app, + className: { + propDefinition: [ + app, + "className", + ], + }, + properties: { + propDefinition: [ + app, + "properties", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + multiTenancyEnabled: { + propDefinition: [ + app, + "multiTenancyEnabled", + ], + }, + vectorIndexType: { + propDefinition: [ + app, + "vectorIndexType", + ], + }, + }, + async run({ $ }) { + const parsedProperties = this.properties?.map((p) => JSON.parse(p)) || []; + const response = await this.app.createClass({ + $, + data: { + class: this.className, + description: this.description, + vectorizer: this.vectorizer, + multiTenancyConfig: { + enabled: this.multiTenancyEnabled, + }, + vectorIndexType: this.vectorIndexType, + properties: parsedProperties, + }, + }); + $.export("$summary", "Successfully sent the request to create a new class"); + return response; + }, +}; diff --git a/components/weaviate/actions/delete-class/delete-class.mjs b/components/weaviate/actions/delete-class/delete-class.mjs new file mode 100644 index 0000000000000..529601c4c06f8 --- /dev/null +++ b/components/weaviate/actions/delete-class/delete-class.mjs @@ -0,0 +1,26 @@ +import app from "../../weaviate.app.mjs"; + +export default { + key: "weaviate-delete-class", + name: "Delete Class", + description: "Delete a class from Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/delete/schema/{className})", + version: "0.0.1", + type: "action", + props: { + app, + classId: { + propDefinition: [ + app, + "classId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.deleteClass({ + $, + classId: this.classId, + }); + $.export("$summary", "Successfully deleted the class named " + this.classId); + return response; + }, +}; diff --git a/components/weaviate/actions/get-schema/get-schema.mjs b/components/weaviate/actions/get-schema/get-schema.mjs new file mode 100644 index 0000000000000..938715e2b0cff --- /dev/null +++ b/components/weaviate/actions/get-schema/get-schema.mjs @@ -0,0 +1,19 @@ +import app from "../../weaviate.app.mjs"; + +export default { + key: "weaviate-get-schema", + name: "Get Schema", + description: "Get schema from Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/get/schema)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.getSchema({ + $, + }); + $.export("$summary", "Successfully retrieved the current database schema"); + return response; + }, +}; diff --git a/components/weaviate/common/constants.mjs b/components/weaviate/common/constants.mjs new file mode 100644 index 0000000000000..1e18520d94454 --- /dev/null +++ b/components/weaviate/common/constants.mjs @@ -0,0 +1,6 @@ +export default { + VECTOR_TYPES: [ + "hnsw", + "flat", + ], +}; diff --git a/components/weaviate/package.json b/components/weaviate/package.json index 69219b7e928bc..047b6f8943b79 100644 --- a/components/weaviate/package.json +++ b/components/weaviate/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/weaviate", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Weaviate Components", "main": "weaviate.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/components/weaviate/weaviate.app.mjs b/components/weaviate/weaviate.app.mjs index c0bc9cc789d62..d56c31f8db9ef 100644 --- a/components/weaviate/weaviate.app.mjs +++ b/components/weaviate/weaviate.app.mjs @@ -1,11 +1,93 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "weaviate", - propDefinitions: {}, + propDefinitions: { + className: { + type: "string", + label: "Class Name", + description: "The name of the class to create", + }, + properties: { + type: "string[]", + label: "Properties", + description: "The properties of the class. Each item must be a JSON object string, e.g.: `{ \"name\": \"title\", \"dataType\": [\"text\"], \"description\": \"Title of the object\" }`", + }, + description: { + type: "string", + label: "Description", + description: "Optional description of the class", + optional: true, + }, + multiTenancyEnabled: { + type: "boolean", + label: "Multi-tenancy Enabled", + description: "Set to `true` to enable multi-tenancy for this class", + optional: true, + }, + vectorIndexType: { + type: "string", + label: "Vector Index Type", + description: "Type of vector index to use", + optional: true, + options: constants.VECTOR_TYPES, + }, + classId: { + type: "string", + label: "Class Name", + description: "Name of the Class", + async options() { + const response = await this.getSchema(); + return response.classes.map(({ class: className }) => ({ + value: className, + label: className, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `https://${this.$auth.cluster_url}`; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + Authorization: `Bearer ${this.$auth.api_key}`, + ...headers, + }, + }); + }, + async createClass(args = {}) { + return this._makeRequest({ + path: "/v1/schema", + method: "post", + ...args, + }); + }, + async deleteClass({ + classId, ...args + }) { + return this._makeRequest({ + path: `/v1/schema/${classId}`, + method: "delete", + ...args, + }); + }, + async getSchema(args = {}) { + return this._makeRequest({ + path: "/v1/schema", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d17fc49d907df..afc42ccc078ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4939,8 +4939,7 @@ importers: specifier: ^3.1.0 version: 3.1.0 - components/financial_data: - specifiers: {} + components/financial_data: {} components/findymail: dependencies: @@ -7914,8 +7913,7 @@ importers: components/lightpanda: {} - components/lightspeed_ecom_c_series: - specifiers: {} + components/lightspeed_ecom_c_series: {} components/lightspeed_retail_pos: dependencies: @@ -8759,8 +8757,7 @@ importers: components/microsoft_advertising: {} - components/microsoft_authenticator: - specifiers: {} + components/microsoft_authenticator: {} components/microsoft_azure_ai_translator: dependencies: @@ -15587,7 +15584,11 @@ importers: specifier: ^1.4.1 version: 1.6.6 - components/weaviate: {} + components/weaviate: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/webflow: dependencies: