Skip to content

Commit

Permalink
[JS] fix: assistants planner error details and message order (#899)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
swatDong authored Nov 29, 2023
1 parent 17702fb commit 349f03f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions js/packages/teams-ai/src/planners/AssistantsPlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ export class AssistantsPlanner<TState extends TurnState = TurnState> 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}`
);
}
}

Expand Down Expand Up @@ -346,7 +348,9 @@ export class AssistantsPlanner<TState extends TurnState = TurnState> 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}`
);
}
}

Expand Down Expand Up @@ -384,6 +388,9 @@ export class AssistantsPlanner<TState extends TurnState = TurnState> 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 => {
Expand Down

0 comments on commit 349f03f

Please sign in to comment.