fix2
This commit is contained in:
parent
acd6eb93e9
commit
184e7763ac
|
|
@ -42,10 +42,17 @@ function parseConfigured(raw: Record<string, unknown> | undefined): Record<Provi
|
|||
}
|
||||
|
||||
function pickModel(models: string[], current: string | undefined, fallback: string): string {
|
||||
if (current && models.includes(current)) return current
|
||||
const trimmed = current?.trim()
|
||||
if (trimmed) return trimmed
|
||||
return models[0] ?? fallback
|
||||
}
|
||||
|
||||
function mergeModelOptions(models: string[], current: string | undefined): string[] {
|
||||
const trimmed = current?.trim()
|
||||
if (!trimmed || models.includes(trimmed)) return models
|
||||
return [trimmed, ...models]
|
||||
}
|
||||
|
||||
export function AccountAiSettings({ accountId, compact }: AccountAiSettingsProps) {
|
||||
const [settings, setSettings] = useState<ThreadsAccountAiSettingsData | null>(null)
|
||||
const [keyInputs, setKeyInputs] = useState<ProviderApiKeys>({})
|
||||
|
|
@ -87,15 +94,12 @@ export function AccountAiSettings({ accountId, compact }: AccountAiSettingsProps
|
|||
const mainProvider = normalizeSupportedProvider(prev.provider)
|
||||
const researchProv = normalizeSupportedProvider(prev.research_provider ?? mainProvider)
|
||||
let next = prev
|
||||
if (providerId === mainProvider && !models.includes(prev.model)) {
|
||||
if (providerId === mainProvider && !prev.model?.trim()) {
|
||||
next = { ...next, model: models[0] }
|
||||
}
|
||||
if (providerId === researchProv) {
|
||||
const currentResearch = prev.research_model ?? ''
|
||||
if (!currentResearch || !models.includes(currentResearch)) {
|
||||
if (providerId === researchProv && !prev.research_model?.trim()) {
|
||||
next = { ...next, research_model: models[0] }
|
||||
}
|
||||
}
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
|
@ -175,6 +179,8 @@ export function AccountAiSettings({ accountId, compact }: AccountAiSettingsProps
|
|||
|
||||
const primaryModels = getModelsForProvider(provider)
|
||||
const researchModels = getModelsForProvider(researchProvider)
|
||||
const primaryModelOptions = mergeModelOptions(primaryModels, settings?.model)
|
||||
const researchModelOptions = mergeModelOptions(researchModels, settings?.research_model)
|
||||
const primaryModelsMeta = modelsMeta[provider]
|
||||
const researchModelsMeta = modelsMeta[researchProvider]
|
||||
const currentProviderConfigured = configured[provider]
|
||||
|
|
@ -288,18 +294,18 @@ export function AccountAiSettings({ accountId, compact }: AccountAiSettingsProps
|
|||
}
|
||||
>
|
||||
<Select
|
||||
value={primaryModels.includes(settings.model) ? settings.model : ''}
|
||||
disabled={primaryModelsMeta?.loading || primaryModels.length === 0}
|
||||
value={settings.model?.trim() ?? ''}
|
||||
disabled={primaryModelsMeta?.loading || primaryModelOptions.length === 0}
|
||||
onChange={(e) =>
|
||||
setSettings((prev) => (prev ? { ...prev, model: e.target.value } : prev))
|
||||
}
|
||||
>
|
||||
{primaryModels.length === 0 ? (
|
||||
{primaryModelOptions.length === 0 ? (
|
||||
<option value="">
|
||||
{primaryModelsMeta?.loading ? '載入中…' : '尚無可用模型'}
|
||||
</option>
|
||||
) : (
|
||||
primaryModels.map((model) => (
|
||||
primaryModelOptions.map((model) => (
|
||||
<option key={model} value={model}>
|
||||
{model}
|
||||
</option>
|
||||
|
|
@ -349,24 +355,20 @@ export function AccountAiSettings({ accountId, compact }: AccountAiSettingsProps
|
|||
}
|
||||
>
|
||||
<Select
|
||||
value={
|
||||
settings.research_model && researchModels.includes(settings.research_model)
|
||||
? settings.research_model
|
||||
: ''
|
||||
}
|
||||
disabled={researchModelsMeta?.loading || researchModels.length === 0}
|
||||
value={settings.research_model?.trim() ?? ''}
|
||||
disabled={researchModelsMeta?.loading || researchModelOptions.length === 0}
|
||||
onChange={(e) =>
|
||||
setSettings((prev) =>
|
||||
prev ? { ...prev, research_model: e.target.value } : prev,
|
||||
)
|
||||
}
|
||||
>
|
||||
{researchModels.length === 0 ? (
|
||||
{researchModelOptions.length === 0 ? (
|
||||
<option value="">
|
||||
{researchModelsMeta?.loading ? '載入中…' : '尚無可用模型'}
|
||||
</option>
|
||||
) : (
|
||||
researchModels.map((model) => (
|
||||
researchModelOptions.map((model) => (
|
||||
<option key={model} value={model}>
|
||||
{model}
|
||||
</option>
|
||||
|
|
|
|||
|
|
@ -82,9 +82,10 @@ export function resolveProviderApiToken(
|
|||
return value
|
||||
}
|
||||
|
||||
function normalizeModel(provider: ProviderId, model: string | undefined, fallback: string): string {
|
||||
const models = modelsForProvider(provider)
|
||||
if (model && models.includes(model)) return model
|
||||
function normalizeModel(_provider: ProviderId, model: string | undefined, fallback: string): string {
|
||||
const trimmed = model?.trim()
|
||||
if (trimmed) return trimmed
|
||||
const models = modelsForProvider(_provider)
|
||||
return models[0] ?? fallback
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue