Skip to content

Commit

Permalink
[Websearch] Add no-op websearch action (builder, rendering), gated (#…
Browse files Browse the repository at this point in the history
…5230)

* [Websearch] Add no-op websearch action (builder, rendering), gated

Description
---
This PR follows #5224 that introduced types and models for websearch.

It adds the websearch action to union action types, and creates the
necessary boilerplate.

Following PRs will implement each part: action execution, action
rendering, action configuration in builder

Risk
---
None, since gated

Deployment plan
---
Front

* remove useless transaction

* spolu coms

* clean

* implement new action pattern

* flav review
  • Loading branch information
philipperolet authored May 23, 2024
1 parent 837fe9f commit 8a2c03a
Show file tree
Hide file tree
Showing 20 changed files with 320 additions and 5 deletions.
8 changes: 8 additions & 0 deletions front/components/assistant/conversation/AgentAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
isProcessActionType,
isRetrievalActionType,
isTablesQueryActionType,
isWebsearchActionType,
} from "@dust-tt/types";

import DustAppRunAction from "@app/components/assistant/conversation/DustAppRunAction";
import ProcessAction from "@app/components/assistant/conversation/ProcessAction";
import RetrievalAction from "@app/components/assistant/conversation/RetrievalAction";
import TablesQueryAction from "@app/components/assistant/conversation/TablesQueryAction";
import WebsearchAction from "@app/components/assistant/conversation/WebsearchAction";

export function AgentAction({ action }: { action: AgentActionType }) {
if (isRetrievalActionType(action)) {
Expand All @@ -37,6 +39,12 @@ export function AgentAction({ action }: { action: AgentActionType }) {
<ProcessAction processAction={action} />
</div>
);
} else if (isWebsearchActionType(action)) {
return (
<div className="pb-4">
<WebsearchAction websearchAction={action} />
</div>
);
} else {
assertNever(action);
}
Expand Down
16 changes: 16 additions & 0 deletions front/components/assistant/conversation/WebsearchAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { WebsearchActionType } from "@dust-tt/types/dist/front/assistant/actions/websearch";

// TODO(pr,websearch) Implement this function
export default function WebsearchAction({
websearchAction,
}: {
websearchAction: WebsearchActionType;
}) {
return (
<>
<div>
Action to be implemented here: {JSON.stringify(websearchAction)}
</div>
</>
);
}
22 changes: 20 additions & 2 deletions front/components/assistant_builder/ActionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ import { useDeprecatedDefaultSingleAction } from "@app/lib/client/assistant_buil

import { ActionDustAppRun } from "./actions/DustAppRunAction";

const BASIC_ACTION_CATEGORIES = ["REPLY_ONLY", "USE_DATA_SOURCES"] as const;
const BASIC_ACTION_CATEGORIES = [
"REPLY_ONLY",
"USE_DATA_SOURCES",
"WEBSEARCH",
] as const;
const ADVANCED_ACTION_CATEGORIES = ["RUN_DUST_APP"] as const;

type ActionCategory =
Expand All @@ -59,6 +63,7 @@ const ACTION_CATEGORY_SPECIFICATIONS: Record<
icon: ComponentType;
description: string;
defaultActionType: AssistantBuilderActionType | null;
flag?: WhitelistableFeature | null;
}
> = {
REPLY_ONLY: {
Expand All @@ -79,6 +84,13 @@ const ACTION_CATEGORY_SPECIFICATIONS: Record<
description: "Run a Dust app, then reply",
defaultActionType: "DUST_APP_RUN",
},
WEBSEARCH: {
label: "Web search",
icon: MagnifyingGlassIcon,
description: "Perform a web search",
defaultActionType: "WEBSEARCH",
flag: "websearch_action",
},
};

const SEARCH_MODE_SPECIFICATIONS: Record<
Expand Down Expand Up @@ -159,6 +171,8 @@ export default function ActionScreen({
return "USE_DATA_SOURCES";
case "DUST_APP_RUN":
return "RUN_DUST_APP";
case "WEBSEARCH":
return "WEBSEARCH";
default:
assertNever(actionType);
}
Expand All @@ -176,6 +190,7 @@ export default function ActionScreen({
return "PROCESS";

case null:
case "WEBSEARCH":
case "DUST_APP_RUN":
// Unused for non data sources related actions.
return "RETRIEVAL_SEARCH";
Expand Down Expand Up @@ -227,7 +242,10 @@ export default function ActionScreen({
/>
</DropdownMenu.Button>
<DropdownMenu.Items origin="topLeft" width={260}>
{BASIC_ACTION_CATEGORIES.map((key) => {
{BASIC_ACTION_CATEGORIES.filter((key) => {
const flag = ACTION_CATEGORY_SPECIFICATIONS[key].flag;
return !flag || owner.flags.includes(flag);
}).map((key) => {
const spec = ACTION_CATEGORY_SPECIFICATIONS[key];
const defaultAction = getDefaultActionConfiguration(
spec.defaultActionType
Expand Down
15 changes: 15 additions & 0 deletions front/components/assistant_builder/ActionsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import {
ActionTablesQuery,
isActionTablesQueryValid,
} from "@app/components/assistant_builder/actions/TablesQueryAction";
import {
ActionWebsearch,
isActionWebsearchValid,
} from "@app/components/assistant_builder/actions/WebsearchAction";
import type {
AssistantBuilderActionConfiguration,
AssistantBuilderDustAppConfiguration,
Expand Down Expand Up @@ -102,6 +106,13 @@ const ACTION_SPECIFICATIONS: Record<
dropDownIcon: TableStrokeIcon,
flag: null,
},
WEBSEARCH: {
label: "Web search",
description: "Perform a web search",
cardIcon: MagnifyingGlassStrokeIcon,
dropDownIcon: MagnifyingGlassIcon,
flag: "websearch_action",
},
};

const DATA_SOURCES_ACTION_CATEGORIES = [
Expand Down Expand Up @@ -139,6 +150,8 @@ export function isActionValid(
return isActionDustAppRunValid(action);
case "TABLES_QUERY":
return isActionTablesQueryValid(action);
case "WEBSEARCH":
return isActionWebsearchValid(action);
default:
assertNever(action);
}
Expand Down Expand Up @@ -613,6 +626,8 @@ function ActionEditor({
setEdited={setEdited}
/>
);
case "WEBSEARCH":
return <ActionWebsearch />;
default:
assertNever(action);
}
Expand Down
7 changes: 7 additions & 0 deletions front/components/assistant_builder/AssistantBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@ export async function submitAssistantBuilderForm({
tables: Object.values(a.configuration),
};

case "WEBSEARCH":
return {
type: "websearch_configuration",
name: a.name,
description: a.description,
};

case "PROCESS":
return {
type: "process_configuration",
Expand Down
18 changes: 18 additions & 0 deletions front/components/assistant_builder/actions/WebsearchAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { AssistantBuilderActionConfiguration } from "@app/components/assistant_builder/types";

export function isActionWebsearchValid(
action: AssistantBuilderActionConfiguration
) {
return (
action.type === "WEBSEARCH" && Object.keys(action.configuration).length > 0
);
}

export function ActionWebsearch() {
return (
<div>
This action will perform a web search and return the top results (title,
link and summary) to the assistant.
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
isProcessConfiguration,
isRetrievalConfiguration,
isTablesQueryConfiguration,
isWebsearchConfiguration,
} from "@dust-tt/types";

import type {
Expand All @@ -28,6 +29,7 @@ import {
getDefaultRetrievalExhaustiveActionConfiguration,
getDefaultRetrievalSearchActionConfiguration,
getDefaultTablesQueryActionConfiguration,
getDefaultWebsearchActionConfiguration,
} from "@app/components/assistant_builder/types";
import { tableKey } from "@app/lib/client/tables_query";
import logger from "@app/logger/logger";
Expand Down Expand Up @@ -197,6 +199,8 @@ export async function buildInitialActions({
processConfiguration.configuration.schema = action.schema;

builderAction = processConfiguration;
} else if (isWebsearchConfiguration(action)) {
builderAction = getDefaultWebsearchActionConfiguration();
} else {
assertNever(action);
}
Expand Down
23 changes: 23 additions & 0 deletions front/components/assistant_builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export type AssistantBuilderProcessConfiguration = {
schema: ProcessSchemaPropertyType[];
};

// Websearch configuration

export type AssistantBuilderWebsearchConfiguration = {
searchResults: 8; // not configurable at the time of writing, placeholder
};

// Builder State

export type AssistantBuilderActionConfiguration = (
Expand All @@ -94,6 +100,10 @@ export type AssistantBuilderActionConfiguration = (
type: "PROCESS";
configuration: AssistantBuilderProcessConfiguration;
}
| {
type: "WEBSEARCH";
configuration: AssistantBuilderWebsearchConfiguration;
}
) & {
name: string;
description: string;
Expand Down Expand Up @@ -217,6 +227,17 @@ export function getDefaultProcessActionConfiguration() {
} satisfies AssistantBuilderActionConfiguration;
}

export function getDefaultWebsearchActionConfiguration(): AssistantBuilderActionConfiguration {
return {
type: "WEBSEARCH",
configuration: {
searchResults: 8,
},
name: "websearch",
description: "Perform a web search.",
};
}

export function getDefaultActionConfiguration(
actionType: AssistantBuilderActionType | null
): AssistantBuilderActionConfiguration | null {
Expand All @@ -233,6 +254,8 @@ export function getDefaultActionConfiguration(
return getDefaultTablesQueryActionConfiguration();
case "PROCESS":
return getDefaultProcessActionConfiguration();
case "WEBSEARCH":
return getDefaultWebsearchActionConfiguration();
default:
assertNever(actionType);
}
Expand Down
5 changes: 5 additions & 0 deletions front/lib/api/assistant/actions/runners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DustAppRunConfigurationType,
ProcessConfigurationType,
} from "@dust-tt/types";
import type { WebsearchConfigurationType } from "@dust-tt/types/dist/front/assistant/actions/websearch";

import { DustAppRunConfigurationServerRunner } from "@app/lib/api/assistant/actions/dust_app_run";
import { ProcessConfigurationServerRunner } from "@app/lib/api/assistant/actions/process";
Expand All @@ -11,16 +12,19 @@ import type {
BaseActionConfigurationServerRunnerConstructor,
BaseActionConfigurationStaticMethods,
} from "@app/lib/api/assistant/actions/types";
import { WebsearchConfigurationServerRunner } from "@app/lib/api/assistant/actions/websearch";

interface ActionToConfigTypeMap {
dust_app_run_configuration: DustAppRunConfigurationType;
process_configuration: ProcessConfigurationType;
websearch_configuration: WebsearchConfigurationType;
// Add other configurations once migrated to classes.
}

interface ActionTypeToClassMap {
dust_app_run_configuration: DustAppRunConfigurationServerRunner;
process_configuration: ProcessConfigurationServerRunner;
websearch_configuration: WebsearchConfigurationServerRunner;
}

// Ensure all AgentAction keys are present in ActionToConfigTypeMap.
Expand Down Expand Up @@ -61,6 +65,7 @@ export const ACTION_TYPE_TO_CONFIGURATION_SERVER_RUNNER: {
} = {
dust_app_run_configuration: DustAppRunConfigurationServerRunner,
process_configuration: ProcessConfigurationServerRunner,
websearch_configuration: WebsearchConfigurationServerRunner,
} as const;

export function getRunnerforActionConfiguration<K extends keyof CombinedMap>(
Expand Down
54 changes: 54 additions & 0 deletions front/lib/api/assistant/actions/websearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { AgentActionSpecification, Result } from "@dust-tt/types";
import { Ok } from "@dust-tt/types";
import type { WebsearchConfigurationType } from "@dust-tt/types/dist/front/assistant/actions/websearch";

import type { BaseActionRunParams } from "@app/lib/api/assistant/actions/types";
import { BaseActionConfigurationServerRunner } from "@app/lib/api/assistant/actions/types";
import type { Authenticator } from "@app/lib/auth";

/**
* Params generation.
*/

export class WebsearchConfigurationServerRunner extends BaseActionConfigurationServerRunner<WebsearchConfigurationType> {
async buildSpecification(
auth: Authenticator,
{
name,
description,
}: { name?: string | undefined; description?: string | undefined }
): Promise<Result<AgentActionSpecification, Error>> {
const owner = auth.workspace();
if (!owner) {
throw new Error(
"Unexpected unauthenticated call to `runWebsearchAction`"
);
}

return new Ok({
name: name ?? "web_search",
description:
description ?? "Perform a web search and return the top results.",
inputs: [
{
name: "query",
description: "The query used to perform the web search.",
type: "string",
},
],
});
}

run(
auth: Authenticator,
runParams: BaseActionRunParams,
customParams: Record<string, unknown>
): AsyncGenerator<unknown, any, unknown> {
throw new Error(
"Method not implemented." +
JSON.stringify(runParams) +
JSON.stringify(customParams) +
JSON.stringify(auth)
);
}
}
Loading

0 comments on commit 8a2c03a

Please sign in to comment.