Skip to content

Commit

Permalink
check API Key's provision directly and provide more clear error message
Browse files Browse the repository at this point in the history
  • Loading branch information
cxumol committed Apr 4, 2024
1 parent 7b4e4a9 commit caa2ecf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)


Expand Down

0 comments on commit caa2ecf

Please sign in to comment.