Skip to content

Commit

Permalink
Merge branch 'alertingInsight' of https://github.com/000FLMS/dashboar…
Browse files Browse the repository at this point in the history
…ds-assistant into alertingInsight
  • Loading branch information
000FLMS committed Sep 20, 2024
2 parents c209f93 + e99cfd9 commit 0bb77d8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion common/constants/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +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';
21 changes: 16 additions & 5 deletions public/components/visualization/source_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
DataSourceOption,
} from '../../../../../src/plugins/data/public';
import { StartServices } from '../../types';
import { TEXT2VEGA_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';
Expand Down Expand Up @@ -110,13 +114,20 @@ 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_AGENT_CONFIG_ID, {
dataSourceId: key !== 'DEFAULT' ? key : undefined,
});
const res = await assistantService.client.agentConfigExists(
[
TEXT2VEGA_RULE_BASED_AGENT_CONFIG_ID,
TEXT2VEGA_WITH_INSTRUCTIONS_AGENT_CONFIG_ID,
TEXT2PPL_AGENT_CONFIG_ID,
],
{
dataSourceId: key !== 'DEFAULT' ? key : undefined,
}
);
if (!res.exists) {
dataSourceIdToIndexPatternIds[key].forEach((indexPatternId) => {
indexPatternOptions.options.forEach((option) => {
Expand Down
5 changes: 3 additions & 2 deletions public/services/assistant_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions server/routes/agent_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ 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())]),
}),
]),
},
},
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<string>()
.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 } });
}
Expand Down
8 changes: 6 additions & 2 deletions server/routes/text2viz_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ 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,
} from '../../common/constants/llm';
import { AssistantServiceSetup } from '../services/assistant_service';
Expand Down Expand Up @@ -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_RULE_BASED_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,
Expand Down

0 comments on commit 0bb77d8

Please sign in to comment.