Spaces:
Running
Running
omkarenator
commited on
Commit
•
c01cdc6
1
Parent(s):
f9d4318
refactor error handling for OpenAI API
Browse files- autoagents/spaces/app.py +5 -5
autoagents/spaces/app.py
CHANGED
@@ -74,8 +74,8 @@ async def run():
|
|
74 |
persist_logs=True,
|
75 |
) # log to HF-dataset
|
76 |
|
77 |
-
async def cleanup(
|
78 |
-
st.error(
|
79 |
await st.session_state.task
|
80 |
st.session_state.task = None
|
81 |
st.stop()
|
@@ -99,9 +99,9 @@ async def run():
|
|
99 |
placeholder.empty()
|
100 |
if isinstance(output, Exception):
|
101 |
if isinstance(output, openai.error.AuthenticationError):
|
102 |
-
await cleanup(
|
103 |
-
|
104 |
-
)
|
105 |
elif isinstance(output, RuntimeWarning):
|
106 |
st.warning(output)
|
107 |
continue
|
|
|
74 |
persist_logs=True,
|
75 |
) # log to HF-dataset
|
76 |
|
77 |
+
async def cleanup(e):
|
78 |
+
st.error(e)
|
79 |
await st.session_state.task
|
80 |
st.session_state.task = None
|
81 |
st.stop()
|
|
|
99 |
placeholder.empty()
|
100 |
if isinstance(output, Exception):
|
101 |
if isinstance(output, openai.error.AuthenticationError):
|
102 |
+
await cleanup(f"AuthenticationError: Invalid OpenAI API key.")
|
103 |
+
elif isinstance(output, openai.error.OpenAIError):
|
104 |
+
await cleanup(output)
|
105 |
elif isinstance(output, RuntimeWarning):
|
106 |
st.warning(output)
|
107 |
continue
|