Unverified 提交 a7bcec22 authored 作者: Adeniji Adekunle James's avatar Adeniji Adekunle James 提交者: GitHub

Fix: Custom Model Not Updating (#1817) (#1840)

Closes (#1817) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes the bug where editing a custom model didn’t update the currently selected model. The selection now stays in sync after renaming or editing. - **Bug Fixes** - Use useSettings to detect if the edited model is the active one (match provider and apiName). - Update settings.selectedModel with the new apiName; on failure show an error and keep the dialog open; otherwise show success, call onSuccess, then close. <sup>Written for commit 88045165a3989277e703a8f31712fcf1dfeaa32a. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
上级 20866d5d
......@@ -11,6 +11,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { IpcClient } from "@/ipc/ipc_client";
import { useSettings } from "@/hooks/useSettings";
import { useMutation } from "@tanstack/react-query";
import { showError, showSuccess } from "@/lib/toast";
......@@ -44,6 +45,7 @@ export function EditCustomModelDialog({
const [description, setDescription] = useState("");
const [maxOutputTokens, setMaxOutputTokens] = useState<string>("");
const [contextWindow, setContextWindow] = useState<string>("");
const { settings, updateSettings } = useSettings();
const ipcClient = IpcClient.getInstance();
......@@ -89,7 +91,22 @@ export function EditCustomModelDialog({
// Then create the new model
await ipcClient.createCustomLanguageModel(newParams);
},
onSuccess: () => {
onSuccess: async () => {
if (
settings?.selectedModel?.name === model?.apiName &&
settings?.selectedModel?.provider === providerId
) {
const newModel = {
...settings.selectedModel,
name: apiName,
};
try {
await updateSettings({ selectedModel: newModel });
} catch {
showError("Failed to update settings");
return; // stop closing dialog
}
}
showSuccess("Custom model updated successfully!");
onSuccess();
onClose();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论