Skip to content

Commit

Permalink
New Components - dust (#14043)
Browse files Browse the repository at this point in the history
* dust init

* [Components] dust #14021
Actions
 - Talk to Assistant
 - Upsert Document

* pnpm update

* some adjusts

* some adjusts

* Require content prop

* remove optional from prop email

---------

Co-authored-by: Leo Vu <[email protected]>
  • Loading branch information
luancazarine and vunguyenhung authored Sep 27, 2024
1 parent 2cf235b commit 08b948b
Show file tree
Hide file tree
Showing 6 changed files with 809 additions and 8 deletions.
74 changes: 74 additions & 0 deletions components/dust/actions/talk-assistant/talk-assistant.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { TIMEZONE_OPTIONS } from "../../common/constants.mjs";
import dust from "../../dust.app.mjs";

export default {
key: "dust-talk-assistant",
name: "Talk to Assistant",
description: "Send a message to an assistant on Dust and receive an answer. [See the documentation](https://docs.dust.tt/reference/post_api-v1-w-wid-assistant-conversations-cid-messages)",
version: "0.0.1",
type: "action",
props: {
dust,
assistantId: {
propDefinition: [
dust,
"assistantId",
],
},
content: {
type: "string",
label: "Message Content",
description: "The content of the message to be sent to the assistant",
},
timezone: {
type: "string",
label: "Timezone",
description: "Set the timezone in which you want to operate.",
options: TIMEZONE_OPTIONS,
},
username: {
type: "string",
label: "Username",
description: "The name to be displayed in the conversation.",
},
email: {
type: "string",
label: "Email",
description: "Put an email if needed.",
},
},
async run({ $ }) {
const {
conversation, message,
} = await this.dust.sendMessageToAssistant({
$,
data: {
message: {
content: this.content,
context: {
timezone: this.timezone,
username: this.username,
fullName: null,
email: this.email,
profilePictureUrl: null,
},
mentions: [
{
configurationId: this.assistantId,
},
],
},
blocking: true,
visibility: "unlisted",
title: null,
},
});

$.export("$summary", "Successfully sent message to assistant");
return {
agentMessage: conversation.content[1][0].content,
conversationUrl: `https://dust.tt/w/${conversation.owner.sId}/assistant/${conversation.sId}`,
message,
};
},
};
48 changes: 48 additions & 0 deletions components/dust/actions/upsert-document/upsert-document.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import dust from "../../dust.app.mjs";

export default {
key: "dust-upsert-document",
name: "Upsert Document",
description: "Upsert a document to a chosen Dust data source. [See the documentation](https://docs.dust.tt/reference/post_api-v1-w-wid-data-sources-name-documents-documentid)",
version: "0.0.1",
type: "action",
props: {
dust,
dataSourceId: {
propDefinition: [
dust,
"dataSourceId",
],
},
documentId: {
type: "string",
label: "Document Id",
description: "An Id for the new document",
},
content: {
type: "string",
label: "Content",
description: "The text content of the document to upsert.",
},
lightDocumentOutput: {
type: "boolean",
label: "Light Document Output",
description: "If true, a lightweight version of the document will be returned in the response (excluding the text, chunks and vectors). Defaults to false.",
optional: true,
},
},
async run({ $ }) {
const response = await this.dust.upsertDocument({
$,
dataSourceId: this.dataSourceId,
documentId: this.documentId,
data: {
text: this.content,
light_document_output: this.lightDocumentOutput,
},
});

$.export("$summary", "Successfully uploaded document");
return response;
},
};
Loading

0 comments on commit 08b948b

Please sign in to comment.