feat: add provider adapter i18n registration support#6917
feat: add provider adapter i18n registration support#6917Li-shi-ling wants to merge 4 commits intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在为 AstrBot 的 Provider 适配器引入全面的国际化 (i18n) 注册支持。通过允许 Provider 适配器声明其自身的 i18n 资源和配置元数据,它解决了自定义 Provider 配置字段无法参与到 WebUI 翻译流程的问题。这一改进确保了所有 Provider 配置都能在用户界面中正确地进行本地化显示,从而提升了用户体验并保持了与平台适配器机制的一致性。 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
_rewrite_metadata_i18n_keysnow also rewritesnamefields (and is reused for platforms and providers), which is a behavior change for platform metadata; consider confirming this won’t break existing consumers that expect literalnamevalues or gatingnamerewriting behind an option. - The docstring for
register_provider_adapterinastrbot/core/provider/register.pystill says it is for registering platform adapters (用于注册平台适配器); updating this to refer to provider adapters would avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `_rewrite_metadata_i18n_keys` now also rewrites `name` fields (and is reused for platforms and providers), which is a behavior change for platform metadata; consider confirming this won’t break existing consumers that expect literal `name` values or gating `name` rewriting behind an option.
- The docstring for `register_provider_adapter` in `astrbot/core/provider/register.py` still says it is for registering platform adapters (用于注册平台适配器); updating this to refer to provider adapters would avoid confusion.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces new provider types (Embedding, Rerank, TTS) and significantly enhances the dashboard's configuration and internationalization (i18n) capabilities for providers. It allows providers to define their own i18n resources and config metadata, which are then dynamically loaded and applied in the UI. A high-severity issue was identified where provider.default_config_tmpl was directly assigned, potentially leading to unintended side effects due to mutable shared global state. This should be corrected by using copy.deepcopy() to ensure isolated copies of the template.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f8771b5038
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
此项更改为 Provider 适配器增加了动态 i18n 注册支持,与现有的平台适配器机制保持一致。
在此更改之前,register_provider_adapter 无法声明 i18n_resources 或 config_metadata,因此 Provider 适配器缺少完整的后端到前端 i18n 注册路径。这导致自定义 Provider 配置字段无法参与到平台适配器所使用的同一套已翻译的 WebUI 表单流程中。
Modifications / 改动点
astrbot/core/provider/entities.py在 ProviderMetaData 中添加了 i18n_resources 和 config_metadata,使 Provider 适配器注册能够通过后端注册层携带自定义的 i18n 负载和配置元数据。
astrbot/core/provider/register.py扩展了 register_provider_adapter(...) 以接受 i18n_resources 和 config_metadata,并将其持久化到 ProviderMetaData 中。这保持了旧注册的兼容性,同时启用了 Provider 端的 i18n 注册功能。
astrbot/dashboard/routes/config.py添加了 Provider 元数据注入和动态 i18n 响应支持。
为 description / hint / labels / name 实现了递归的元数据 i18n 键重写,包括嵌套的 items 和 template_schema。
添加了使用 provider_group.provider.{provider.type}.* 的 Provider 端键路径生成。
扩展了 /api/config/get 和 /api/config/provider/template 两个接口,使其返回 provider_i18n_translations。
将 Provider 适配器的 config_metadata 注入到 Provider 架构生成中。
dashboard/src/composables/useProviderSources.ts通过 mergeDynamicTranslations('features.config-metadata', ...) 添加了动态 Provider i18n 合并逻辑。
将 Provider 翻译加载路径集中到共享的组合式函数中,使 Provider 页面和 Provider 配置对话框都能受益于相同的动态 i18n 行为。
添加了语言切换重新加载处理,以便在切换语言时刷新 Provider 适配器的翻译。
Screenshots or Test Results / 运行截图或测试结果
测试插件代码(节选)
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
[ x ] 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
有进行测试
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。没有引入新库
/ 我的更改没有引入恶意代码。
没有引入
Summary by Sourcery
Add dynamic i18n registration and metadata support for provider adapters and expose provider adapter types and registration utilities through the public API.
New Features:
Enhancements: