Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use modern typing syntax #201

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

marginal23326
Copy link
Contributor

Since this repo uses Python 3.11+, I updated the typing annotations to use the cleaner built-in generics like list[str], dict[str, Any], and type[Something] instead of the old List[], Dict[], and Type[]. Also replaced Optional[] with | None for better readability. As part of this, I removed most of the typing imports that were no longer needed after the change. Also removed redundant exception variables where they weren’t needed.

This PR introduces proper error handling in the UI for missing API keys, addressing issue browser-use#188. Previously, missing API keys resulted in tracebacks in the console, but no clear error was shown in the UI. This made it difficult to understand what went wrong. Now, API key checks are performed at the start of the `get_llm_model` function in `src/utils/utils.py`. I've also added a `PROVIDER_DISPLAY_NAMES` constant for more user-friendly error messages and a `handle_api_key_error` function that leverages `gr.Error` to display clear error messages directly in the UI. If an API key is missing, you'll now see an error message right away. The `run_browser_agent` and `run_with_stream` functions in `webui.py` have been adjusted to ensure these `gr.Error` exceptions are handled properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant