diff --git a/docs/docs/config.mdx b/docs/docs/config.mdx index 9a211c3cc4..bf4977abbc 100644 --- a/docs/docs/config.mdx +++ b/docs/docs/config.mdx @@ -45,6 +45,7 @@ wsh editconfig | ai:apiversion | string | for Azure AI only (when apitype is "azure", this will default to "2023-05-15") | | ai:orgid | string | | | ai:maxtokens | int | max tokens to pass to API | +| ai:maxtokensfield | string | name of the max tokens field in request to be compatible with the model api (default: max_tokens) | | ai:timeoutms | int | timeout (in milliseconds) for AI calls | | conn:askbeforewshinstall | bool | set to false to disable popup asking if you want to install wsh extensions on new machines | | term:fontsize | float | the fontsize for the terminal block | diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 4f399e0e34..0ac0fd8503 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -692,6 +692,7 @@ declare global { "ai:orgid"?: string; "ai:apiversion"?: string; "ai:maxtokens"?: number; + "ai:maxtokensfield"?: string; "ai:timeoutms"?: number; "ai:fontsize"?: number; "ai:fixedfontsize"?: number; diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index 0185b3bc24..5a2c85f19c 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -21,6 +21,7 @@ const ( ConfigKey_AiOrgID = "ai:orgid" ConfigKey_AIApiVersion = "ai:apiversion" ConfigKey_AiMaxTokens = "ai:maxtokens" + ConfigKey_AiMaxTokensField = "ai:maxtokensfield" ConfigKey_AiTimeoutMs = "ai:timeoutms" ConfigKey_AiFontSize = "ai:fontsize" ConfigKey_AiFixedFontSize = "ai:fixedfontsize" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index 814d3d46a9..c09bd1c5fc 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -43,6 +43,7 @@ type AiSettingsType struct { AiOrgID string `json:"ai:orgid,omitempty"` AIApiVersion string `json:"ai:apiversion,omitempty"` AiMaxTokens float64 `json:"ai:maxtokens,omitempty"` + AiMaxTokensField string `json:"ai:maxtokensfield,omitempty"` AiTimeoutMs float64 `json:"ai:timeoutms,omitempty"` AiFontSize float64 `json:"ai:fontsize,omitempty"` AiFixedFontSize float64 `json:"ai:fixedfontsize,omitempty"` @@ -66,6 +67,7 @@ type SettingsType struct { AiOrgID string `json:"ai:orgid,omitempty"` AIApiVersion string `json:"ai:apiversion,omitempty"` AiMaxTokens float64 `json:"ai:maxtokens,omitempty"` + AiMaxTokensField string `json:"ai:maxtokensfield,omitempty"` AiTimeoutMs float64 `json:"ai:timeoutms,omitempty"` AiFontSize float64 `json:"ai:fontsize,omitempty"` AiFixedFontSize float64 `json:"ai:fixedfontsize,omitempty"` @@ -405,6 +407,9 @@ func ReadFullConfig() FullConfigType { continue } else { configPart, errs = readConfigPart(jsonTag, simpleMerge) + if jsonTag == "settings" { + configPart = normalizeSettingsAliases(configPart) + } } fullConfig.ConfigErrors = append(fullConfig.ConfigErrors, errs...) if configPart != nil { @@ -458,6 +463,32 @@ func getConfigKeyNamespace(key string) string { return key[:colonIdx] } +// Alias map for settings keys to support alternate names in user config. +// Canonical key is on the right-hand side. +var settingsAliasKeyMap = map[string]string{ + "ai:max_tokens": "ai:maxtokens", + "ai:max_tokens_param": "ai:maxtokensfield", + "ai:max_tokens_field": "ai:maxtokensfield", + "ai:maxtokenfields": "ai:maxtokensfield", + "ai:maxtokenfield": "ai:maxtokensfield", +} +// normalizeSettingsAliases rewrites known alias keys in-place to their canonical forms. +// If both alias and canonical exist, the canonical value wins and the alias is removed. +func normalizeSettingsAliases(m waveobj.MetaMapType) waveobj.MetaMapType { + if m == nil { + return nil + } + for alias, canonical := range settingsAliasKeyMap { + if val, ok := m[alias]; ok { + if _, exists := m[canonical]; !exists { + m[canonical] = val + } + delete(m, alias) + } + } + return m +} + func orderConfigKeys(m waveobj.MetaMapType) []string { keys := make([]string, 0, len(m)) for k := range m { @@ -561,6 +592,7 @@ func SetBaseConfigValue(toMerge waveobj.MetaMapType) error { if m == nil { m = make(waveobj.MetaMapType) } + toMerge = normalizeSettingsAliases(toMerge) for configKey, val := range toMerge { ctype := getConfigKeyType(configKey) if ctype == nil { diff --git a/schema/aipresets.json b/schema/aipresets.json index db6d2b052e..4b677bf40e 100644 --- a/schema/aipresets.json +++ b/schema/aipresets.json @@ -33,6 +33,24 @@ "ai:maxtokens": { "type": "number" }, + "ai:maxtokensfield": { + "type": "string" + }, + "ai:max_tokens_field": { + "type": "string", + "deprecated": true, + "description": "Alias of ai:maxtokensfield" + }, + "ai:max_tokens_param": { + "type": "string", + "deprecated": true, + "description": "Alias of ai:maxtokensfield" + }, + "ai:maxtokenfields": { + "type": "string", + "deprecated": true, + "description": "Alias of ai:maxtokensfield" + }, "ai:timeoutms": { "type": "number" }, diff --git a/schema/settings.json b/schema/settings.json index 395974b573..d8d9f5fbdb 100644 --- a/schema/settings.json +++ b/schema/settings.json @@ -47,6 +47,9 @@ "ai:maxtokens": { "type": "number" }, + "ai:maxtokensfield": { + "type": "string" + }, "ai:timeoutms": { "type": "number" },