barunsaha commited on
Commit
11744df
·
1 Parent(s): bd30014

Update error handling for wrong API keys

Browse files
Files changed (1) hide show
  1. app.py +6 -20
app.py CHANGED
@@ -478,29 +478,15 @@ def set_up_chat_ui():
478
  True
479
  )
480
  except Exception as ex:
481
- _msg = str(ex)
482
- if 'payment required' in _msg.lower():
483
  handle_error(
484
- 'The available inference quota has exhausted.'
485
- ' Please use your own Hugging Face access token. Paste your token in'
486
- ' the input field on the sidebar to the left.'
487
- '\n\nDon\'t have a token? Get your free'
488
- ' [HF access token](https://huggingface.co/settings/tokens) now'
489
- ' and start creating your slide deck! For gated models, you may need to'
490
- ' visit the model\'s page and accept the terms or service.'
491
- '\n\nAlternatively, choose a different LLM and provider from the list.',
492
- should_log=True
493
- )
494
- else:
495
- handle_error(
496
- f'An unexpected error occurred while generating the content: {_msg}'
497
- '\n\nPlease try again later, possibly with different inputs.'
498
- ' Alternatively, try selecting a different LLM from the dropdown list.'
499
- ' If you are using Azure OpenAI, Cohere, Gemini, or Together AI models, make'
500
- ' sure that you have provided a correct API key.'
501
- ' Read **[how to get free LLM API keys](https://github.com/barun-saha/slide-deck-ai?tab=readme-ov-file#summary-of-the-llms)**.',
502
  True
503
  )
 
 
504
 
505
 
506
  def _is_it_refinement() -> bool:
 
478
  True
479
  )
480
  except Exception as ex:
481
+ if 'litellm.AuthenticationError' in str(ex):
 
482
  handle_error(
483
+ f'LLM API authentication failed: {ex}'
484
+ '\nMake sure that you have provided a valid, correct API key.'
485
+ ' Read **[how to get free LLM API keys](https://github.com/barun-saha/slide-deck-ai?tab=readme-ov-file#unmatched-flexibility-choose-your-ai-brain)**.',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  True
487
  )
488
+ else:
489
+ handle_error('An unexpected error occurred: ' + str(ex), True)
490
 
491
 
492
  def _is_it_refinement() -> bool: