Skip to content

Commit

Permalink
table query
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu committed Sep 20, 2024
1 parent 84b1ed1 commit 578eb0f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
29 changes: 24 additions & 5 deletions front/lib/api/assistant/actions/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
PROCESS_ACTION_TOP_K,
renderSchemaPropertiesAsJSONSchema,
} from "@dust-tt/types";
import assert from "assert";

import { runActionStreamed } from "@app/lib/actions/server";
import { DEFAULT_PROCESS_ACTION_NAME } from "@app/lib/api/assistant/actions/names";
Expand All @@ -41,6 +42,7 @@ import {
DustProdActionRegistry,
PRODUCTION_DUST_WORKSPACE_ID,
} from "@app/lib/registry";
import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource";
import logger from "@app/logger/logger";

interface ProcessActionBlob {
Expand Down Expand Up @@ -241,6 +243,17 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
hasAvailableActions: false,
});

const uniqueDataSourceViewIds = Array.from(
new Set(actionConfiguration.dataSources.map((ds) => ds.dataSourceViewId))
);
const dataSourceViews = await DataSourceViewResource.fetchByIds(
auth,
uniqueDataSourceViewIds
);
const dataSourceViewsMap = Object.fromEntries(
dataSourceViews.map((dsv) => [dsv.sId, dsv])
);

const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-process"].config
);
Expand All @@ -258,9 +271,9 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
? PRODUCTION_DUST_WORKSPACE_ID
: d.workspaceId,

// Use dataSourceViewId if it exists; otherwise, use dataSourceId.
// Note: This value is passed to the registry for lookup.
data_source_id: d.dataSourceViewId ?? d.dataSourceId,
// Note: This value is passed to the registry for lookup. The registry will return the
// associated data source's dustAPIDataSourceId.
data_source_id: d.dataSourceViewId,
})
);

Expand All @@ -286,10 +299,16 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
config.DATASOURCE.filter.parents.in_map = {};
}

const dsView = dataSourceViewsMap[ds.dataSourceViewId];
// This should never happen since dataSourceViews are stored by id in the
// agent_data_source_configurations table.
assert(dsView, `Data source view ${ds.dataSourceViewId} not found`);

// Note: We use dataSourceId here because after the registry lookup,
// it returns either the data source itself or the data source associated with the data source view.
config.DATASOURCE.filter.parents.in_map[ds.dataSourceId] =
ds.filter.parents.in;
config.DATASOURCE.filter.parents.in_map[
dsView.dataSource.dustAPIDataSourceId
] = ds.filter.parents.in;
}
if (ds.filter.parents?.not) {
if (!config.DATASOURCE.filter.parents.not) {
Expand Down
21 changes: 7 additions & 14 deletions front/lib/api/assistant/actions/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,32 +389,31 @@ export class RetrievalConfigurationServerRunner extends BaseActionConfigurationS

const now = Date.now();

// "assistant-v2-retrieval" has no model interaction.
const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-retrieval"].config
);

const uniqueDataSourceViewIds = Array.from(
new Set(actionConfiguration.dataSources.map((ds) => ds.dataSourceViewId))
);

const dataSourceViews = await DataSourceViewResource.fetchByIds(
auth,
uniqueDataSourceViewIds
);

const dataSourceViewsMap = Object.fromEntries(
dataSourceViews.map((dsv) => [dsv.sId, dsv])
);

// "assistant-v2-retrieval" has no model interaction.
const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-retrieval"].config
);

// Handle data sources list and parents/tags filtering.
config.DATASOURCE.data_sources = actionConfiguration.dataSources.map(
(d) => ({
workspace_id:
isDevelopment() && !apiConfig.getDevelopmentDustAppsWorkspaceId()
? PRODUCTION_DUST_WORKSPACE_ID
: d.workspaceId,
// Note: This value is passed to the registry for lookup.
// Note: This value is passed to the registry for lookup. The registry will return the
// associated data source's dustAPIDataSourceId.
data_source_id: d.dataSourceViewId,
})
);
Expand Down Expand Up @@ -508,7 +507,6 @@ export class RetrievalConfigurationServerRunner extends BaseActionConfigurationS
// This is not perfect and will be erroneous in case of two data sources with the same id from
// two different workspaces. We don't support cross workspace data sources right now. But we'll
// likely want `core` to return the `workspace_id` that was used eventualy.
// TODO(spolu): make `core` return data source workspace id.
const dustAPIDataSourcesIdToDetails = Object.fromEntries(
actionConfiguration.dataSources.map((ds) => [
dataSourceViewsMap[ds.dataSourceViewId].dataSource.dustAPIDataSourceId,
Expand Down Expand Up @@ -619,11 +617,6 @@ export class RetrievalConfigurationServerRunner extends BaseActionConfigurationS
const details = dustAPIDataSourcesIdToDetails[d.data_source_id];
assert(details, `Data source view ${d.data_source_id} not found`);

console.log(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
);
console.log(details);

return {
blob: {
dataSourceWorkspaceId: details.workspaceId,
Expand Down
4 changes: 3 additions & 1 deletion front/lib/api/assistant/actions/tables_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ export class TablesQueryConfigurationServerRunner extends BaseActionConfiguratio
const tables = actionConfiguration.tables.map((t) => ({
workspace_id: t.workspaceId,
table_id: t.tableId,
data_source_id: t.dataSourceId,
// Note: This value is passed to the registry for lookup. The registry will return the
// associated data source's dustAPIDataSourceId.
data_source_id: t.dataSourceViewId,
}));
if (tables.length === 0) {
yield {
Expand Down
1 change: 0 additions & 1 deletion types/src/front/assistant/actions/tables_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type TablesQueryConfigurationType = {
};

export type TableDataSourceConfiguration = {
dataSourceId: string;
dataSourceViewId: string;
tableId: string;
workspaceId: string;
Expand Down

0 comments on commit 578eb0f

Please sign in to comment.