Skip to content

Commit

Permalink
Add discovery summary API (#295) (#306)
Browse files Browse the repository at this point in the history
* Add discovery summary API

Signed-off-by: Liyun Xiu <[email protected]>

* Remove local change

Signed-off-by: Liyun Xiu <[email protected]>

* Update changelog

Signed-off-by: Liyun Xiu <[email protected]>

---------

Signed-off-by: Liyun Xiu <[email protected]>
(cherry picked from commit b72ba97)
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 decb58e commit cf65633
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions common/constants/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const AGENT_API = {
export const SUMMARY_ASSISTANT_API = {
SUMMARIZE: `${API_BASE}/summary`,
INSIGHT: `${API_BASE}/insight`,
DATA2SUMMARY: `${API_BASE}/data2summary`,
};

export const NOTEBOOK_API = {
Expand Down
5 changes: 4 additions & 1 deletion server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { registerChatRoutes } from './routes/chat_routes';
import { registerText2VizRoutes } from './routes/text2viz_routes';
import { AssistantService } from './services/assistant_service';
import { registerAgentRoutes } from './routes/agent_routes';
import { registerSummaryAssistantRoutes } from './routes/summary_routes';
import { registerSummaryAssistantRoutes, registerData2SummaryRoutes } from './routes/summary_routes';
import { capabilitiesProvider as visNLQCapabilitiesProvider } from './vis_type_nlq/capabilities_provider';
import { visNLQSavedObjectType } from './vis_type_nlq/saved_object_type';
import { capabilitiesProvider } from './capabilities';
Expand Down Expand Up @@ -72,6 +72,9 @@ export class AssistantPlugin implements Plugin<AssistantPluginSetup, AssistantPl
}

core.capabilities.registerProvider(capabilitiesProvider);

// Register router for discovery summary
registerData2SummaryRoutes(router, assistantServiceSetup);

const registerMessageParser = (messageParser: MessageParser) => {
const findItem = this.messageParsers.find((item) => item.id === messageParser.id);
Expand Down
37 changes: 37 additions & 0 deletions server/routes/summary_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AssistantServiceSetup } from '../services/assistant_service';

const SUMMARY_AGENT_CONFIG_ID = 'os_summary';
const OS_INSIGHT_AGENT_CONFIG_ID = 'os_insight';
const DATA2SUMMARY_AGENT_CONFIG_ID = 'os_data2summary';
let osInsightAgentId: string | undefined;
let userInsightAgentId: string | undefined;

Expand Down Expand Up @@ -125,3 +126,39 @@ export function registerSummaryAssistantRoutes(
})
);
}

export function registerData2SummaryRoutes(router: IRouter, assistantService: AssistantServiceSetup) {
router.post(
{
path: SUMMARY_ASSISTANT_API.DATA2SUMMARY,
validate: {
body: schema.object({
sample_data: schema.string(),
sample_count: schema.maybe(schema.number()),
total_count: schema.maybe(schema.number()),
question: schema.maybe(schema.string()),
ppl: schema.maybe(schema.string()),
}),
query: schema.object({
dataSourceId: schema.maybe(schema.string()),
}),
},
},
router.handleLegacyErrors(async (context, req, res) => {
const assistantClient = assistantService.getScopedClient(req, context);
try {
const response = await assistantClient.executeAgentByName(DATA2SUMMARY_AGENT_CONFIG_ID, {
sample_data: req.body.sample_data,
total_count: req.body.total_count,
sample_count: req.body.sample_count,
ppl: req.body.ppl,
question: req.body.question,
});
const result = response.body.inference_results[0].output[0].result;
return res.ok({ body: result });
} catch (e) {
return res.internalError();
}
})
);
}

0 comments on commit cf65633

Please sign in to comment.