-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
community[minor]: Taskade Project Loader (#5927)
Co-authored-by: jacoblee93 <[email protected]>
- Loading branch information
1 parent
b35812c
commit 5076dd3
Showing
8 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
docs/core_docs/docs/integrations/document_loaders/web_loaders/taskade.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
hide_table_of_contents: true | ||
--- | ||
|
||
# Taskade | ||
|
||
[Taskade](https://www.taskade.com) is the ultimate tool for AI-driven writing, project management, and task automation. Designed to be your second brain, Taskade simplifies project execution and enhances team collaboration from start to finish. | ||
|
||
## Overview | ||
|
||
With [Taskade](https://www.taskade.com), you can build, train, and deploy your own team of AI agents to automate tasks and streamline workflows. Taskade features a seamless blend of ideation, collaboration, and execution tools—from structured lists to modern tables and mind maps, all customizable to fit your unique workflow and adapt to your needs. | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
import Example from "@examples/document_loaders/taskade.ts"; | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> | ||
|
||
You can find your Taskade project id by opening the project in your browser and extracting them from the URL: | ||
|
||
``` | ||
https://www.taskade.com/d/<YOUR PROJECT ID HERE> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { TaskadeProjectLoader } from "@langchain/community/document_loaders/web/taskade"; | ||
|
||
const loader = new TaskadeProjectLoader({ | ||
personalAccessToken: "TASKADE_PERSONAL_ACCESS_TOKEN", // or load it from process.env.TASKADE_PERSONAL_ACCESS_TOKEN | ||
projectId: "projectId", | ||
}); | ||
const docs = await loader.load(); | ||
|
||
console.log({ docs }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
libs/langchain-community/src/document_loaders/tests/taskade.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable no-process-env */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { test } from "@jest/globals"; | ||
import { TaskadeProjectLoader } from "../web/taskade.js"; | ||
|
||
test.skip("Test TaskadeProjectLoader", async () => { | ||
const loader = new TaskadeProjectLoader({ | ||
personalAccessToken: process.env.TASKADE_PERSONAL_ACCESS_TOKEN!, | ||
projectId: process.env.TASKADE_PROJECT_ID!, | ||
}); | ||
const documents = await loader.load(); | ||
console.log(documents[0].pageContent); | ||
}); |
125 changes: 125 additions & 0 deletions
125
libs/langchain-community/src/document_loaders/web/taskade.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { getEnvironmentVariable } from "@langchain/core/utils/env"; | ||
import { Document } from "@langchain/core/documents"; | ||
import { BaseDocumentLoader } from "@langchain/core/document_loaders/base"; | ||
|
||
/** | ||
* Interface representing the parameters for configuring the TaskadeLoader. | ||
* It includes optional properties for the personal access token and project id. | ||
*/ | ||
export interface TaskadeLoaderParams { | ||
personalAccessToken?: string; | ||
projectId: string; | ||
} | ||
|
||
/** | ||
* Interface representing a Taskade project. It includes properties for the | ||
* id, text, parentId and completed. | ||
*/ | ||
export interface TaskadeProject { | ||
tasks: Array<{ | ||
id: string; | ||
text: string; | ||
parentId: string; | ||
completed: boolean; | ||
}>; | ||
} | ||
|
||
/** | ||
* Class representing a document loader for loading Taskade project. It | ||
* extends the BaseDocumentLoader and implements the TaskadeLoaderParams | ||
* interface. The constructor takes a config object as a parameter, which | ||
* contains the personal access token and project ID. | ||
* @example | ||
* ```typescript | ||
* const loader = new TaskadeProjectLoader({ | ||
* personalAccessToken: "TASKADE_PERSONAL_ACCESS_TOKEN", | ||
* projectId: "projectId", | ||
* }); | ||
* const docs = await loader.load(); | ||
* ``` | ||
*/ | ||
export class TaskadeProjectLoader | ||
extends BaseDocumentLoader | ||
implements TaskadeLoaderParams | ||
{ | ||
public readonly personalAccessToken?: string; | ||
|
||
public readonly projectId: string; | ||
|
||
private headers: Record<string, string> = {}; | ||
|
||
constructor({ | ||
personalAccessToken = getEnvironmentVariable( | ||
"TASKADE_PERSONAL_ACCESS_TOKEN" | ||
), | ||
projectId, | ||
}: TaskadeLoaderParams) { | ||
super(); | ||
this.personalAccessToken = personalAccessToken; | ||
this.projectId = projectId; | ||
|
||
if (this.personalAccessToken) { | ||
this.headers = { | ||
Authorization: `Bearer ${this.personalAccessToken}`, | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Fetches the Taskade project using the Taskade API and returns it as a | ||
* TaskadeProject object. | ||
* @returns A Promise that resolves to a TaskadeProject object. | ||
*/ | ||
private async getTaskadeProject(): Promise<TaskadeProject> { | ||
const tasks = []; | ||
let after: string | null = null; | ||
let hasMoreTasks = true; | ||
while (hasMoreTasks) { | ||
const queryParamsString: string = new URLSearchParams({ | ||
limit: "100", | ||
...(after == null ? {} : { after }), | ||
}).toString(); | ||
const url = `https://www.taskade.com/api/v1/projects/${this.projectId}/tasks?${queryParamsString}`; | ||
|
||
const response = await fetch(url, { headers: this.headers }); | ||
const data = await response.json(); | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`Unable to get Taskade project: ${response.status} ${JSON.stringify( | ||
data | ||
)}` | ||
); | ||
} | ||
|
||
if (!data) { | ||
throw new Error("Unable to get Taskade project"); | ||
} | ||
|
||
if (data.items.length === 0) { | ||
hasMoreTasks = false; | ||
} else { | ||
after = data.items[data.items.length - 1].id; | ||
} | ||
|
||
tasks.push(...data.items); | ||
} | ||
|
||
return { tasks }; | ||
} | ||
|
||
/** | ||
* Fetches the Taskade project using the Taskade API, creates a Document instance | ||
* with the JSON representation of the file as the page content and the | ||
* API URL as the metadata, and returns it. | ||
* @returns A Promise that resolves to an array of Document instances. | ||
*/ | ||
public async load(): Promise<Document[]> { | ||
const data = await this.getTaskadeProject(); | ||
|
||
const metadata = { projectId: this.projectId }; | ||
const text = data.tasks.map((t) => t.text).join("\n"); | ||
|
||
return [new Document({ pageContent: text, metadata })]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters