From 3e781894e99a45ad07200476ffc86960b98d3088 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Wed, 18 Sep 2024 15:43:22 +0800 Subject: [PATCH 1/4] feat: use two agent for text2viz Agent 1: rule-based if user didn't provide any instructions Agent 2: no rules will be applied, only use user's instructions Signed-off-by: Yulong Ruan --- common/constants/llm.ts | 1 + server/routes/text2viz_routes.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/constants/llm.ts b/common/constants/llm.ts index 48da38fa..18477cae 100644 --- a/common/constants/llm.ts +++ b/common/constants/llm.ts @@ -45,4 +45,5 @@ export const DEFAULT_USER_NAME = 'User'; export const TEXT2VEGA_INPUT_SIZE_LIMIT = 400; export const TEXT2VEGA_AGENT_CONFIG_ID = 'os_text2vega'; +export const TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID = 'os_text2vega_with_instructions'; export const TEXT2PPL_AGENT_CONFIG_ID = 'os_query_assist_ppl'; diff --git a/server/routes/text2viz_routes.ts b/server/routes/text2viz_routes.ts index bf6b9cf9..d9595093 100644 --- a/server/routes/text2viz_routes.ts +++ b/server/routes/text2viz_routes.ts @@ -9,6 +9,7 @@ import { TEXT2PPL_AGENT_CONFIG_ID, TEXT2VEGA_AGENT_CONFIG_ID, TEXT2VEGA_INPUT_SIZE_LIMIT, + TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID, TEXT2VIZ_API, } from '../../common/constants/llm'; import { AssistantServiceSetup } from '../services/assistant_service'; @@ -42,7 +43,10 @@ export function registerText2VizRoutes(router: IRouter, assistantService: Assist router.handleLegacyErrors(async (context, req, res) => { const assistantClient = assistantService.getScopedClient(req, context); try { - const response = await assistantClient.executeAgentByConfigName(TEXT2VEGA_AGENT_CONFIG_ID, { + const agentConfigName = req.body.input_instruction + ? TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID + : TEXT2VEGA_AGENT_CONFIG_ID; + const response = await assistantClient.executeAgentByConfigName(agentConfigName, { input_question: req.body.input_question, input_instruction: req.body.input_instruction, ppl: req.body.ppl, From fcc2ca1def2d2df60cd245349c28045df200c23e Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Wed, 18 Sep 2024 15:50:08 +0800 Subject: [PATCH 2/4] feat: rename text2viz agent config name Signed-off-by: Yulong Ruan --- common/constants/llm.ts | 2 +- public/components/visualization/source_selector.tsx | 11 +++++++---- server/routes/text2viz_routes.ts | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/common/constants/llm.ts b/common/constants/llm.ts index 18477cae..c6988d28 100644 --- a/common/constants/llm.ts +++ b/common/constants/llm.ts @@ -44,6 +44,6 @@ export const DEFAULT_USER_NAME = 'User'; export const TEXT2VEGA_INPUT_SIZE_LIMIT = 400; -export const TEXT2VEGA_AGENT_CONFIG_ID = 'os_text2vega'; +export const TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID = 'os_text2vega'; export const TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID = 'os_text2vega_with_instructions'; export const TEXT2PPL_AGENT_CONFIG_ID = 'os_query_assist_ppl'; diff --git a/public/components/visualization/source_selector.tsx b/public/components/visualization/source_selector.tsx index f053a074..dbb2070b 100644 --- a/public/components/visualization/source_selector.tsx +++ b/public/components/visualization/source_selector.tsx @@ -14,7 +14,7 @@ import { DataSourceOption, } from '../../../../../src/plugins/data/public'; import { StartServices } from '../../types'; -import { TEXT2VEGA_AGENT_CONFIG_ID } from '../../../common/constants/llm'; +import { TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID } from '../../../common/constants/llm'; import { getAssistantService } from '../../services'; const DEFAULT_DATA_SOURCE_TYPE = 'DEFAULT_INDEX_PATTERNS'; @@ -114,9 +114,12 @@ export const SourceSelector = ({ * If not configured, disable the corresponding index pattern from the selection list */ Object.keys(dataSourceIdToIndexPatternIds).forEach(async (key) => { - const res = await assistantService.client.agentConfigExists(TEXT2VEGA_AGENT_CONFIG_ID, { - dataSourceId: key !== 'DEFAULT' ? key : undefined, - }); + const res = await assistantService.client.agentConfigExists( + TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID, + { + dataSourceId: key !== 'DEFAULT' ? key : undefined, + } + ); if (!res.exists) { dataSourceIdToIndexPatternIds[key].forEach((indexPatternId) => { indexPatternOptions.options.forEach((option) => { diff --git a/server/routes/text2viz_routes.ts b/server/routes/text2viz_routes.ts index d9595093..308808c5 100644 --- a/server/routes/text2viz_routes.ts +++ b/server/routes/text2viz_routes.ts @@ -7,7 +7,7 @@ import { schema } from '@osd/config-schema'; import { IRouter } from '../../../../src/core/server'; import { TEXT2PPL_AGENT_CONFIG_ID, - TEXT2VEGA_AGENT_CONFIG_ID, + TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID, TEXT2VEGA_INPUT_SIZE_LIMIT, TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID, TEXT2VIZ_API, @@ -45,7 +45,7 @@ export function registerText2VizRoutes(router: IRouter, assistantService: Assist try { const agentConfigName = req.body.input_instruction ? TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID - : TEXT2VEGA_AGENT_CONFIG_ID; + : TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID; const response = await assistantClient.executeAgentByConfigName(agentConfigName, { input_question: req.body.input_question, input_instruction: req.body.input_instruction, From 2ac85004cf0e3662cf8055d14ca3914982f63b18 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Fri, 20 Sep 2024 10:37:10 +0800 Subject: [PATCH 3/4] check all required agents for t2viz Signed-off-by: Yulong Ruan --- .../components/visualization/source_selector.tsx | 14 +++++++++++--- public/services/assistant_client.ts | 5 +++-- server/routes/agent_routes.ts | 10 +++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/public/components/visualization/source_selector.tsx b/public/components/visualization/source_selector.tsx index dbb2070b..90438a4e 100644 --- a/public/components/visualization/source_selector.tsx +++ b/public/components/visualization/source_selector.tsx @@ -14,7 +14,11 @@ import { DataSourceOption, } from '../../../../../src/plugins/data/public'; import { StartServices } from '../../types'; -import { TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID } from '../../../common/constants/llm'; +import { + TEXT2PPL_AGENT_CONFIG_ID, + TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID, + TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID, +} from '../../../common/constants/llm'; import { getAssistantService } from '../../services'; const DEFAULT_DATA_SOURCE_TYPE = 'DEFAULT_INDEX_PATTERNS'; @@ -110,12 +114,16 @@ export const SourceSelector = ({ const assistantService = getAssistantService(); /** - * Check each data source to see if text to vega agent is configured or not + * Check each data source to see if text to vega agents are configured or not * If not configured, disable the corresponding index pattern from the selection list */ Object.keys(dataSourceIdToIndexPatternIds).forEach(async (key) => { const res = await assistantService.client.agentConfigExists( - TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID, + [ + TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID, + TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID, + TEXT2PPL_AGENT_CONFIG_ID, + ], { dataSourceId: key !== 'DEFAULT' ? key : undefined, } diff --git a/public/services/assistant_client.ts b/public/services/assistant_client.ts index 624b86d8..1d151a9b 100644 --- a/public/services/assistant_client.ts +++ b/public/services/assistant_client.ts @@ -38,9 +38,10 @@ export class AssistantClient { }; /** - * Return if the given agent config name has agent id configured + * Check if the given agent config name has agent id configured + * Return false if any of the given config name has no agent id configured */ - agentConfigExists = (agentConfigName: string, options?: Options) => { + agentConfigExists = (agentConfigName: string | string[], options?: Options) => { return this.http.fetch<{ exists: boolean }>({ method: 'GET', path: AGENT_API.CONFIG_EXISTS, diff --git a/server/routes/agent_routes.ts b/server/routes/agent_routes.ts index abbbd087..227143a7 100644 --- a/server/routes/agent_routes.ts +++ b/server/routes/agent_routes.ts @@ -51,7 +51,7 @@ export function registerAgentRoutes(router: IRouter, assistantService: Assistant query: schema.oneOf([ schema.object({ dataSourceId: schema.maybe(schema.string()), - agentConfigName: schema.string(), + agentConfigName: schema.oneOf([schema.string(), schema.arrayOf(schema.string())]), }), ]), }, @@ -59,8 +59,12 @@ export function registerAgentRoutes(router: IRouter, assistantService: Assistant router.handleLegacyErrors(async (context, req, res) => { try { const assistantClient = assistantService.getScopedClient(req, context); - const agentId = await assistantClient.getAgentIdByConfigName(req.query.agentConfigName); - return res.ok({ body: { exists: Boolean(agentId) } }); + const promises = Array() + .concat(req.query.agentConfigName) + .map((configName) => assistantClient.getAgentIdByConfigName(configName)); + const results = await Promise.all(promises); + const exists = results.every((r) => Boolean(r)); + return res.ok({ body: { exists } }); } catch (e) { return res.ok({ body: { exists: false } }); } From a361f4b4b106423d37da4e39a71bd3519416be56 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Fri, 20 Sep 2024 10:41:23 +0800 Subject: [PATCH 4/4] add changelogs Signed-off-by: Yulong Ruan --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b428ae7..4f4b4759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - feat: added a new visualization type visualization-nlq to support creating visualization from natural language([#264](https://github.com/opensearch-project/dashboards-assistant/pull/264)) - feat: only allow to select supported index patterns in text to visualization and code changes related to prompt updates([#310](https://github.com/opensearch-project/dashboards-assistant/pull/310)) - feat: exposed an API to check if a give agent config name has configured with agent id([#307](https://github.com/opensearch-project/dashboards-assistant/pull/307)) +- feat: check all required agents before enabling index pattern selection for text to visualization([313](https://github.com/opensearch-project/dashboards-assistant/pull/313)) ### 📈 Features/Enhancements