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

[query assist] update ml-commons response schema #2124

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from 1 commit
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
16 changes: 12 additions & 4 deletions server/routes/query_assist/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 31 in server/routes/query_assist/routes.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const client = context.core.opensearch.client.asCurrentUser;
try {
// if the call does not throw any error, then the agent is properly configured
Expand All @@ -54,7 +54,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 57 in server/routes/query_assist/routes.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const client = context.core.opensearch.client.asCurrentUser;
try {
const pplRequest = await getAgentIdAndRequest({
Expand Down Expand Up @@ -83,11 +83,15 @@
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)
ps48 marked this conversation as resolved.
Show resolved Hide resolved
) {
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 All @@ -109,7 +113,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 116 in server/routes/query_assist/routes.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const client = context.core.opensearch.client.asCurrentUser;
const { index, question, query, response: _response, isError } = request.body;
const queryResponse = JSON.stringify(_response);
Expand Down Expand Up @@ -155,11 +159,15 @@
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
Loading