Skip to content

Commit 41b6558

Browse files
committed
vectorshift init
1 parent 3aea15a commit 41b6558

File tree

8 files changed

+743
-4
lines changed

8 files changed

+743
-4
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import vectorshift from "../../vectorshift.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "vectorshift-add-data-to-knowledge-base",
6+
name: "Add Data to Knowledge Base",
7+
description: "Adds data to a knowledge base in VectorShift. [See the documentation](https://docs.vectorshift.ai/api-reference/knowledge-bases/index).",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
vectorshift,
12+
knowledgeBaseId: {
13+
propDefinition: [
14+
vectorshift,
15+
"knowledgeBaseId",
16+
],
17+
},
18+
fileData: {
19+
propDefinition: [
20+
vectorshift,
21+
"fileData",
22+
],
23+
optional: true,
24+
},
25+
urlData: {
26+
propDefinition: [
27+
vectorshift,
28+
"urlData",
29+
],
30+
optional: true,
31+
},
32+
wikipedia: {
33+
propDefinition: [
34+
vectorshift,
35+
"wikipedia",
36+
],
37+
optional: true,
38+
},
39+
youtube: {
40+
propDefinition: [
41+
vectorshift,
42+
"youtube",
43+
],
44+
optional: true,
45+
},
46+
arxiv: {
47+
propDefinition: [
48+
vectorshift,
49+
"arxiv",
50+
],
51+
optional: true,
52+
},
53+
git: {
54+
propDefinition: [
55+
vectorshift,
56+
"git",
57+
],
58+
optional: true,
59+
},
60+
addDataConfig: {
61+
propDefinition: [
62+
vectorshift,
63+
"addDataConfig",
64+
],
65+
optional: true,
66+
},
67+
},
68+
async run({ $ }) {
69+
if (
70+
!this.fileData &&
71+
!this.urlData &&
72+
!this.wikipedia &&
73+
!this.youtube &&
74+
!this.arxiv &&
75+
!this.git
76+
) {
77+
throw new Error("At least one of fileData, urlData, wikipedia, youtube, arxiv, or git must be provided.");
78+
}
79+
80+
const documentIds = await this.vectorshift.addDataToKnowledgeBase({
81+
knowledgeBaseId: this.knowledgeBaseId,
82+
fileData: this.fileData,
83+
urlData: this.urlData,
84+
wikipedia: this.wikipedia,
85+
youtube: this.youtube,
86+
arxiv: this.arxiv,
87+
git: this.git,
88+
addDataConfig: this.addDataConfig,
89+
});
90+
91+
$.export(
92+
"$summary",
93+
`Added ${documentIds.length} document(s) to knowledge base ${this.knowledgeBaseId}. Document IDs: ${documentIds.join(", ")}`,
94+
);
95+
96+
return {
97+
document_ids: documentIds,
98+
};
99+
},
100+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import vectorshift from "../../vectorshift.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "vectorshift-create-pipeline",
6+
name: "Create Pipeline",
7+
description: "Creates a new pipeline in VectorShift. [See the documentation](https://docs.vectorshift.ai)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
vectorshift: {
12+
type: "app",
13+
app: "vectorshift",
14+
},
15+
name: {
16+
propDefinition: [
17+
"vectorshift",
18+
"name",
19+
],
20+
},
21+
config: {
22+
propDefinition: [
23+
"vectorshift",
24+
"config",
25+
],
26+
},
27+
description: {
28+
propDefinition: [
29+
"vectorshift",
30+
"description",
31+
],
32+
optional: true,
33+
},
34+
},
35+
async run({ $ }) {
36+
const pipelineId = await this.vectorshift.createPipeline({
37+
name: this.name,
38+
config: this.config,
39+
description: this.description,
40+
});
41+
42+
$.export("$summary", `Created pipeline with ID ${pipelineId}`);
43+
return {
44+
id: pipelineId,
45+
};
46+
},
47+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import vectorshift from "../../vectorshift.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "vectorshift-run-pipeline",
6+
name: "Run Pipeline",
7+
description: "Executes a VectorShift pipeline with specified inputs. [See the documentation](https://docs.vectorshift.ai/api-reference/pipelines/run)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
vectorshift,
12+
pipelineId: {
13+
propDefinition: [
14+
vectorshift,
15+
"pipelineId",
16+
],
17+
},
18+
inputs: {
19+
type: "string",
20+
label: "Pipeline Inputs",
21+
description: "Inputs for the pipeline execution as a JSON string",
22+
},
23+
},
24+
async run({ $ }) {
25+
const runId = await this.vectorshift.executePipeline({
26+
pipelineId: this.pipelineId,
27+
inputs: this.inputs,
28+
});
29+
$.export("$summary", `Pipeline executed successfully. Run ID: ${runId}`);
30+
return {
31+
run_id: runId,
32+
};
33+
},
34+
};

components/vectorshift/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import vectorshift from "../../vectorshift.app.mjs";
2+
import {
3+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4+
} from "@pipedream/platform";
5+
6+
export default {
7+
key: "vectorshift-new-chatbot",
8+
name: "New Chatbot Created",
9+
description: "Emit new event when a chatbot is created. [See the documentation]()",
10+
version: "0.0.{{ts}}",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
vectorshift,
15+
db: "$.service.db",
16+
timer: {
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
},
23+
hooks: {
24+
async deploy() {
25+
try {
26+
const chatbots = await this.vectorshift.listChatbots();
27+
if (!Array.isArray(chatbots)) {
28+
throw new Error("Chatbots response is not an array");
29+
}
30+
const sortedChatbots = chatbots.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
31+
const recentChatbots = sortedChatbots.slice(0, 50).reverse();
32+
for (const chatbot of recentChatbots) {
33+
this.$emit(chatbot, {
34+
id: chatbot.id,
35+
summary: `New Chatbot: ${chatbot.name || "Unnamed"}`,
36+
ts: chatbot.created_at
37+
? Date.parse(chatbot.created_at)
38+
: Date.now(),
39+
});
40+
}
41+
const chatbotIds = chatbots.map((cb) => cb.id);
42+
await this.db.set("chatbotIds", chatbotIds);
43+
} catch (error) {
44+
console.error(`Error in deploy hook: ${error.message}`);
45+
}
46+
},
47+
async activate() {
48+
// No webhook setup required
49+
},
50+
async deactivate() {
51+
// No webhook teardown required
52+
},
53+
},
54+
async run() {
55+
try {
56+
const currentChatbots = await this.vectorshift.listChatbots();
57+
if (!Array.isArray(currentChatbots)) {
58+
throw new Error("Chatbots response is not an array");
59+
}
60+
const storedChatbotIds = await this.db.get("chatbotIds") || [];
61+
const newChatbots = currentChatbots.filter((chatbot) => !storedChatbotIds.includes(chatbot.id));
62+
63+
for (const chatbot of newChatbots) {
64+
this.$emit(chatbot, {
65+
id: chatbot.id,
66+
summary: `New Chatbot: ${chatbot.name || "Unnamed"}`,
67+
ts: chatbot.created_at
68+
? Date.parse(chatbot.created_at)
69+
: Date.now(),
70+
});
71+
}
72+
73+
const updatedChatbotIds = currentChatbots.map((cb) => cb.id);
74+
await this.db.set("chatbotIds", updatedChatbotIds);
75+
} catch (error) {
76+
console.error(`Error in run method: ${error.message}`);
77+
}
78+
},
79+
};

0 commit comments

Comments
 (0)