Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce Customizable Base URLs for API Providers (#524)
* feat(custom-base-url): add support for custom base URL configuration - Introduced a `custom_base_url` field to the `Account` model in `account_config.py` for providers that allow custom base URLs. - Updated `EditAccountDialog` in `account_dialog.py` to include a new input field for the custom base URL and adjusted the UI to reflect this change. - Modified `Provider` class in `provider.py` to include an `allow_custom_base_url` attribute, enabling custom base URL configuration for specific providers. - Updated provider configurations for `mistralai`, `openai`, and `openrouter` to support custom base URLs. - Adjusted OpenAIEngine logic to prioritize the custom base URL over the default provider base URL if provided. * refactor(account_dialog): improve code structure in EditAccountDialog - Removed `TYPE_CHECKING` imports and directly imported `Provider`. - Refactored the `EditAccountDialog` class to improve clarity and maintainability: - Introduced type hints for method parameters and return types. - Improved method names and added docstrings for better readability. - Split large methods into smaller, more focused methods. - Added error messages for form validation as comments for translators. - Reduced code duplication by consolidating similar code blocks. - Revised organization and API key fields handling for clarity. * feat(account_dialog): enhance validation and focus control - Introduced a regex pattern `CUSTOM_BASE_URL_PATTERN` for validating custom base URLs. - Changed `get_selected_provider` method into a `provider` property for enhanced code readability. - Updated `_validate_form` to return a tuple of error message and associated field. - Added focus control to invalid form fields to enhance user experience by directing attention to the error. - Refactor form validation to include custom base URL validation. * Update basilisk/config/account_config.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * style(pre-commit.ci): auto fixes from pre-commit hooks for more information, see https://pre-commit.ci * Update basilisk/config/account_config.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * refactor(config): centralize `CUSTOM_BASE_URL_PATTERN` for unified URL validation - Move the `CUSTOM_BASE_URL_PATTERN` regex from `account_dialog.py` to `account_config.py`. - Update the `Account` class definition to use this centralized pattern for `custom_base_url`. - Adjust imports in `__init__.py` and `account_dialog.py` to utilize the centralized `CUSTOM_BASE_URL_PATTERN`. * refactor(account_dialog): update type annotations to Python 3.10+ syntax Replaced 'Optional[T]' with 'T | None' for type hinting in the account_dialog.py file. This change modernizes the code to make use of the Python 3.10+ feature which improves readability. * feat(account_dialog): show default base URL Enhanced the account dialog to display the default base URL when available, aiding in customization clarity. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information