-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add Huawei Cloud MaaS provider #2415
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
Open
ddling
wants to merge
1
commit into
chatboxai:main
Choose a base branch
from
ddling:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/renderer/packages/model-setting-utils/huaweicloud-maas-setting-util.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { ModelProvider, ModelProviderEnum, ProviderSettings, SessionType } from 'src/shared/types' | ||
| import { ModelSettingUtil } from './interface' | ||
| import HuaweiCloudMaaS from '../models/huaweicloud-maas' | ||
| import BaseConfig from './base-config' | ||
|
|
||
| export default class HuaweiCloudMAASSettingUtil extends BaseConfig implements ModelSettingUtil { | ||
| public provider: ModelProvider = ModelProviderEnum.HuaweiCloudMaaS | ||
|
|
||
| async getCurrentModelDisplayName( | ||
| model: string, | ||
| sessionType: SessionType, | ||
| providerSettings?: ProviderSettings | ||
| ): Promise<string> { | ||
| return `HuaweiCloudMaaS API (${providerSettings?.models?.find((m) => m.modelId === model)?.nickname || model})` | ||
| } | ||
|
|
||
| public getLocalOptionGroups() { | ||
| // HuaweiCloudMaaS支持的所有模型 | ||
|
|
||
| const deepseekModels = [ | ||
| 'deepseek-r1-250528', | ||
| 'DeepSeek-V3', | ||
| 'DeepSeek-R1' | ||
| ] | ||
|
|
||
| const qwenModels = [ | ||
| 'qwen3-235b-a22b', | ||
| 'qwen3-32b' | ||
| ] | ||
|
|
||
| return [ | ||
| { | ||
| group_name: 'DeepSeek 系列', | ||
| options: deepseekModels.map((value) => ({ | ||
| label: value, | ||
| value: value, | ||
| })), | ||
| collapsable: true, | ||
| }, | ||
| { | ||
| group_name: '千问 系列', | ||
| options: qwenModels.map((value) => ({ | ||
| label: value, | ||
| value: value, | ||
| })), | ||
| collapsable: true, | ||
| }, | ||
| ] | ||
| } | ||
|
|
||
| protected async listProviderModels() { | ||
| return [] | ||
| } | ||
|
|
||
| isCurrentModelSupportImageInput(model: string): boolean { | ||
| return HuaweiCloudMaaS.helpers.isModelSupportVision(model) | ||
| } | ||
|
|
||
| isCurrentModelSupportToolUse(model: string): boolean { | ||
| return HuaweiCloudMaaS.helpers.isModelSupportToolUse(model) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { fetchWithProxy } from '@/utils/request' | ||
| import { createOpenAICompatible } from '@ai-sdk/openai-compatible' | ||
| import { extractReasoningMiddleware, wrapLanguageModel } from 'ai' | ||
| import AbstractAISDKModel from './abstract-ai-sdk' | ||
| import { ProviderModelInfo } from 'src/shared/types' | ||
| import { fetchRemoteModels } from './openai-compatible' | ||
|
|
||
| const helpers = { | ||
| isModelSupportVision: (model: string) => { | ||
| // HuaweiCloudMaaS支持视觉的模型 | ||
| return false | ||
| }, | ||
| isModelSupportToolUse: (model: string) => { | ||
| // HuaweiCloudMaaS支持工具使用的模型(除了纯图像生成和推理专用模型) | ||
| const nonToolModels = [ | ||
| 'qwen3-235b-a22b', | ||
| 'qwen3-32b' | ||
| ] | ||
| return !nonToolModels.some(nonToolModel => model.includes(nonToolModel)) | ||
| }, | ||
| } | ||
|
|
||
| interface Options { | ||
| apiKey: string | ||
| apiHost: string | ||
| model: ProviderModelInfo | ||
| temperature?: number | ||
| topP?: number | ||
| useProxy?: boolean | ||
| } | ||
|
|
||
| export default class HuaweiCloudMaaS extends AbstractAISDKModel { | ||
| public name = 'HuaweiCloudMaaS' | ||
| public static helpers = helpers | ||
| public options: Options | ||
|
|
||
| constructor(options: Options) { | ||
| super(options) | ||
| this.options = { | ||
| ...options, | ||
| apiHost: options.apiHost || 'https://ai.huaweicloud.com/v1', | ||
| } | ||
| } | ||
|
|
||
| public isSupportToolUse() { | ||
| return helpers.isModelSupportToolUse(this.options.model.modelId) | ||
| } | ||
|
|
||
| private getProvider() { | ||
| return createOpenAICompatible({ | ||
| name: 'HuaweiCloudMaaS', | ||
| apiKey: this.options.apiKey, | ||
| baseURL: this.options.apiHost, | ||
| fetch: this.options.useProxy ? fetchWithProxy : undefined, | ||
| }) | ||
| } | ||
|
|
||
| protected getChatModel() { | ||
| const provider = this.getProvider() | ||
| return wrapLanguageModel({ | ||
| model: provider.languageModel(this.options.model.modelId), | ||
| middleware: extractReasoningMiddleware({ tagName: 'think' }), | ||
| }) | ||
| } | ||
|
|
||
| protected getImageModel() { | ||
| const provider = this.getProvider() | ||
| return provider.imageModel('dall-e-3') | ||
| } | ||
|
|
||
| protected getCallSettings() { | ||
| return { | ||
| temperature: this.options.temperature, | ||
| topP: this.options.topP, | ||
| } | ||
| } | ||
|
|
||
| public async listModels(): Promise<string[]> { | ||
| return fetchRemoteModels({ | ||
| apiHost: this.options.apiHost, | ||
| apiKey: this.options.apiKey, | ||
| useProxy: this.options.useProxy, | ||
| }).catch((err) => { | ||
| console.error('HuaweiCloudMaaS models fetch error:', err) | ||
| // 返回HuaweiCloudMaaS支持的常见模型作为备选 | ||
| return [ | ||
| 'deepseek-r1-250528', | ||
| 'DeepSeek-V3', | ||
| 'DeepSeek-R1', | ||
| 'qwen3-235b-a22b', | ||
| 'qwen3-32b' | ||
| ] | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Model instantiation is correct but missing UI mappings.
The model instantiation follows the established pattern and uses appropriate constructor parameters. However, HuaweiCloudMaaS is missing from both
aiProviderNameHash(lines 195-211) andAIModelProviderMenuOptionList(lines 213-285), which are likely used for UI display purposes.Add the missing entries to enable proper UI display:
export const aiProviderNameHash: Record<ModelProvider, string> = { [ModelProviderEnum.OpenAI]: 'OpenAI API', [ModelProviderEnum.Azure]: 'Azure OpenAI API', [ModelProviderEnum.ChatGLM6B]: 'ChatGLM API', [ModelProviderEnum.ChatboxAI]: 'Chatbox AI', [ModelProviderEnum.Claude]: 'Claude API', [ModelProviderEnum.Gemini]: 'Google Gemini API', [ModelProviderEnum.Ollama]: 'Ollama API', [ModelProviderEnum.Groq]: 'Groq API', [ModelProviderEnum.DeepSeek]: 'DeepSeek API', [ModelProviderEnum.SiliconFlow]: 'SiliconFlow API', [ModelProviderEnum.VolcEngine]: 'VolcEngine API', [ModelProviderEnum.LMStudio]: 'LM Studio API', [ModelProviderEnum.Perplexity]: 'Perplexity API', [ModelProviderEnum.XAI]: 'xAI API', + [ModelProviderEnum.HuaweiCloudMaaS]: 'HuaweiCloudMaaS API', [ModelProviderEnum.Custom]: 'Custom Provider', }And add to the menu options list:
export const AIModelProviderMenuOptionList = [ // ... existing entries ... { value: ModelProviderEnum.ChatGLM6B, label: aiProviderNameHash[ModelProviderEnum.ChatGLM6B], disabled: false, }, + { + value: ModelProviderEnum.HuaweiCloudMaaS, + label: aiProviderNameHash[ModelProviderEnum.HuaweiCloudMaaS], + disabled: false, + }, ]🤖 Prompt for AI Agents