arcade chat catch OpenAIErrors (#69)

Instead of `arcade chat` crashing, we just prompt the user again


![image](https://github.com/user-attachments/assets/34aaed14-13af-4ab0-aae2-9734b34cf7ba)
This commit is contained in:
Eric Gustin 2024-09-25 15:55:35 -07:00 committed by GitHub
parent 9eb9f77a92
commit 5a32685b19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,6 +8,7 @@ from typing import Any, Optional
from urllib.parse import urlencode from urllib.parse import urlencode
import typer import typer
from openai import OpenAIError
from rich.console import Console from rich.console import Console
from rich.markup import escape from rich.markup import escape
from rich.table import Table from rich.table import Table
@ -244,7 +245,12 @@ def chat(
history.append({"role": "user", "content": user_input}) history.append({"role": "user", "content": user_input})
chat_result = handle_chat_interaction(client, model, history, user_email, stream) try:
chat_result = handle_chat_interaction(client, model, history, user_email, stream)
except OpenAIError as e:
console.print(f"❌ Arcade Chat failed with error: {e!s}", style="bold red")
continue
history = chat_result.history history = chat_result.history
tool_messages = chat_result.tool_messages tool_messages = chat_result.tool_messages
tool_authorization = chat_result.tool_authorization tool_authorization = chat_result.tool_authorization
@ -254,7 +260,14 @@ def chat(
with console.status("Waiting for you to authorize the action...", spinner="dots"): with console.status("Waiting for you to authorize the action...", spinner="dots"):
wait_for_authorization_completion(client, tool_authorization) wait_for_authorization_completion(client, tool_authorization)
# re-run the chat request now that authorization is complete # re-run the chat request now that authorization is complete
chat_result = handle_chat_interaction(client, model, history, user_email, stream) try:
chat_result = handle_chat_interaction(
client, model, history, user_email, stream
)
except OpenAIError as e:
console.print(f"❌ Arcade Chat failed with error: {e!s}", style="bold red")
continue
history = chat_result.history history = chat_result.history
tool_messages = chat_result.tool_messages tool_messages = chat_result.tool_messages