Skip to content

Commit

Permalink
Support log pattern if there is dsl and index passed for alert summar…
Browse files Browse the repository at this point in the history
…y. (#339) (#340)

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

Signed-off-by: Heng Qian <[email protected]>

* Add CHANGELOG.md

Signed-off-by: Heng Qian <[email protected]>

---------

Signed-off-by: Heng Qian <[email protected]>
(cherry picked from commit 5c32cca)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent e4231cc commit 6ab517e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions public/components/incontext_insight/generate_popover_body.tsx
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 });
} 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

0 comments on commit 6ab517e

Please sign in to comment.