Gracefully handle bad agent auth (#1115)

use provider that is set
This commit is contained in:
Timothy Carambat 2024-04-16 16:42:06 -07:00 committed by GitHub
parent f9ac27e9a4
commit 8ebe1a515b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 6 deletions

View File

@ -48,7 +48,13 @@ const websocket = {
name: this.name,
setup(aibitat) {
aibitat.onError(async (error) => {
console.error(chalk.red(` error: ${error?.message}`));
if (!!error?.message) {
console.error(chalk.red(` error: ${error.message}`));
aibitat.introspect(
`Error encountered while running: ${error.message}`
);
}
if (error instanceof RetryError) {
console.error(chalk.red(` retrying in 60 seconds...`));
setTimeout(() => {

View File

@ -117,10 +117,14 @@ class AnthropicProvider extends Provider {
cost,
};
} catch (error) {
// If invalid Auth error we need to abort because no amount of waiting
// will make auth better.
if (error instanceof Anthropic.AuthenticationError) throw error;
if (
error instanceof Anthropic.RateLimitError ||
error instanceof Anthropic.InternalServerError ||
error instanceof Anthropic.APIError
error instanceof Anthropic.APIError // Also will catch AuthenticationError!!!
) {
throw new RetryError(error.message);
}

View File

@ -102,11 +102,14 @@ class OpenAIProvider extends Provider {
cost,
};
} catch (error) {
console.log(error);
// If invalid Auth error we need to abort because no amount of waiting
// will make auth better.
if (error instanceof OpenAI.AuthenticationError) throw error;
if (
error instanceof OpenAI.RateLimitError ||
error instanceof OpenAI.InternalServerError ||
error instanceof OpenAI.APIError
error instanceof OpenAI.APIError // Also will catch AuthenticationError!!!
) {
throw new RetryError(error.message);
}

View File

@ -157,8 +157,8 @@ class AgentHandler {
}
) {
this.aibitat = new AIbitat({
provider: "openai",
model: "gpt-3.5-turbo",
provider: this.provider ?? "openai",
model: this.model ?? "gpt-3.5-turbo",
chats: await this.#chatHistory(20),
handlerProps: {
invocation: this.invocation,