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

Assistant: Lib function createAgentConfiguration #1303

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 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
3 changes: 1 addition & 2 deletions front/admin/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ async function main() {
await ExtractedEvent.sync({ alter: true });
await DocumentTrackerChangeSuggestion.sync({ alter: true });

await AgentConfiguration.sync({ alter: true });
await AgentGenerationConfiguration.sync({ alter: true });

await AgentRetrievalConfiguration.sync({ alter: true });
await AgentDataSourceConfiguration.sync({ alter: true });
await AgentConfiguration.sync({ alter: true });
await AgentRetrievalAction.sync({ alter: true });
await RetrievalDocument.sync({ alter: true });
await RetrievalDocumentChunk.sync({ alter: true });
Expand Down
76 changes: 24 additions & 52 deletions front/lib/api/assistant/actions/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import { Err, Ok, Result } from "@app/lib/result";
import { new_id } from "@app/lib/utils";
import logger from "@app/logger/logger";
import {
DataSourceConfiguration,
isRetrievalConfiguration,
RetrievalActionType,
RetrievalConfigurationType,
RetrievalDocumentType,
TimeFrame,
} from "@app/types/assistant/actions/retrieval";
import {
AgentActionSpecification,
AgentConfigurationType,
} from "@app/types/assistant/agent";
AgentDataSourceConfigurationType,
isRetrievalConfiguration,
RetrievalConfigurationType,
} from "@app/types/assistant/actions/retrieval";
import { AgentActionSpecification } from "@app/types/assistant/agent";
import { AgentConfigurationType } from "@app/types/assistant/configuration";
import {
AgentMessageType,
ConversationType,
Expand Down Expand Up @@ -273,7 +273,7 @@ export type RetrievalParamsEvent = {
created: number;
configurationId: string;
messageId: string;
dataSources: "all" | DataSourceConfiguration[];
dataSources: AgentDataSourceConfigurationType[];
query: string | null;
relativeTimeFrame: TimeFrame | null;
topK: number;
Expand Down Expand Up @@ -387,56 +387,28 @@ export async function* runRetrieval(
);

// Handle data sources list and parents/tags filtering.
if (c.dataSources === "all") {
const prodCredentials = await prodAPICredentialsForOwner(owner);
const api = new DustAPI(prodCredentials);
config.DATASOURCE.data_sources = c.dataSources.map((d) => ({
workspace_id: d.workspaceId,
data_source_id: d.dataSourceId,
}));

for (const ds of c.dataSources) {
if (ds.filter.tags) {
if (!config.DATASOURCE.filter.tags) {
config.DATASOURCE.filter.tags = { in: [], not: [] };
}

const dsRes = await api.getDataSources(prodCredentials.workspaceId);
if (dsRes.isErr()) {
return yield {
type: "retrieval_error",
created: Date.now(),
configurationId: configuration.sId,
messageId: agentMessage.sId,
error: {
code: "retrieval_data_sources_error",
message: `Error retrieving workspace data sources: ${dsRes.error.message}`,
},
};
config.DATASOURCE.filter.tags.in.push(...ds.filter.tags.in);
config.DATASOURCE.filter.tags.not.push(...ds.filter.tags.not);
}

const ds = dsRes.value.filter((d) => d.assistantDefaultSelected);

config.DATASOURCE.data_sources = ds.map((d) => {
return {
workspace_id: prodCredentials.workspaceId,
data_source_id: d.name,
};
});
} else {
config.DATASOURCE.data_sources = c.dataSources.map((d) => ({
workspace_id: d.workspaceId,
data_source_id: d.dataSourceId,
PopDaph marked this conversation as resolved.
Show resolved Hide resolved
}));

for (const ds of c.dataSources) {
if (ds.filter.tags) {
if (!config.DATASOURCE.filter.tags) {
config.DATASOURCE.filter.tags = { in: [], not: [] };
}

config.DATASOURCE.filter.tags.in.push(...ds.filter.tags.in);
config.DATASOURCE.filter.tags.not.push(...ds.filter.tags.not);
if (ds.filter.parents) {
if (!config.DATASOURCE.filter.parents) {
config.DATASOURCE.filter.parents = { in: [], not: [] };
}

if (ds.filter.parents) {
if (!config.DATASOURCE.filter.parents) {
config.DATASOURCE.filter.parents = { in: [], not: [] };
}

config.DATASOURCE.filter.parents.in.push(...ds.filter.parents.in);
config.DATASOURCE.filter.parents.not.push(...ds.filter.parents.not);
}
config.DATASOURCE.filter.parents.in.push(...ds.filter.parents.in);
config.DATASOURCE.filter.parents.not.push(...ds.filter.parents.not);
}
}

Expand Down
64 changes: 2 additions & 62 deletions front/lib/api/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,15 @@ import { Authenticator } from "@app/lib/auth";
import { Err, Ok, Result } from "@app/lib/result";
import { generateModelSId } from "@app/lib/utils";
import { isRetrievalConfiguration } from "@app/types/assistant/actions/retrieval";
import {
AgentActionConfigurationType,
AgentActionSpecification,
AgentConfigurationStatus,
AgentConfigurationType,
AgentGenerationConfigurationType,
} from "@app/types/assistant/agent";
import { AgentActionSpecification } from "@app/types/assistant/agent";
import { AgentConfigurationType } from "@app/types/assistant/configuration";
import {
AgentActionType,
AgentMessageType,
ConversationType,
UserMessageType,
} from "@app/types/assistant/conversation";

/**
* Agent configuration.
*/

export async function createAgentConfiguration(
auth: Authenticator,
{
name,
pictureUrl,
action,
generation,
}: {
name: string;
pictureUrl?: string;
action?: AgentActionConfigurationType;
generation?: AgentGenerationConfigurationType;
}
): Promise<AgentConfigurationType> {
return {
sId: generateModelSId(),
name,
pictureUrl: pictureUrl ?? null,
status: "active",
action: action ?? null,
generation: generation ?? null,
};
}

export async function updateAgentConfiguration(
auth: Authenticator,
configurationId: string,
{
name,
pictureUrl,
status,
action,
generation,
}: {
name: string;
pictureUrl?: string;
status: AgentConfigurationStatus;
action?: AgentActionConfigurationType;
generation?: AgentGenerationConfigurationType;
}
): Promise<AgentConfigurationType> {
return {
sId: generateModelSId(),
name,
pictureUrl: pictureUrl ?? null,
status,
action: action ?? null,
generation: generation ?? null,
};
}

/**
* Action Inputs generation.
*/
Expand Down
Loading