From caa2ecffabbef8b50cb47d5e688fe7dd85dc7117 Mon Sep 17 00:00:00 2001 From: cxumol Date: Thu, 4 Apr 2024 10:49:03 +0000 Subject: [PATCH] check API Key's provision directly and provide more clear error message --- app/app.py | 5 +++++ app/util.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index acc4d8d..5bb14d8 100644 --- a/app/app.py +++ b/app/app.py @@ -73,6 +73,9 @@ def set_same_cheap_strong( # setup_zone, ) +def check_API_Key_provision(cheap_key, strong_key): + if not cheap_key or not strong_key: + raise ValueError("API Key is not provided. You can get one from https://beta.openai.com/account/api-keys. Please read the in-App guide carefully before you start.") ## Main Functions @@ -290,6 +293,8 @@ def finalize_letter_pdf( fn=lambda: gr.Accordion("AI setup (OpenAI-compatible LLM API)", open=False), inputs=None, outputs=[setup_zone], + ).success( + fn=check_API_Key_provision, inputs=[cheap_key, strong_key], outputs=None ).success( fn=prepare_input, inputs=[jd_info, cv_file, cv_text], outputs=[jd_info, cv_text] ).success( diff --git a/app/util.py b/app/util.py index 1a651d6..dd49adc 100644 --- a/app/util.py +++ b/app/util.py @@ -48,7 +48,7 @@ def is_valid_openai_api_key(api_base: str, api_key: str) -> bool: def checkAPI(api_base: str, api_key: str): if not is_valid_openai_api_key(api_base, api_key): raise ValueError( - "API not available. Did you forget to setup your API Keys? If you don't have any API key, try getting one from https://beta.openai.com/account/api-keys" + "API not available. Please double check your API settings. If you don't have any API key, try getting one from https://beta.openai.com/account/api-keys" )