Skip to content

Conversation

@yrk111222
Copy link

@yrk111222 yrk111222 commented Dec 9, 2025

Description

Hello,
I have added the ModelScope provider, as well as some well-known models.

Added svg to ProviderIcon.tsx
I also added a png image for the provider, with a white background in modelscope.png

Created modelscope-setting-util.ts

Added models to default.ts

Additional Notes

This PR primarily adds support for the ModelScope API. Users can now utilize models supported by ModelScope API inference by setting an API key.

How to obtain an API key

Note: Please bind your Alibaba Cloud account before using this feature.

Screenshots

image

Contributor Agreement

By submitting this Pull Request, I confirm that I have read and agree to the following terms:

  • I agree to contribute all code submitted in this PR to the open-source community edition licensed under GPLv3 and the proprietary official edition without compensation.
  • I grant the official edition development team the rights to freely use, modify, and distribute this code, including for commercial purposes.
  • I confirm that this code is my original work, or I have obtained the appropriate authorization from the copyright holder to submit this code under these terms.
  • I understand that the submitted code will be publicly released under the GPLv3 license, and may also be used in the proprietary official edition.

Please check the box below to confirm:

[x] I have read and agree with the above statement.

Summary by CodeRabbit

  • New Features
    • Added ModelScope as a new AI provider option, enabling users to integrate and select ModelScope models within the application.
    • Configured default ModelScope models and settings for seamless provider integration.
    • Implemented provider settings migration to support existing ModelScope configurations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds comprehensive support for a new ModelScope provider across the application stack, including icon rendering, provider type registration, utility classes for model discovery, default model configurations, factory integration, and data migration logic.

Changes

Cohort / File(s) Summary
Provider Type & Compatibility
src/shared/types/provider.ts, src/shared/utils/llm_utils.ts
Adds ModelScope enum member to ModelProviderEnum and includes it in the isOpenAICompatible provider array for compatibility checking.
UI Components
src/renderer/components/icons/ProviderIcon.tsx
Adds SVG path rendering for ModelScope provider icon in the icon selection logic.
Provider Configuration
src/shared/defaults.ts
Extends SystemProviders array with ModelScope provider entry, including API host, model definitions, and model capabilities/context windows.
Provider Implementation Classes
src/shared/models/modelscope.ts
New class extending OpenAICompatible for ModelScope API integration, sets default API host to https://api-inference.modelscope.cn/v1, and handles options initialization.
Model Factory & Menu Integration
src/shared/models/index.ts
Adds ModelScope case to getModel factory switch and includes ModelScope in AIModelProviderMenuOptionList for provider menu display.
Provider Utilities
src/renderer/packages/model-setting-utils/index.ts, src/renderer/packages/model-setting-utils/modelscope-setting-util.ts
New ModelScopeSettingUtil class implementing model display name formatting and model listing via dependencies; integrated into provider utility resolver map.
Data Migration
src/renderer/stores/migration.ts
Extends 9-to-10 migration logic to handle legacy ModelScope API key and model settings, registers provider during migration, and maps model selections.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Areas of focus:

  • Verify ModelScope API endpoint configuration and compatibility with OpenAI-compatible interface
  • Confirm migration logic properly extracts and registers legacy ModelScope settings without data loss
  • Ensure model listing and display name formatting in ModelScopeSettingUtil align with expected provider behavior

Possibly related PRs

  • Adding MistralAI #2514: Adds support for additional AI providers with analogous changes across provider registration, icon rendering, model configuration, and setting utilities.

Suggested reviewers

  • themez

Poem

🐰 A new provider hops into view,
ModelScope joins the crew!
From icons to models, all wired with care,
OpenAI-compatible beyond compare. 🚀✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add ModelScope API support' clearly and concisely summarizes the main change—adding support for the ModelScope provider throughout the codebase.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yrk111222
Copy link
Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/renderer/components/icons/ProviderIcon.tsx (1)

109-115: ModelScope icon wiring looks good; consider camelCase clipRule

The new ModelScope branch is correctly wired and will render for provider === ModelProviderEnum.ModelScope. To stay consistent with the rest of this file and React’s SVG props, you might want to use clipRule instead of clip-rule:

-          <path clip-rule="evenodd" d="M21.333 13.3v-2.667h-2.666V7.967H16V5.3h5.333v2.667H24V13.3h-2.667zm0-2.667H23.5V8.467h-2.167v2.166z"></path>
+          <path clipRule="evenodd" d="M21.333 13.3v-2.667h-2.666V7.967H16V5.3h5.333v2.667H24V13.3h-2.667zm0-2.667H23.5V8.467h-2.167v2.166z"></path>
src/shared/models/index.ts (1)

32-33: ModelScope model wiring is consistent with other OpenAI‑style providers

  • The new ModelProviderEnum.ModelScope case in getModel mirrors other OpenAI‑compatible providers and forwards the expected knobs (model, temperature, topP, maxOutputTokens, stream) into ModelScope, which itself supplies the fixed host.
  • aiProviderNameHash and AIModelProviderMenuOptionList entries ensure ModelScope appears correctly in the provider selector UI.

