Skip to content

Commit cebcbcc

Browse files
authored
Merge branch 'main' into stream_mode
2 parents be79ee2 + 644d3a9 commit cebcbcc

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/pages/Setting/Models.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import { useAuthStore } from "@/store/authStore";
4040
import { toast } from "sonner";
4141
import { useTranslation } from "react-i18next";
4242

43+
const LOCAL_PROVIDER_NAMES = ["ollama", "vllm", "sglang", "lmstudio"];
44+
4345
export default function SettingModels() {
4446
const { modelType, cloud_model_type, setModelType, setCloudModelType } =
4547
useAuthStore();
@@ -137,12 +139,16 @@ const [errors, setErrors] = useState<
137139
);
138140
// Handle local model
139141
const local = providerList.find(
140-
(p: any) => p.provider_name === "Local Model"
142+
(p: any) => LOCAL_PROVIDER_NAMES.includes(p.provider_name)
141143
);
142144
console.log(123123, local);
143145
if (local) {
144146
setLocalEndpoint(local.endpoint_url || "");
145-
setLocalPlatform(local.encrypted_config?.model_platform || "ollama");
147+
setLocalPlatform(
148+
local.encrypted_config?.model_platform ||
149+
local.provider_name ||
150+
"ollama"
151+
);
146152
setLocalType(local.encrypted_config?.model_type || "llama3.2");
147153
setLocalEnabled(local.is_valid ?? true);
148154
setLocalPrefer(local.prefer ?? false);
@@ -426,10 +432,14 @@ const [errors, setErrors] = useState<
426432
(p: any) => p.provider_name === localPlatform
427433
);
428434
if (local) {
429-
handleLocalSwitch(true);
430-
431435
setLocalProviderId(local.id);
432436
setLocalPrefer(local.prefer ?? false);
437+
setLocalPlatform(
438+
local.encrypted_config?.model_platform ||
439+
local.provider_name ||
440+
localPlatform
441+
);
442+
await handleLocalSwitch(true, local.id);
433443
}
434444
} catch (e: any) {
435445
setLocalError(
@@ -487,7 +497,7 @@ const [errors, setErrors] = useState<
487497
// Optional: add error message
488498
}
489499
};
490-
const handleLocalSwitch = async (checked: boolean) => {
500+
const handleLocalSwitch = async (checked: boolean, providerId?: number) => {
491501
if (!checked) {
492502
setLocalEnabled(false);
493503
return;
@@ -503,15 +513,18 @@ const [errors, setErrors] = useState<
503513
});
504514
}
505515
try {
506-
if (localProviderId === undefined) return;
516+
const targetProviderId =
517+
providerId !== undefined ? providerId : localProviderId;
518+
if (targetProviderId === undefined) return;
507519
await proxyFetchPost("/api/provider/prefer", {
508-
provider_id: localProviderId,
520+
provider_id: targetProviderId,
509521
});
510522
setModelType("local");
511523
setLocalEnabled(true);
512524
setActiveModelIdx(null);
513525
setForm((f) => f.map((fi) => ({ ...fi, prefer: false }))); // Set all others' prefer to false
514526
setLocalPrefer(true);
527+
setCloudPrefer(false);
515528
} catch (e) {
516529
// Optional: add error message
517530
}

0 commit comments

Comments
 (0)