Skip to content

Commit e8cc0fc

Browse files
authored
feat(zgsm): enhance model handling and configuration (#431)
* feat(zgsm): enhance model handling and configuration * fix(i18n): remove showCustomConfig text
1 parent 263b203 commit e8cc0fc

File tree

8 files changed

+38
-11
lines changed

8 files changed

+38
-11
lines changed

src/api/providers/zgsm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class ZgsmAiHandler extends BaseProvider implements SingleCompletionHandl
5757
const urlHost = this._getUrlHost(this.baseURL)
5858
const isAzureOpenAi = urlHost === "azure.com" || urlHost.endsWith(".azure.com") || options.openAiUseAzure
5959

60+
this.fetchModel()
6061
this.headers = {
6162
...COSTRICT_DEFAULT_HEADERS,
6263
...(this.options.openAiHeaders || {}),

src/shared/ExtensionMessage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
OrganizationAllowList,
1515
ShareVisibility,
1616
QueuedMessage,
17+
IZgsmModelResponseData,
1718
} from "@roo-code/types"
1819

1920
import { GitCommit } from "../utils/git"
@@ -172,7 +173,7 @@ export interface ExtensionMessage {
172173
openAiModels?: string[]
173174
ollamaModels?: ModelRecord
174175
lmStudioModels?: ModelRecord
175-
fullResponseData?: ModelInfo[]
176+
fullResponseData?: IZgsmModelResponseData[]
176177
vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
177178
huggingFaceModels?: Array<{
178179
id: string

webview-ui/src/components/settings/providers/ZgsmAI.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,15 @@ export const ZgsmAI = ({
124124

125125
switch (message.type) {
126126
case "zgsmModels": {
127-
const updatedModels = message.openAiModels ?? []
128-
setOpenAiModels(Object.fromEntries(updatedModels.map((item) => [item, zgsmModels.default])))
127+
const { openAiModels: updatedModels = [], fullResponseData = [] } = message
128+
setOpenAiModels(
129+
Object.fromEntries(
130+
updatedModels.map((modelId) => [
131+
modelId,
132+
fullResponseData?.find(({ id }) => id === modelId) ?? zgsmModels.default,
133+
]),
134+
),
135+
)
129136
break
130137
}
131138
}
@@ -175,7 +182,9 @@ export const ZgsmAI = ({
175182
onChange={(e: any) => {
176183
setCachedStateField("useZgsmCustomConfig", e.target.checked)
177184
}}>
178-
<label className="block font-medium mb-1">{t("settings:providers.showCustomConfig")}</label>
185+
<label className="block font-medium mb-1">
186+
{t("settings:providers.useZgsmCustomConfig")}
187+
</label>
179188
</VSCodeCheckbox>
180189
</div>
181190
</>

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const useSelectedModel = (apiConfiguration?: ProviderSettings) => {
9797
})
9898
: {
9999
id: apiConfiguration?.zgsmModelId || apiConfiguration?.apiModelId || zgsmDefaultModelId,
100-
info: zgsmModels.default,
100+
info: getZgsmModelFeedback({ apiConfiguration }, zgsmModels.default),
101101
}
102102

103103
return {
@@ -115,6 +115,24 @@ export const useSelectedModel = (apiConfiguration?: ProviderSettings) => {
115115
}
116116
}
117117

118+
function getZgsmModelFeedback(
119+
config: {
120+
provider?: ProviderName
121+
apiConfiguration?: ProviderSettings
122+
},
123+
defaultModelInfo: ModelInfo,
124+
): ModelInfo {
125+
const { apiConfiguration } = config
126+
if (
127+
apiConfiguration?.useZgsmCustomConfig &&
128+
apiConfiguration?.openAiCustomModelInfo &&
129+
JSON.stringify(apiConfiguration.openAiCustomModelInfo) !== "{}"
130+
) {
131+
return apiConfiguration.openAiCustomModelInfo
132+
}
133+
return defaultModelInfo
134+
}
135+
118136
function getSelectedModel({
119137
provider,
120138
apiConfiguration,
@@ -136,7 +154,8 @@ function getSelectedModel({
136154
switch (provider) {
137155
case "zgsm": {
138156
const id = apiConfiguration.zgsmModelId || apiConfiguration.apiModelId || zgsmDefaultModelId
139-
const info = routerModels.zgsm[id]
157+
const info = getZgsmModelFeedback({ apiConfiguration }, routerModels.zgsm[id] || zgsmModels.default)
158+
140159
return { id, info }
141160
}
142161
case "openrouter": {

webview-ui/src/i18n/costrict-i18n/locales/en/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"capabilities": "Configure the capabilities and pricing for your custom OpenAI-compatible model. Be careful when specifying the model capabilities, as they can affect how Costrict performs."
4343
},
4444
"useZgsmCustomConfig": "Use custom configuration",
45-
"showCustomConfig": "Show Model Custom Configuration",
4645
"geminiCli": {
4746
"projectIdDescription": "Specify your Google Cloud Project ID for enterprise or non-free tier access. Leave empty for automatic project discovery with personal accounts. If you encounter an API Error, it is recommended to fill in the Project ID."
4847
},

webview-ui/src/i18n/costrict-i18n/locales/zh-CN/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"capabilities": "配置您的自定义OpenAI兼容模型的功能和定价。在指定模型功能时要小心,因为它们会影响 Costrict 的表现。"
4343
},
4444
"useZgsmCustomConfig": "使用自定义配置",
45-
"showCustomConfig": "显示模型自定义配置",
4645
"geminiCli": {
4746
"projectIdDescription": "为企业或非免费套餐访问指定您的 Google Cloud 项目 ID。如使用个人账号并希望自动发现项目,请留空。如果您遇到 API 错误,建议填写项目ID。"
4847
},

webview-ui/src/i18n/costrict-i18n/locales/zh-TW/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
"customModel": {
4242
"capabilities": "配置您的自定義OpenAI兼容模型的功能和定價。在指定模型功能時要小心,因為它們會影響 Costrict 的表現。"
4343
},
44-
"useZgsmCustomConfig": "使用模型自定義配置",
45-
"showCustomConfig": "顯示自定義配置",
44+
"useZgsmCustomConfig": "使用自定義配置",
4645
"geminiCli": {
4746
"projectIdDescription": "若為企業或非免費方案存取,請指定您的 Google Cloud 專案 ID。如使用個人帳號並希望自動探索專案,請留空。如果您遇到 API 錯誤,建議填寫專案 ID。"
4847
},

webview-ui/src/utils/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export function validateModelId(apiConfiguration: ProviderSettings, routerModels
312312

313313
const models = routerModels?.[provider]
314314

315-
if (models && Object.keys(models).length > 1 && !Object.keys(models).includes(modelId)) {
315+
if (provider !== "zgsm" && models && Object.keys(models).length > 1 && !Object.keys(models).includes(modelId)) {
316316
return i18next.t("settings:validation.modelAvailability", { modelId })
317317
}
318318

0 commit comments

Comments
 (0)