arcade chat catch OpenAIErrors (#69)
Instead of `arcade chat` crashing, we just prompt the user again 
This commit is contained in:
parent
9eb9f77a92
commit
5a32685b19
1 changed files with 15 additions and 2 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue