From aef38d3725d7d071bf0255913d0ee96973c9be60 Mon Sep 17 00:00:00 2001 From: Jonathan Lessinger Date: Wed, 10 Jan 2024 13:22:45 -0500 Subject: [PATCH] wip exception handling --- python/src/aiconfig/editor/server/server.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/python/src/aiconfig/editor/server/server.py b/python/src/aiconfig/editor/server/server.py index 9c257804a..ccfb6a186 100644 --- a/python/src/aiconfig/editor/server/server.py +++ b/python/src/aiconfig/editor/server/server.py @@ -234,7 +234,11 @@ def generate(cancellation_token_id: str): # type: ignore # Use multi-threading so that we don't block run command from # displaying the streamed output (if streaming is supported) def run_async_config_in_thread(): - asyncio.run(aiconfig.run(prompt_name=prompt_name, params=params, run_with_dependencies=False, options=inference_options)) # type: ignore + try: + asyncio.run(aiconfig.run(prompt_name=prompt_name, params=params, run_with_dependencies=False, options=inference_options)) # type: ignore + except Exception as e: + output_text_queue.put(e) + output_text_queue.put(STOP_STREAMING_SIGNAL) # type: ignore def create_cancellation_payload(): @@ -307,7 +311,11 @@ def kill_thread(thread_id: int | None): yield from handle_cancellation() return - if isinstance(text, str): + if isinstance(text, Exception): + yield "[" + yield json.dumps({"message": "exception", "output": str(text)}) + yield "]" + elif isinstance(text, str): accumulated_output_text += text elif isinstance(text, dict) and "content" in text: # TODO: Fix streaming output format so that it returns text