From e3240511ab9654adfa19e830e08dc84e74dfa96a Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Mon, 4 Dec 2023 16:37:49 -0500 Subject: [PATCH] handle model not found error better --- backend/main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/main.py b/backend/main.py index 72b6fd3..9056db4 100644 --- a/backend/main.py +++ b/backend/main.py @@ -206,6 +206,18 @@ async def stream_code(websocket: WebSocket): ) ) return await throw_error(error_message) + except openai.NotFoundError as e: + print("[GENERATE_CODE] Model not found", e) + error_message = ( + e.message + + ". Please make sure you have followed the instructions correctly to obtain an OpenAI key with GPT vision access: https://github.com/abi/screenshot-to-code/blob/main/Troubleshooting.md" + + ( + " Alternatively, you can purchase code generation credits directly on this website." + if IS_PROD + else "" + ) + ) + return await throw_error(error_message) # Write the messages dict into a log so that we can debug later write_logs(prompt_messages, completion)