[Refactor] Overhaul Spark adapter with model catalog and dynamic configuration#765
[Refactor] Overhaul Spark adapter with model catalog and dynamic configuration#765dingyi222666 merged 3 commits intov1-devfrom
Conversation
…mic configuration This commit significantly improves the Spark adapter with a centralized model catalog system and dynamic configuration management. Models are now only shown when their API passwords are properly configured. Key improvements: - Introduce SparkModelDefinition interface for centralized model configuration - Create sparkModelCatalog with all Spark models and their properties - Implement dynamic model filtering based on configured passwords - Support model aliases for flexible password configuration - Add comprehensive getSparkModelPassword and hasSparkModelPassword utilities - Improve API path routing for different Spark API versions - Enhance request config selection with load balancing across configurations - Better error handling for missing passwords and invalid models - Update locale strings for clearer setup instructions in Chinese and English Other improvements: - Add usage documentation for Gemini, OpenAI, and OpenAI-like adapters - Simplify model refresh logic in SparkClient - Improve message role mapping (user/tool distinction) - Add support for additional request parameters (top_k, keep_alive, etc.) - Enhance response format handling with thinking and JSON response support - Better handling of chat completion tool parameters Benefits: - Cleaner configuration with prefilled model aliases - Reduced duplication through centralized catalog - Better API flexibility with support for multiple Spark API versions - More intuitive user experience with only available models shown - Improved maintainability with model definitions in one place
Update package versions for all adapter packages following the refactoring and documentation improvements made in the previous commit. Version updates: - adapter-spark: 1.3.6 -> 1.3.7 - adapter-gemini: 1.3.28 -> 1.3.29 - adapter-openai: 1.3.8 -> 1.3.9 - adapter-openai-like: 1.3.9 -> 1.3.10 These version bumps reflect the significant improvements made to the adapters including the new model catalog system, dynamic configuration management, and comprehensive documentation.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (6)
📒 Files selected for processing (8)
Walkthrough三个适配器(Gemini、OpenAI-like、OpenAI)添加了usage文档常量。Spark适配器进行了重大重构,用模型定义目录替代硬编码模型列表,实现了模型感知的配置选择逻辑,扩展了类型系统以支持新的请求字段和工具功能。 Changes
Sequence DiagramsequenceDiagram
participant Client as Client Request
participant Requester as SparkRequester
participant ConfigSelector as _selectConfigForModel
participant ModelDef as _getModelDefinition
participant ModelCatalog as SparkModelCatalog
participant APIClient as Spark API
Client->>Requester: completion(model, messages)
Requester->>ConfigSelector: _selectConfigForModel(model)
ConfigSelector->>ModelCatalog: 查找模型定义
ModelCatalog-->>ConfigSelector: SparkModelDefinition
ConfigSelector->>ConfigSelector: 检查密钥可用性<br/>轮转选择配置
ConfigSelector-->>Requester: ClientConfigWrapper
Requester->>ModelDef: _getModelDefinition(model)
ModelDef->>ModelCatalog: 解析模型元数据
ModelCatalog-->>ModelDef: apiPath, maxTokens, capabilities
ModelDef-->>Requester: SparkModelDefinition
Requester->>Requester: 构建请求载荷<br/>添加新字段、工具、penalties
Requester->>Requester: 根据模型定义调整HTTP路径
Requester->>APIClient: POST请求
APIClient-->>Requester: 响应流
Requester->>Requester: 解析、日志记录、处理工具调用
Requester-->>Client: 完成结果
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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! This pull request significantly refactors the Spark adapter by implementing a robust model catalog system and dynamic configuration management. The changes streamline how models are defined, configured, and accessed, ensuring that only properly credentialed models are available. This overhaul not only enhances the adapter's flexibility and reliability but also improves the overall user experience through better error handling, expanded API parameter support, and clearer documentation across multiple adapters. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Co-authored-by: codefactor-io[bot] <47775046+codefactor-io[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and well-executed refactoring of the Spark adapter, featuring a centralized model catalog that greatly enhances maintainability and extensibility. The dynamic model filtering based on password configuration is a clever and user-friendly addition. The PR also provides valuable documentation updates for several adapters and crucial bug fixes, such as correcting the message role mapping. My feedback is limited to a couple of minor points regarding an affiliate link in the documentation and a hardcoded non-English string in an error message. Overall, these are excellent changes that substantially improve the adapter's architecture.
|
|
||
| **如果你没有可用的 Gemini 格式 API,请前往以下地址注册:** | ||
|
|
||
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997) |
There was a problem hiding this comment.
The new usage documentation includes a hardcoded affiliate link. While this might be intentional, it's generally better to avoid embedding affiliate links directly in the source code to maintain neutrality and avoid potential user trust issues. Consider removing the affiliate query parameter (?aff=...) or making it configurable if this is part of a partnership.
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997) | |
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register) |
|
|
||
| **如果你没有可用的 OpenAI 格式 API,请前往以下地址注册:** | ||
|
|
||
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997) |
There was a problem hiding this comment.
The new usage documentation includes a hardcoded affiliate link. While this might be intentional, it's generally better to avoid embedding affiliate links directly in the source code to maintain neutrality and avoid potential user trust issues. Consider removing the affiliate query parameter (?aff=...) or making it configurable if this is part of a partnership.
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997) | |
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register) |
|
|
||
| **如果你没有可用的 OpenAI 格式 API,请前往以下地址注册:** | ||
|
|
||
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997) |
There was a problem hiding this comment.
The new usage documentation includes a hardcoded affiliate link. While this might be intentional, it's generally better to avoid embedding affiliate links directly in the source code to maintain neutrality and avoid potential user trust issues. Consider removing the affiliate query parameter (?aff=...) or making it configurable if this is part of a partnership.
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997) | |
| [https://api.bltcy.ai/register](https://api.bltcy.ai/register) |
| if (matchedConfigs.length < 1) { | ||
| throw new ChatLunaError( | ||
| ChatLunaErrorCode.API_KEY_UNAVAILABLE, | ||
| new Error(`没有找到模型 "${model}" 的 API 密钥`) |
There was a problem hiding this comment.
This error message is hardcoded in Chinese. For better maintainability and to make the codebase more accessible to a wider range of contributors, it's recommended to use English for internal error messages. If localization is desired, these strings should be moved to locale files and referenced via keys.
| new Error(`没有找到模型 "${model}" 的 API 密钥`) | |
| new Error(`API key for model "${model}" not found`) |
…iguration (#765) * refactor(adapter): overhaul Spark adapter with model catalog and dynamic configuration This commit significantly improves the Spark adapter with a centralized model catalog system and dynamic configuration management. Models are now only shown when their API passwords are properly configured. Key improvements: - Introduce SparkModelDefinition interface for centralized model configuration - Create sparkModelCatalog with all Spark models and their properties - Implement dynamic model filtering based on configured passwords - Support model aliases for flexible password configuration - Add comprehensive getSparkModelPassword and hasSparkModelPassword utilities - Improve API path routing for different Spark API versions - Enhance request config selection with load balancing across configurations - Better error handling for missing passwords and invalid models - Update locale strings for clearer setup instructions in Chinese and English Other improvements: - Add usage documentation for Gemini, OpenAI, and OpenAI-like adapters - Simplify model refresh logic in SparkClient - Improve message role mapping (user/tool distinction) - Add support for additional request parameters (top_k, keep_alive, etc.) - Enhance response format handling with thinking and JSON response support - Better handling of chat completion tool parameters Benefits: - Cleaner configuration with prefilled model aliases - Reduced duplication through centralized catalog - Better API flexibility with support for multiple Spark API versions - More intuitive user experience with only available models shown - Improved maintainability with model definitions in one place * chore(packages): bump adapter package versions Update package versions for all adapter packages following the refactoring and documentation improvements made in the previous commit. Version updates: - adapter-spark: 1.3.6 -> 1.3.7 - adapter-gemini: 1.3.28 -> 1.3.29 - adapter-openai: 1.3.8 -> 1.3.9 - adapter-openai-like: 1.3.9 -> 1.3.10 These version bumps reflect the significant improvements made to the adapters including the new model catalog system, dynamic configuration management, and comprehensive documentation. * Update packages/adapter-spark/src/types.ts Co-authored-by: codefactor-io[bot] <47775046+codefactor-io[bot]@users.noreply.github.com> --------- Co-authored-by: codefactor-io[bot] <47775046+codefactor-io[bot]@users.noreply.github.com>
Summary
This PR refactors the Spark adapter with a centralized model catalog system and dynamic configuration management. Models are now only shown when their API passwords are properly configured.
New Features
SparkModelDefinitioninterface for centralized model configuration with support for all Spark models (lite, pro, pro-128k, max, max-32k, 4.0-ultra, x1.5, x2)getSparkModelPassword,hasSparkModelPassword, andgetSparkModelDefinitionutilitiesBug fixes
Other Changes