Skip to content

Commit

Permalink
[query assist] update ml-commons response schema (opensearch-project#…
Browse files Browse the repository at this point in the history
…2124)

* [query assist] update ml-commons response schema processing

Signed-off-by: Joshua Li <[email protected]>

* disable query assist routes when data source is enabled

Signed-off-by: Joshua Li <[email protected]>

---------

Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 authored Sep 5, 2024
1 parent 0550228 commit acff04b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export function setupRoutes({
registerIntegrationsRoute(router);
registerDataConnectionsRoute(router, dataSourceEnabled);
registerDatasourcesRoute(router, dataSourceEnabled);
registerQueryAssistRoutes(router);

// query assist is part of log explorer, which will be disabled if datasource is enabled
if (!dataSourceEnabled) {
registerQueryAssistRoutes(router);
}

registerGettingStartedRoutes(router);
}
16 changes: 12 additions & 4 deletions server/routes/query_assist/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ export function registerQueryAssistRoutes(router: IRouter) {
if (
isResponseError(error) &&
error.statusCode === 400 &&
error.body.includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
// on opensearch >= 2.17, error.body is an object https://github.com/opensearch-project/ml-commons/pull/2858
JSON.stringify(error.body).includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
) {
return response.badRequest({ body: ERROR_DETAILS.GUARDRAILS_TRIGGERED });
}
return response.custom({ statusCode: error.statusCode || 500, body: error.message });
return response.custom({
statusCode: error.statusCode || 500,
body: typeof error.body === 'string' ? error.body : JSON.stringify(error.body),
});
}
}
);
Expand Down Expand Up @@ -155,11 +159,15 @@ export function registerQueryAssistRoutes(router: IRouter) {
if (
isResponseError(error) &&
error.statusCode === 400 &&
error.body.includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
// on opensearch >= 2.17, error.body is an object https://github.com/opensearch-project/ml-commons/pull/2858
JSON.stringify(error.body).includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
) {
return response.badRequest({ body: ERROR_DETAILS.GUARDRAILS_TRIGGERED });
}
return response.custom({ statusCode: error.statusCode || 500, body: error.message });
return response.custom({
statusCode: error.statusCode || 500,
body: typeof error.body === 'string' ? error.body : JSON.stringify(error.body),
});
}
}
);
Expand Down

0 comments on commit acff04b

Please sign in to comment.