Skip to content

New Components - agentset #16232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions components/agentset/actions/create-ingest-job/create-ingest-job.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import agentset from "../../agentset.app.mjs";
import { PAYLOAD_TYPE_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "agentset-create-ingest-job",
name: "Create Ingest Job",
description: "Create an ingest job for the authenticated organization. [See the documentation](https://docs.agentset.ai/api-reference/endpoint/ingest-jobs/create)",
version: "0.0.1",
type: "action",
props: {
agentset,
namespaceId: {
propDefinition: [
agentset,
"namespaceId",
],
},
payloadType: {
type: "string",
label: "Payload Type",
description: "Type of payload for the ingest job",
options: PAYLOAD_TYPE_OPTIONS,
reloadProps: true,
},
text: {
type: "string",
label: "Text",
description: "The text to ingest",
hidden: true,
},
fileUrl: {
type: "string",
label: "File URL",
description: "The URL of the file to ingest",
hidden: true,
},
urls: {
type: "string[]",
label: "URLs",
description: "The URLs to ingest",
hidden: true,
},
name: {
type: "string",
label: "Name",
description: "The name of the ingest job",
optional: true,
hidden: true,
},
},
async additionalProps(props) {
props.text.hidden = true;
props.name.hidden = true;
props.fileUrl.hidden = true;
props.urls.hidden = true;

switch (this.payloadType) {
case "TEXT":
props.text.hidden = false;
props.name.hidden = false;
break;
case "FILE":
props.fileUrl.hidden = false;
props.name.hidden = false;
break;
case "URLS":
props.urls.hidden = false;
break;
}
return {};
},
async run({ $ }) {
const payload = {
type: this.payloadType,
};
switch (this.payloadType) {
case "TEXT":
payload.text = this.text;
payload.name = this.name;
break;
case "FILE":
payload.fileUrl = this.fileUrl;
payload.name = this.name;
break;
case "URLS":
payload.urls = parseObject(this.urls);
break;
}
const response = await this.agentset.createIngestJob({
$,
namespaceId: this.namespaceId,
data: {
payload,
},
});
$.export("$summary", `Ingest job created successfully: ID ${response.data.id}`);
return response;
},
};
30 changes: 30 additions & 0 deletions components/agentset/actions/create-namespace/create-namespace.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import agentset from "../../agentset.app.mjs";
import { slugify } from "../../common/utils.mjs";

export default {
key: "agentset-create-namespace",
name: "Create Namespace",
description: "Creates a namespace for the authenticated organization. [See the documentation](https://docs.agentset.ai/api-reference/endpoint/namespaces/create)",
version: "0.0.1",
type: "action",
props: {
agentset,
name: {
type: "string",
label: "Name",
description: "The name of the namespace to create",
},
},
async run({ $ }) {
const response = await this.agentset.createNamespace({
$,
data: {
name: this.name,
slug: slugify(this.name),
},
});

$.export("$summary", `Successfully created namespace with ID: ${response.data.id}`);
return response;
},
};
89 changes: 89 additions & 0 deletions components/agentset/actions/search-namespace/search-namespace.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import agentset from "../../agentset.app.mjs";

export default {
key: "agentset-search-namespace",
name: "Agentset Search Namespace",
description: "Complete retrieval pipeline for RAG with semantic search, filtering, and reranking. [See the documentation](https://docs.agentset.ai/api-reference/endpoint/search)",
version: "0.0.1",
type: "action",
props: {
agentset,
namespaceId: {
propDefinition: [
agentset,
"namespaceId",
],
},
query: {
type: "string",
label: "Query",
description: "The query for semantic search",
},
topK: {
type: "integer",
label: "Top K",
description: "Number of top documents to return",
min: 1,
max: 100,
optional: true,
},
rerank: {
type: "boolean",
label: "Rerank",
description: "Whether to rerank the results",
optional: true,
},
rerankLimit: {
type: "integer",
label: "Rerank Limit",
description: "The number of results to return after reranking",
min: 1,
max: 100,
optional: true,
},
filter: {
type: "object",
label: "Filter",
description: "Filter to apply to search results",
optional: true,
},
minScore: {
type: "string",
label: "Minimum Score",
description: "Minimum score to return. Range from 0 to 1",
optional: true,
},
includeRelationship: {
type: "boolean",
label: "Include Relationship",
description: "Whether to include relationships in the results",
optional: true,
},
includeMetadata: {
type: "boolean",
label: "Include Metadata",
description: "Whether to include metadata in the results",
optional: true,
},
},

async run({ $ }) {
const response = await this.agentset.searchNamespace({
$,
namespaceId: this.namespaceId,
data: {
query: this.query,
topK: this.topK,
rerank: this.rerank,
rerankLimit: this.rerankLimit,
filter: this.filter,
minScore: this.minScore && parseFloat(this.minScore),
includeRelationships: this.includeRelationship,
includeMetadata: this.includeMetadata,
},
});

$.export("$summary", `Successfully completed the search for query: "${this.query}"`);
return response;
},
};
120 changes: 116 additions & 4 deletions components/agentset/agentset.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,123 @@
import { axios } from "@pipedream/platform";
import { STATUSES_OPTIONS } from "./common/constants.mjs";

export default {
type: "app",
app: "agentset",
propDefinitions: {},
propDefinitions: {
namespaceId: {
type: "string",
label: "Namespace ID",
description: "The ID of the namespace",
async options() {
const { data } = await this.listNamespaces();
return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
statuses: {
type: "string[]",
label: "Statuses",
description: "Filter by status",
options: STATUSES_OPTIONS,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.agentset.ai/v1";
},
_headers() {
return {
Authorization: `Bearer ${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listNamespaces(opts = {}) {
return this._makeRequest({
path: "/namespace",
...opts,
});
},
createNamespace(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/namespace",
...opts,
});
},
createIngestJob({
namespaceId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/namespace/${namespaceId}/ingest-jobs`,
...opts,
});
},
listIngestJobs({
namespaceId, ...opts
}) {
return this._makeRequest({
path: `/namespace/${namespaceId}/ingest-jobs`,
...opts,
});
},
listDocuments({
namespaceId, ...opts
}) {
return this._makeRequest({
path: `/namespace/${namespaceId}/documents`,
...opts,
});
},
searchNamespace({
namespaceId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/namespace/${namespaceId}/search`,
...opts,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let count = 0;
let cursor;

do {
params.cursor = cursor;
const {
data,
pagination: { nextCursor },
} = await fn({
params,
...opts,
});
for (const d of data) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

cursor = nextCursor;

} while (cursor);
},
},
};

19 changes: 19 additions & 0 deletions components/agentset/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const PAYLOAD_TYPE_OPTIONS = [
"TEXT",
"FILE",
"URLS",
];

export const STATUSES_OPTIONS = [
"BACKLOG",
"QUEUED",
"QUEUED_FOR_RESYNC",
"QUEUED_FOR_DELETE",
"PRE_PROCESSING",
"PROCESSING",
"DELETING",
"CANCELLING",
"COMPLETED",
"FAILED",
"CANCELLED",
];
Loading
Loading