From 349f03f7307630b46fac70d8afccc4b6b432a101 Mon Sep 17 00:00:00 2001 From: Qianhao Dong Date: Thu, 30 Nov 2023 02:35:24 +0800 Subject: [PATCH] [JS] fix: assistants planner error details and message order (#899) ## Linked issues closes: #806 #892 ## Details Fix issues in `AssistantsPlanner` #### Change details - Throw error with detailed code and message when run failed, from OpenAI Run's `last_error` field. - Reverse the messages returned from OpenAI's listMessages API, to ensure responses in asc order. ## Attestation Checklist - [X] My code follows the style guidelines of this project - I have checked for/fixed spelling, linting, and other errors - I have commented my code for clarity - I have made corresponding changes to the documentation (we use [TypeDoc](https://typedoc.org/) to document our code) - My changes generate no new warnings - I have added tests that validates my changes, and provides sufficient test coverage. I have tested with: - Local testing - E2E testing in Teams - New and existing unit tests pass locally with my changes ### Additional information > Feel free to add other relevant information below --- .../teams-ai/src/planners/AssistantsPlanner.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/js/packages/teams-ai/src/planners/AssistantsPlanner.ts b/js/packages/teams-ai/src/planners/AssistantsPlanner.ts index 9c6984fe5..5e4c492db 100644 --- a/js/packages/teams-ai/src/planners/AssistantsPlanner.ts +++ b/js/packages/teams-ai/src/planners/AssistantsPlanner.ts @@ -311,7 +311,9 @@ export class AssistantsPlanner implements case 'expired': return { type: 'plan', commands: [{type: 'DO', action: AI.TooManyStepsActionName} as PredictedDoCommand] }; default: - throw new Error(`Run failed ${results.status}`); + throw new Error( + `Run failed ${results.status}. ErrorCode: ${results.last_error?.code}. ErrorMessage: ${results.last_error?.message}` + ); } } @@ -346,7 +348,9 @@ export class AssistantsPlanner implements case 'expired': return { type: 'plan', commands: [{type: 'DO', action: AI.TooManyStepsActionName} as PredictedDoCommand] }; default: - throw new Error(`Run failed ${results.status}`); + throw new Error( + `Run failed ${results.status}. ErrorCode: ${results.last_error?.code}. ErrorMessage: ${results.last_error?.message}` + ); } } @@ -384,6 +388,9 @@ export class AssistantsPlanner implements } } + // listMessages return messages in desc, reverse to be in asc order + newMessages.reverse(); + // Convert the messages to SAY commands const plan: Plan = { type: 'plan', commands: [] }; newMessages.forEach(message => {