Skip to content

Commit

Permalink
move to Section for upsertToDatasource (#2732)
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu authored Dec 1, 2023
1 parent 61f1926 commit 2aa97a7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
12 changes: 10 additions & 2 deletions connectors/src/connectors/github/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ export async function githubUpsertIssueActivity(
await upsertToDatasource({
dataSourceConfig,
documentId,
documentText: renderedIssue,
documentContent: {
prefix: null,
content: renderedIssue,
sections: [],
},
documentUrl: issue.url,
timestampMs: lastUpdateTimestamp,
tags: tags,
Expand Down Expand Up @@ -287,7 +291,11 @@ export async function githubUpsertDiscussionActivity(
await upsertToDatasource({
dataSourceConfig,
documentId,
documentText: renderedDiscussion,
documentContent: {
prefix: null,
content: renderedDiscussion,
sections: [],
},
documentUrl: discussion.url,
timestampMs: new Date(discussion.createdAt).getTime(),
tags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,11 @@ async function syncOneFile(
await upsertToDatasource({
dataSourceConfig,
documentId,
documentText: documentContent,
documentContent: {
prefix: null,
content: documentContent,
sections: [],
},
documentUrl: file.webViewLink,
timestampMs: file.updatedAtMs,
tags,
Expand Down
6 changes: 5 additions & 1 deletion connectors/src/connectors/notion/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,11 @@ export async function renderAndUpsertPageFromCache({
workspaceAPIKey: connector.workspaceAPIKey,
},
documentId,
documentText: renderedPage,
documentContent: {
prefix: null,
content: renderedPage,
sections: [],
},
documentUrl: pageCacheEntry.url,
timestampMs: updatedTime,
tags: getTagsForPage({
Expand Down
12 changes: 10 additions & 2 deletions connectors/src/connectors/slack/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ export async function syncNonThreaded(
await upsertToDatasource({
dataSourceConfig,
documentId,
documentText: text,
documentContent: {
prefix: null,
content: text,
sections: [],
},
documentUrl: sourceUrl,
timestampMs: createdAt,
tags,
Expand Down Expand Up @@ -614,7 +618,11 @@ export async function syncThread(
await upsertToDatasource({
dataSourceConfig,
documentId,
documentText: text,
documentContent: {
prefix: null,
content: text,
sections: [],
},
documentUrl: sourceUrl,
timestampMs: createdAt,
tags,
Expand Down
16 changes: 10 additions & 6 deletions connectors/src/lib/data_sources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PostDataSourceDocumentRequestBody } from "@dust-tt/types";
import {
CoreAPIDataSourceDocumentSection,
PostDataSourceDocumentRequestBody,
sectionFullText,
} from "@dust-tt/types";
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";

import logger from "@connectors/logger/logger";
Expand All @@ -23,7 +27,7 @@ type UpsertContext = {
type UpsertToDataSourceParams = {
dataSourceConfig: DataSourceConfig;
documentId: string;
documentText: string;
documentContent: CoreAPIDataSourceDocumentSection;
documentUrl?: string;
timestampMs?: number;
tags?: string[];
Expand All @@ -37,7 +41,7 @@ export const upsertToDatasource = withRetries(_upsertToDatasource);
async function _upsertToDatasource({
dataSourceConfig,
documentId,
documentText,
documentContent,
documentUrl,
timestampMs,
tags,
Expand All @@ -49,7 +53,7 @@ async function _upsertToDatasource({
...loggerArgs,
documentId,
documentUrl,
documentLength: documentText.length,
documentLength: sectionFullText(documentContent).length,
workspaceId: dataSourceConfig.workspaceId,
dataSourceName: dataSourceConfig.dataSourceName,
});
Expand All @@ -66,8 +70,8 @@ async function _upsertToDatasource({
const urlSafeName = encodeURIComponent(dataSourceConfig.dataSourceName);
const endpoint = `${DUST_FRONT_API}/api/v1/w/${dataSourceConfig.workspaceId}/data_sources/${urlSafeName}/documents/${documentId}`;
const dustRequestPayload: PostDataSourceDocumentRequestBody = {
text: documentText,
section: null,
text: null,
section: documentContent,
source_url: documentUrl,
timestamp: timestampMs,
tags: tags?.map((tag) => tag.substring(0, 512)),
Expand Down

0 comments on commit 2aa97a7

Please sign in to comment.