mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix: add model to provider
This commit is contained in:
@@ -11,6 +11,7 @@ import { getModelsByProviderId, getModelKind } from "@/shared/constants/models";
|
|||||||
import { getThinkingLevels } from "open-sse/providers/thinkingLevels.js";
|
import { getThinkingLevels } from "open-sse/providers/thinkingLevels.js";
|
||||||
import { useCopyToClipboard } from "@/shared/hooks/useCopyToClipboard";
|
import { useCopyToClipboard } from "@/shared/hooks/useCopyToClipboard";
|
||||||
import { useModelCaps } from "@/shared/hooks/useModelCaps";
|
import { useModelCaps } from "@/shared/hooks/useModelCaps";
|
||||||
|
import { useNotificationStore } from "@/store/notificationStore";
|
||||||
import { translate } from "@/i18n/runtime";
|
import { translate } from "@/i18n/runtime";
|
||||||
import { fetchSuggestedModels } from "@/shared/utils/providerModelsFetcher";
|
import { fetchSuggestedModels } from "@/shared/utils/providerModelsFetcher";
|
||||||
import { getProviderCustomModelRows } from "@/shared/utils/providerCustomModels";
|
import { getProviderCustomModelRows } from "@/shared/utils/providerCustomModels";
|
||||||
@@ -80,6 +81,7 @@ export default function ProviderDetailPage() {
|
|||||||
const stopOneByOneRef = useRef(false);
|
const stopOneByOneRef = useRef(false);
|
||||||
const [importingQoderModels, setImportingQoderModels] = useState(false);
|
const [importingQoderModels, setImportingQoderModels] = useState(false);
|
||||||
const { copied, copy } = useCopyToClipboard();
|
const { copied, copy } = useCopyToClipboard();
|
||||||
|
const notify = useNotificationStore();
|
||||||
|
|
||||||
const AG_RISK_STORAGE_KEY = "ag_risk_confirmed";
|
const AG_RISK_STORAGE_KEY = "ag_risk_confirmed";
|
||||||
|
|
||||||
@@ -504,22 +506,35 @@ export default function ProviderDetailPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleAddCustomModel = async (modelId, type = "llm", providerAliasOverride = providerStorageAlias) => {
|
const handleAddCustomModel = async (modelId, type = "llm", providerAliasOverride = providerStorageAlias) => {
|
||||||
|
const fullModel = `${providerAliasOverride}/${modelId}`;
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/models/custom", {
|
const res = await fetch("/api/models/custom", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ providerAlias: providerAliasOverride, id: modelId, type }),
|
body: JSON.stringify({ providerAlias: providerAliasOverride, id: modelId, type }),
|
||||||
});
|
});
|
||||||
|
const data = await res.json().catch(() => ({}));
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
await fetchCustomModels();
|
// A built-in model that was permanently deleted is hidden by its
|
||||||
|
// tombstone. Refresh both sources so restoring it is visible at once.
|
||||||
|
await Promise.all([fetchCustomModels(), fetchDeletedModels()]);
|
||||||
if (typeof window !== "undefined") window.dispatchEvent(new CustomEvent("customModelChanged"));
|
if (typeof window !== "undefined") window.dispatchEvent(new CustomEvent("customModelChanged"));
|
||||||
|
if (data.restored) {
|
||||||
|
notify.success(`${fullModel} has been restored.`);
|
||||||
|
} else if (data.added) {
|
||||||
|
notify.success(`${fullModel} has been added.`);
|
||||||
|
} else {
|
||||||
|
notify.info(`${fullModel} is already available.`);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
} else {
|
} else {
|
||||||
const data = await res.json();
|
notify.error(data.error || `Failed to add ${fullModel}.`);
|
||||||
alert(data.error || "Failed to add custom model");
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error adding custom model:", error);
|
console.log("Error adding custom model:", error);
|
||||||
|
notify.error(`Failed to add ${fullModel}. Check the connection and try again.`);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteCustomModel = async (modelId, type = "llm", providerAliasOverride = providerStorageAlias) => {
|
const handleDeleteCustomModel = async (modelId, type = "llm", providerAliasOverride = providerStorageAlias) => {
|
||||||
@@ -1706,8 +1721,9 @@ export default function ProviderDetailPage() {
|
|||||||
providerAlias={providerStorageAlias}
|
providerAlias={providerStorageAlias}
|
||||||
providerDisplayAlias={providerDisplayAlias}
|
providerDisplayAlias={providerDisplayAlias}
|
||||||
onSave={async (modelId) => {
|
onSave={async (modelId) => {
|
||||||
await handleAddCustomModel(modelId, "llm", providerStorageAlias);
|
const result = await handleAddCustomModel(modelId, "llm", providerStorageAlias);
|
||||||
setShowAddCustomModel(false);
|
if (result) setShowAddCustomModel(false);
|
||||||
|
return result;
|
||||||
}}
|
}}
|
||||||
onClose={() => setShowAddCustomModel(false)}
|
onClose={() => setShowAddCustomModel(false)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user