fix: pass through user-configured model name instead of overriding with first API model
CoStrict provider now directly passes the user's configured model name to the API, instead of replacing it with the first model from the /ai-gateway/api/v1/models list. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3e8a82d01c
commit
98c9f219f7
|
|
@ -17,10 +17,9 @@ function getModelFamily(model: string): 'haiku' | 'sonnet' | 'opus' | null {
|
|||
*
|
||||
* 优先级:
|
||||
* 1. 传入的 model 本身就是已知的 CoStrict 模型 ID(用户通过 /model 明确选择)
|
||||
* 2. COSTRICT_MODEL 环境变量(管理员全局覆盖 / 登录默认值)
|
||||
* 3. COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量(按模型族)
|
||||
* 4. 已缓存的 CoStrict 模型列表中的第一个
|
||||
* 5. 直接透传原始模型名(最后兜底)
|
||||
* 2. COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量(按模型族)
|
||||
* 3. 直接透传原始模型名(用户手动配置的模型名)
|
||||
* 4. COSTRICT_MODEL 环境变量(仅作为最终兜底)
|
||||
*/
|
||||
export function resolveCoStrictModel(anthropicModel: string): string {
|
||||
const cleanModel = anthropicModel.replace(/\[1m\]$/, '')
|
||||
|
|
@ -29,10 +28,7 @@ export function resolveCoStrictModel(anthropicModel: string): string {
|
|||
const cached = getCachedCoStrictModels()
|
||||
if (cached.some(m => m.id === cleanModel)) return cleanModel
|
||||
|
||||
// 优先级 2: COSTRICT_MODEL 环境变量
|
||||
if (process.env.COSTRICT_MODEL) return process.env.COSTRICT_MODEL
|
||||
|
||||
// 优先级 3: COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量
|
||||
// 优先级 2: COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量
|
||||
const family = getModelFamily(cleanModel)
|
||||
if (family) {
|
||||
const envVar = `COSTRICT_DEFAULT_${family.toUpperCase()}_MODEL`
|
||||
|
|
@ -40,9 +36,6 @@ export function resolveCoStrictModel(anthropicModel: string): string {
|
|||
if (override) return override
|
||||
}
|
||||
|
||||
// 优先级 4: 缓存中的第一个模型
|
||||
if (cached.length > 0) return cached[0].id
|
||||
|
||||
// 优先级 5: 透传原始模型名
|
||||
// 优先级 3: 直接透传原始模型名(用户手动配置的模型名优先于环境变量)
|
||||
return cleanModel
|
||||
}
|
||||
|
|
|
|||
|
|
@ -433,9 +433,8 @@ export async function setup(
|
|||
// 预取模型列表,填充同步缓存
|
||||
const baseUrl = getCoStrictBaseURL(activeCreds.base_url)
|
||||
const models = await fetchCoStrictModels(baseUrl, activeCreds.access_token)
|
||||
if (models.length > 0 && !process.env.COSTRICT_MODEL) {
|
||||
process.env.COSTRICT_MODEL = models[0].id
|
||||
}
|
||||
// 模型列表已预取并缓存,不再自动设置 COSTRICT_MODEL 环境变量
|
||||
// resolveCoStrictModel() 会直接透传用户配置的模型名
|
||||
process.env.CLAUDE_CODE_USE_COSTRICT = '1'
|
||||
} catch {
|
||||
// 初始化失败不阻断启动
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user