-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add Z.ai coding plan support #8003
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |
| type InternationalZAiModelId, | ||
| type MainlandZAiModelId, | ||
| ZAI_DEFAULT_TEMPERATURE, | ||
| zaiApiLineConfigs, | ||
| } from "@roo-code/types" | ||
|
|
||
| import type { ApiHandlerOptions } from "../../shared/api" | ||
|
|
@@ -14,14 +15,14 @@ import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider" | |
|
|
||
| export class ZAiHandler extends BaseOpenAiCompatibleProvider<InternationalZAiModelId | MainlandZAiModelId> { | ||
| constructor(options: ApiHandlerOptions) { | ||
| const isChina = options.zaiApiLine === "china" | ||
| const isChina = zaiApiLineConfigs[options.zaiApiLine ?? "international_coding"].isChina | ||
|
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. Is the change in default from "international" to "international_coding" intentional? This is a breaking change for existing users who haven't specified a . Consider documenting this change clearly or maintaining backward compatibility by defaulting to "international" instead. |
||
| const models = isChina ? mainlandZAiModels : internationalZAiModels | ||
| const defaultModelId = isChina ? mainlandZAiDefaultModelId : internationalZAiDefaultModelId | ||
|
|
||
| super({ | ||
| ...options, | ||
| providerName: "Z AI", | ||
| baseURL: isChina ? "https://open.bigmodel.cn/api/paas/v4" : "https://api.z.ai/api/paas/v4", | ||
| baseURL: zaiApiLineConfigs[options.zaiApiLine ?? "international_coding"].baseUrl, | ||
| apiKey: options.zaiApiKey ?? "not-provided", | ||
| defaultProviderModelId: defaultModelId, | ||
| providerModels: models, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { useCallback } from "react" | ||
| import { VSCodeTextField, VSCodeDropdown, VSCodeOption } from "@vscode/webview-ui-toolkit/react" | ||
|
|
||
| import type { ProviderSettings } from "@roo-code/types" | ||
| import { zaiApiLineConfigs, zaiApiLineSchema, type ProviderSettings } from "@roo-code/types" | ||
|
|
||
| import { useAppTranslation } from "@src/i18n/TranslationContext" | ||
| import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink" | ||
|
|
@@ -33,15 +33,17 @@ export const ZAi = ({ apiConfiguration, setApiConfigurationField }: ZAiProps) => | |
| <div> | ||
| <label className="block font-medium mb-1">{t("settings:providers.zaiEntrypoint")}</label> | ||
| <VSCodeDropdown | ||
| value={apiConfiguration.zaiApiLine || "international"} | ||
| value={apiConfiguration.zaiApiLine || zaiApiLineSchema.enum.international_coding} | ||
| onChange={handleInputChange("zaiApiLine")} | ||
| className={cn("w-full")}> | ||
| <VSCodeOption value="international" className="p-2"> | ||
| api.z.ai | ||
| </VSCodeOption> | ||
| <VSCodeOption value="china" className="p-2"> | ||
| open.bigmodel.cn | ||
| </VSCodeOption> | ||
| {zaiApiLineSchema.options.map((zaiApiLine) => { | ||
| const config = zaiApiLineConfigs[zaiApiLine] | ||
| return ( | ||
| <VSCodeOption key={zaiApiLine} value={zaiApiLine} className="p-2"> | ||
| {config.name} ({config.baseUrl}) | ||
|
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. Consider showing just the name in the dropdown and moving the URL to the description/help text below for better UI clarity. The current format with both name and URL might be a bit verbose: |
||
| </VSCodeOption> | ||
| ) | ||
| })} | ||
| </VSCodeDropdown> | ||
| <div className="text-xs text-vscode-descriptionForeground mt-1"> | ||
| {t("settings:providers.zaiEntrypointDescription")} | ||
|
|
@@ -62,7 +64,7 @@ export const ZAi = ({ apiConfiguration, setApiConfigurationField }: ZAiProps) => | |
| {!apiConfiguration?.zaiApiKey && ( | ||
| <VSCodeButtonLink | ||
| href={ | ||
| apiConfiguration.zaiApiLine === "china" | ||
| zaiApiLineConfigs[apiConfiguration.zaiApiLine ?? "international_coding"].isChina | ||
| ? "https://open.bigmodel.cn/console/overview" | ||
| : "https://z.ai/manage-apikey/apikey-list" | ||
| } | ||
|
|
||
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.
Would it be beneficial to add explicit test cases for the new "international_coding" and "china_coding" options? Currently, the tests only cover "international" and "china" options, but not the new coding-specific plans.