Skip to content
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

feat(dust): add support for fragments #18

Merged
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
4 changes: 2 additions & 2 deletions packages/pieces/community/dust/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-dust",
"version": "0.0.4"
}
"version": "0.1.0"
}
8 changes: 7 additions & 1 deletion packages/pieces/community/dust/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { createConversation } from './lib/actions/create-conversation';
import { replyToConversation } from './lib/actions/reply-to-conversation';
import { upsertDocument } from './lib/actions/upsert-document';
import { addFragmentToConversation } from './lib/actions/add-fragment-to-conversation';

export const dustAuth = PieceAuth.CustomAuth({
description: 'Dust authentication requires an API key.',
Expand Down Expand Up @@ -35,6 +36,11 @@ export const dust = createPiece({
minimumSupportedRelease: '0.9.0',
logoUrl: 'https://cdn.activepieces.com/pieces/dust.png',
authors: ['AdamSelene', 'abuaboud'],
actions: [createConversation, replyToConversation, upsertDocument],
actions: [
createConversation,
replyToConversation,
addFragmentToConversation,
upsertDocument,
],
triggers: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import { dustAuth } from '../..';
import { DUST_BASE_URL, getConversationContent } from '../common';
import {
httpClient,
HttpMethod,
HttpRequest,
} from '@activepieces/pieces-common';

export const addFragmentToConversation = createAction({
// auth: check https://www.activepieces.com/docs/developers/piece-reference/authentication,
name: 'addFragmentToConversation',
displayName: 'Add fragment to conversation',
description:
'Create a new content fragment in a conversation. Content fragments are pieces of information that can be inserted in conversations and are passed as context to assistants to when they generate an answer.',
auth: dustAuth,
props: {
conversationId: Property.ShortText({
displayName: 'Conversation ID',
required: true,
}),
fragment: Property.File({ displayName: 'Fragment', required: true }),
fragmentName: Property.ShortText({
displayName: 'Fragment name',
required: false,
}),
},
async run({ auth, propsValue }) {
const request: HttpRequest = {
method: HttpMethod.POST,
url: `${DUST_BASE_URL}/${auth.workspaceId}/assistant/conversations/${propsValue.conversationId}/content_fragments`,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${auth.apiKey}`,
},
body: JSON.stringify(
{
content: propsValue.fragment.data.toString('utf-8'),
title: propsValue.fragmentName || propsValue.fragment.filename,
contentType: 'file_attachment',
context: null,
url: null,
},
(key, value) => (typeof value === 'undefined' ? null : value)
),
};
return (await httpClient.sendRequest(request)).body;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,47 @@ export const createConversation = createAction({
username: usernameProp,
timezone: timezoneProp,
query: Property.LongText({ displayName: 'Query', required: true }),
fragment: Property.File({ displayName: 'Fragment', required: false }),
fragmentName: Property.ShortText({
displayName: 'Fragment name',
required: false,
}),
},
async run({ auth, propsValue }) {
const payload: Record<string, any> = {
visibility: 'unlisted',
title: null,
message: {
content: propsValue.query,
mentions: [{ configurationId: propsValue.assistant }],
context: {
timezone: propsValue.timezone,
username: propsValue.username,
email: null,
fullName: null,
profilePictureUrl: null,
},
},
};
if (propsValue.fragment) {
payload['contentFragment'] = {
title: propsValue.fragmentName || propsValue.fragment.filename,
content: propsValue.fragment.data.toString('utf-8'),
contentType: 'file_attachment',
context: null,
url: null,
};
}

const request: HttpRequest = {
method: HttpMethod.POST,
url: `${DUST_BASE_URL}/${auth.workspaceId}/assistant/conversations`,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${auth.apiKey}`,
},
body: JSON.stringify(
{
visibility: 'unlisted',
title: null,
message: {
content: propsValue.query,
mentions: [{ configurationId: propsValue.assistant }],
context: {
timezone: propsValue.timezone,
username: propsValue.username,
email: null,
fullName: null,
profilePictureUrl: null,
},
},
},
(key, value) => (typeof value === 'undefined' ? null : value)
body: JSON.stringify(payload, (key, value) =>
typeof value === 'undefined' ? null : value
),
};
const body = (await httpClient.sendRequest(request)).body;
Expand Down
1 change: 1 addition & 0 deletions packages/pieces/community/dust/src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export async function getConversationContent(
await new Promise((f) => setTimeout(f, 10000));

conversation = await getConversation(conversationId);
console.log('STATUS', conversation.body);
retries += 1;
}

Expand Down
Loading