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

Support log pattern if there is dsl and index passed for alert summary. #339

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Support insight with RAG in alert analysis assistant and refine the UX ([#266](https://github.com/opensearch-project/dashboards-assistant/pull/266))
- Add assistant enabled capabilities to control rendering component([#267](https://github.com/opensearch-project/dashboards-assistant/pull/267))
- Add data to summary API([#295](https://github.com/opensearch-project/dashboards-assistant/pull/295))
- Refactor popover to add message action bar and add metrics to thumb-up and thumb-down([#304](https://github.com/opensearch-project/dashboards-assistant/pull/304))
- Refactor popover to add message action bar and add metrics to thumb-up and thumb-down([#304](https://github.com/opensearch-project/dashboards-assistant/pull/304))
- Support log pattern analysis ([#339](https://github.com/opensearch-project/dashboards-assistant/pull/339))
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export const GeneratePopoverBody: React.FC<{
? 'os_insight'
: 'user_insight'
: undefined;
const index = contextObj?.additionalInfo?.index;
const dsl = contextObj?.additionalInfo?.dsl;

await httpSetup
?.post(SUMMARY_ASSISTANT_API.SUMMARIZE, {
Expand All @@ -110,6 +112,8 @@ export const GeneratePopoverBody: React.FC<{
insightType,
question: summarizationQuestion,
context: contextContent,
index,
dsl,
}),
query: dataSourceQuery,
})
Expand Down
18 changes: 13 additions & 5 deletions server/routes/summary_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getAgentIdByConfigName, searchAgent } from './get_agent';
import { AssistantServiceSetup } from '../services/assistant_service';

const SUMMARY_AGENT_CONFIG_ID = 'os_summary';
const LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID = 'os_summary_with_logPattern';
const OS_INSIGHT_AGENT_CONFIG_ID = 'os_insight';
const DATA2SUMMARY_AGENT_CONFIG_ID = 'os_data2summary';
let osInsightAgentId: string | undefined;
Expand All @@ -29,6 +30,8 @@ export function registerSummaryAssistantRoutes(
insightType: schema.maybe(schema.string()),
question: schema.string(),
context: schema.maybe(schema.string()),
index: schema.maybe(schema.string()),
dsl: schema.maybe(schema.string()),
}),
query: schema.object({
dataSourceId: schema.maybe(schema.string()),
Expand All @@ -41,9 +44,15 @@ export function registerSummaryAssistantRoutes(
dataSourceId: req.query.dataSourceId,
});
const assistantClient = assistantService.getScopedClient(req, context);
const response = await assistantClient.executeAgentByConfigName(SUMMARY_AGENT_CONFIG_ID, {
const agentConfigId =
req.body.index && req.body.dsl
? LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID
: SUMMARY_AGENT_CONFIG_ID;
const response = await assistantClient.executeAgentByConfigName(agentConfigId, {
context: req.body.context,
question: req.body.question,
index: req.body.index,
input: req.body.dsl,
});
let summary;
let insightAgentIdExists = false;
Expand Down Expand Up @@ -114,14 +123,13 @@ export function registerSummaryAssistantRoutes(
question: req.body.question,
});
try {
let result = response.body.inference_results[0].output[0].result;
result = JSON.parse(result).output.text;
return res.ok({ body: result });
return res.ok({ body: response.body.inference_results[0].output[0].result });
Copy link
Member

@ruanyl ruanyl Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So both agents(tools): LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID and SUMMARY_AGENT_CONFIG_ID has changed the output from plain text to json?
Never mind, it seems the output structure changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Only os_insight agent has change its output structure from json to text. Because there is a post function added in connector:

"post_process_function": "return params.output.text;"

} catch (e) {
return res.internalError();
} finally {
// Reset userInsightAgentId in case users update their insight agent.
// Reset both agents id in case of update
userInsightAgentId = undefined;
osInsightAgentId = undefined;
}
})
);
Expand Down
Loading