improve error UX (particular when no OpenAI API key is found)
This commit is contained in:
parent
4ef26a6ae8
commit
29cea327cc
@ -23,7 +23,8 @@ from prompts.claude_prompts import VIDEO_PROMPT
|
||||
from prompts.types import Stack
|
||||
|
||||
# from utils import pprint_prompt
|
||||
from video.utils import extract_tag_content, assemble_claude_prompt_video # type: ignore
|
||||
from video.utils import extract_tag_content, assemble_claude_prompt_video
|
||||
from ws.constants import APP_ERROR_WEB_SOCKET_CODE # type: ignore
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
@ -58,7 +59,7 @@ async def stream_code(websocket: WebSocket):
|
||||
message: str,
|
||||
):
|
||||
await websocket.send_json({"type": "error", "value": message})
|
||||
await websocket.close()
|
||||
await websocket.close(APP_ERROR_WEB_SOCKET_CODE)
|
||||
|
||||
# TODO: Are the values always strings?
|
||||
params: Dict[str, str] = await websocket.receive_json()
|
||||
@ -121,11 +122,8 @@ async def stream_code(websocket: WebSocket):
|
||||
|
||||
if not openai_api_key and code_generation_model == "gpt_4_vision":
|
||||
print("OpenAI API key not found")
|
||||
await websocket.send_json(
|
||||
{
|
||||
"type": "error",
|
||||
"value": "No OpenAI API key found. Please add your API key in the settings dialog or add it to backend/.env file. If you add it to .env, make sure to restart the backend server.",
|
||||
}
|
||||
await throw_error(
|
||||
"No OpenAI API key found. Please add your API key in the settings dialog or add it to backend/.env file. If you add it to .env, make sure to restart the backend server."
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
0
backend/ws/__init__.py
Normal file
0
backend/ws/__init__.py
Normal file
2
backend/ws/constants.py
Normal file
2
backend/ws/constants.py
Normal file
@ -0,0 +1,2 @@
|
||||
# WebSocket protocol (RFC 6455) allows for the use of custom close codes in the range 4000-4999
|
||||
APP_ERROR_WEB_SOCKET_CODE = 4332
|
||||
@ -48,7 +48,7 @@ export function generateCode(
|
||||
onCancel();
|
||||
} else if (event.code !== 1000) {
|
||||
console.error("WebSocket error code", event);
|
||||
toast.error(ERROR_MESSAGE);
|
||||
onCancel();
|
||||
} else {
|
||||
onComplete();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user