Repository navigation
refactor: enhance provider registration with display names and icons #8236
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,9 +90,7 @@ def get(self, request: Request): | |
| ): | ||
| providers.append(ModelProvideConstants[key].get_model_provide_info().to_dict()) | ||
| return result.success(providers) | ||
| return result.success( | ||
| [ModelProvideConstants[key].get_model_provide_info().to_dict() for key in ModelProvideConstants.__members__] | ||
| ) | ||
| return result.success(ModelProvideConstants.get_provider_info_list()) | ||
|
|
||
| class ModelTypeList(APIView): | ||
| authentication_classes = [TokenAuth] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at this diff, here's my analysis: What the change doesIt replaces an inline list comprehension (that iterated Potential issues & suggestions
Summary: The refactor is reasonable and reduces duplication, but verify the new method exists, preserves iteration semantics ( |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
Potential Issues
1. Thread safety in
get_provider_info_list/register_provider_infois written without the lock inregister, while_instancesusesself._lock. If registration is only done once at import time this is fine, but it's inconsistent — consider guarding both or documenting thatregisteris import-time-only.2.
get_provider_info_listdoes I/O every call (no caching)functools.lru_cacheon a module-level helper, or store loaded icons after first build).from common.utils.common import get_file_contentandPROJECT_DIRare imported inside the method — fine for avoiding circular imports, but repeated per-call imports add overhead; hoist if safe.get_file_contentwill throw and break the whole list. Consider try/except with a log + skip (or empty string).3. Fragile dir extraction
This couples display-info lookup to the factory module path. Cleaner: store
provider_dirdirectly in_provider_info, e.g.:and pass the dir you already have in
register()(you do —provider_dirparam), so just key by it.4. Lazy translation (
gettext_lazy) mixed with plain stringsSome entries use
_("..."), others are hardcoded ("OpenAI", "DeepSeek", ...). That's probably intentional (brand names unchanged), but verify consistency. More importantly —display_namemay be a lazy proxy object stored in a dict; when returned in a plainlist[dict], it will render per current locale at access time, which is usually desired, but make sure callers don't need concretestr(e.g., for JSONKeyError withensure_ascii). If serialized elsewhere, forcestr(...).5. Naming typos / inconsistencies
"model_siliconCloud_provider"and"siliconCloud_model_provider"use camelCase inconsistently with the rest (snake_case). Changing keys is a breaking change, but worth flagging._svg(e.g.,"azure_icon_svg") — presumably.svgextension appended internally. Ensureget_file_contenthandles this correctly. Double-check names like"zhipuai_icon_svg"vs provider name"zhipu","bedrock_icon_svg"vs dir"aws_bedrock_model_provider"— easy to mismatch.6. Return type docstring/signature
-> list[dict]is vague; preferlist[ProviderInfo]with a TypedDict / dataclass for clarity.7.
_provider_infomay desync from_factoriesTwo parallel dicts keyed by
namemust stay in sync. Ifregisterever fails partway (exception between assignments), state is inconsistent. Consider a single dict of small records, e.g.:Optimization suggestions
get_provider_info_list()results (icons rarely change)..register(...)chain — easier to maintain and test:register(duplicate name check, non-empty args) to fail fast.get_icon(name)accessor, so callers who only need names/icons don't pay full cost.Summary
Main concerns: no caching on file I/O, fragile path-to-dir derivation, dual-dict desync risk, and a few naming typos. None are blocking, but addressing #2, #3, and #7 would improve robustness significantly.