Skip to content

Commit e35feaf

Browse files
lcaresialuancazarinecoderabbitai[bot]
authored andcommitted
Merging pull request PipedreamHQ#18377
* Added actions * Update components/weaviate/actions/create-class/create-class.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Luan Cazarine <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 6f23e27 commit e35feaf

File tree

7 files changed

+207
-7
lines changed

7 files changed

+207
-7
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import app from "../../weaviate.app.mjs";
2+
3+
export default {
4+
key: "weaviate-create-class",
5+
name: "Create Class",
6+
description: "Create a new class in Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/post/schema)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
className: {
12+
propDefinition: [
13+
app,
14+
"className",
15+
],
16+
},
17+
properties: {
18+
propDefinition: [
19+
app,
20+
"properties",
21+
],
22+
},
23+
description: {
24+
propDefinition: [
25+
app,
26+
"description",
27+
],
28+
},
29+
multiTenancyEnabled: {
30+
propDefinition: [
31+
app,
32+
"multiTenancyEnabled",
33+
],
34+
},
35+
vectorIndexType: {
36+
propDefinition: [
37+
app,
38+
"vectorIndexType",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const parsedProperties = this.properties?.map((p) => JSON.parse(p)) || [];
44+
const response = await this.app.createClass({
45+
$,
46+
data: {
47+
class: this.className,
48+
description: this.description,
49+
vectorizer: this.vectorizer,
50+
multiTenancyConfig: {
51+
enabled: this.multiTenancyEnabled,
52+
},
53+
vectorIndexType: this.vectorIndexType,
54+
properties: parsedProperties,
55+
},
56+
});
57+
$.export("$summary", "Successfully sent the request to create a new class");
58+
return response;
59+
},
60+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import app from "../../weaviate.app.mjs";
2+
3+
export default {
4+
key: "weaviate-delete-class",
5+
name: "Delete Class",
6+
description: "Delete a class from Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/delete/schema/{className})",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
classId: {
12+
propDefinition: [
13+
app,
14+
"classId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.deleteClass({
20+
$,
21+
classId: this.classId,
22+
});
23+
$.export("$summary", "Successfully deleted the class named " + this.classId);
24+
return response;
25+
},
26+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import app from "../../weaviate.app.mjs";
2+
3+
export default {
4+
key: "weaviate-get-schema",
5+
name: "Get Schema",
6+
description: "Get schema from Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/get/schema)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
},
12+
async run({ $ }) {
13+
const response = await this.app.getSchema({
14+
$,
15+
});
16+
$.export("$summary", "Successfully retrieved the current database schema");
17+
return response;
18+
},
19+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
VECTOR_TYPES: [
3+
"hnsw",
4+
"flat",
5+
],
6+
};

components/weaviate/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/weaviate",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Weaviate Components",
55
"main": "weaviate.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
1518
}
Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,93 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "weaviate",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
className: {
9+
type: "string",
10+
label: "Class Name",
11+
description: "The name of the class to create",
12+
},
13+
properties: {
14+
type: "string[]",
15+
label: "Properties",
16+
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\" }`",
17+
},
18+
description: {
19+
type: "string",
20+
label: "Description",
21+
description: "Optional description of the class",
22+
optional: true,
23+
},
24+
multiTenancyEnabled: {
25+
type: "boolean",
26+
label: "Multi-tenancy Enabled",
27+
description: "Set to `true` to enable multi-tenancy for this class",
28+
optional: true,
29+
},
30+
vectorIndexType: {
31+
type: "string",
32+
label: "Vector Index Type",
33+
description: "Type of vector index to use",
34+
optional: true,
35+
options: constants.VECTOR_TYPES,
36+
},
37+
classId: {
38+
type: "string",
39+
label: "Class Name",
40+
description: "Name of the Class",
41+
async options() {
42+
const response = await this.getSchema();
43+
return response.classes.map(({ class: className }) => ({
44+
value: className,
45+
label: className,
46+
}));
47+
},
48+
},
49+
},
550
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
51+
_baseUrl() {
52+
return `https://${this.$auth.cluster_url}`;
53+
},
54+
async _makeRequest(opts = {}) {
55+
const {
56+
$ = this,
57+
path,
58+
headers,
59+
...otherOpts
60+
} = opts;
61+
return axios($, {
62+
...otherOpts,
63+
url: this._baseUrl() + path,
64+
headers: {
65+
Authorization: `Bearer ${this.$auth.api_key}`,
66+
...headers,
67+
},
68+
});
69+
},
70+
async createClass(args = {}) {
71+
return this._makeRequest({
72+
path: "/v1/schema",
73+
method: "post",
74+
...args,
75+
});
76+
},
77+
async deleteClass({
78+
classId, ...args
79+
}) {
80+
return this._makeRequest({
81+
path: `/v1/schema/${classId}`,
82+
method: "delete",
83+
...args,
84+
});
85+
},
86+
async getSchema(args = {}) {
87+
return this._makeRequest({
88+
path: "/v1/schema",
89+
...args,
90+
});
991
},
1092
},
11-
};
93+
};

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)