If you ever decide to make the ModelScope host configurable, you’ll only need to thread formattedApiHost into the ModelScope constructor; the surrounding plumbing is already in place.

Also applies to: 81-99, 116-318, 401-421, 423-515

src/shared/defaults.ts (1)

824-906: SystemProviders entry for ModelScope matches existing provider patterns

The new ModelScope provider definition (id/type/urls/defaultSettings/apiHost/models) is structurally aligned with the other OpenAI‑compatible providers, and its host matches the one used in ModelScope itself, so consumers of SystemProviders should just work. If the host ever needs to change, consider centralizing it in a shared constant to avoid drift.

src/renderer/packages/model-setting-utils/modelscope-setting-util.ts (1)

17-21: Avoid non-null assertion on settings.apiKey and validate explicitly

Relying on settings.apiKey! here assumes upstream always provides a non-empty key. If configuration is ever incomplete (e.g., user hasn’t entered a key yet), this can result in confusing runtime behavior at the model client layer.

Consider validating the API key up front and removing the non-null assertion:

-  protected async listProviderModels(settings: ProviderSettings) {
-    const dependencies = await createModelDependencies()
-    const modelscope = new ModelScope({ apiKey: settings.apiKey!, model: { modelId: '', capabilities: [] } }, dependencies)
-    return modelscope.listModels()
-  }
+  protected async listProviderModels(settings: ProviderSettings) {
+    if (!settings.apiKey) {
+      throw new Error('ModelScope API key is required to list models')
+    }
+
+    const dependencies = await createModelDependencies()
+    const modelscope = new ModelScope(
+      { apiKey: settings.apiKey, model: { modelId: '', capabilities: [] } },
+      dependencies,
+    )
+    return modelscope.listModels()
+  }

This makes failure modes clearer and keeps the type-safety aligned with runtime behavior.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 077a0ad and d6e8d77.

⛔ Files ignored due to path filters (1)
  • src/renderer/static/icons/providers/modelscope.png is excluded by !**/*.png
📒 Files selected for processing (9)
  • src/renderer/components/icons/ProviderIcon.tsx (1 hunks)
  • src/renderer/packages/model-setting-utils/index.ts (2 hunks)
  • src/renderer/packages/model-setting-utils/modelscope-setting-util.ts (1 hunks)
  • src/renderer/stores/migration.ts (3 hunks)
  • src/shared/defaults.ts (1 hunks)
  • src/shared/models/index.ts (4 hunks)
  • src/shared/models/modelscope.ts (1 hunks)
  • src/shared/types/provider.ts (1 hunks)
  • src/shared/utils/llm_utils.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/shared/utils/llm_utils.ts (1)
src/shared/types/session.ts (1)
  • ModelProviderEnum (7-7)
src/shared/models/modelscope.ts (2)
src/shared/models/openai-compatible.ts (1)
  • OpenAICompatibleSettings (10-19)
src/shared/types/adapters.ts (1)
  • ModelDependencies (27-32)
🔇 Additional comments (6)
src/shared/utils/llm_utils.ts (1)

123-140: ModelScope correctly marked as OpenAI‑compatible

Including ModelProviderEnum.ModelScope in the allowlist keeps ModelScope on the shared OpenAI‑compatible path alongside the other proxy-style providers; this is aligned with the new ModelScope model class and looks good.

src/shared/types/provider.ts (1)

4-24: ModelProviderEnum extension for ModelScope is consistent

The new ModelScope = 'modelscope' enum member fits cleanly with existing usage (defaults, models, migrations) and doesn’t alter any existing behavior.

src/renderer/packages/model-setting-utils/index.ts (1)

31-32: ModelScopeSettingUtil registration is correct

Registering ModelProviderEnum.ModelScopeModelScopeSettingUtil in the hash cleanly plugs the new provider into the existing settings resolution flow without affecting customs or other providers.

Also applies to: 37-56

src/shared/models/modelscope.ts (1)

1-28: ModelScope OpenAI‑compatible wrapper looks sound

The ModelScope class correctly extends OpenAICompatible, injects the fixed ModelScope host, and forwards all the relevant settings (apiKey, model, temperature, topP, maxOutputTokens, stream) to the base class while keeping a typed options snapshot. This should behave like the other OpenAI‑compatible providers with a fixed endpoint.

src/renderer/stores/migration.ts (1)

400-482: ModelScope settings and session migration logic is aligned with existing providers

The added handling in migrate_9_to_10 for modelscopeApiKey/modelscopeModel follows the same pattern as other providers: it seeds providers[ModelScope] from legacy settings and maps session modelId via the new ModelProviderEnum.ModelScope: 'modelscopeModel' entry. This should preserve existing ModelScope usage across upgrades without affecting other providers.

Also applies to: 488-593, 639-666

src/renderer/packages/model-setting-utils/modelscope-setting-util.ts (1)

7-15: Display name logic is clear and robust

The display name composition is straightforward and safely falls back to the raw model when there is no configured nickname. This is a good fit for UI display and handles missing providerSettings gracefully.

@yrk111222
Copy link
Author

Hi @themez ,
Could you please help review this PR at your convenience?
It addresses the following issue: #2655
Thank you!

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