feat(config): enhance model configuration with support for audio models and improve UI for user preferences

This commit is contained in:
HouYunFei
2026-06-02 17:24:27 +08:00
parent 39793e890d
commit 38ec654748
4 changed files with 151 additions and 34 deletions
+5 -7
View File
@@ -5,7 +5,7 @@ import { Cpu } from "lucide-react";
import { Select, SelectContent, SelectItem, SelectTrigger } from "@/components/ui/select";
import { cn } from "@/lib/utils";
import { filterModelsByCapability, type AiConfig, type ModelCapability } from "@/stores/use-config-store";
import { selectableModelsByCapability, type AiConfig, type ModelCapability } from "@/stores/use-config-store";
type ModelPickerProps = {
config: AiConfig;
@@ -21,7 +21,7 @@ type ModelPickerProps = {
export function ModelPicker({ config, value, onChange, capability, className, fullWidth = false, placeholder = "选择模型", onMissingConfig }: ModelPickerProps) {
const pickerId = useId();
const [open, setOpen] = useState(false);
const options = useMemo(() => filterModelsByCapability(Array.from(new Set([...(config.channelMode === "local" ? [value] : []), ...config.models].filter((model): model is string => Boolean(model)))), capability), [capability, config.channelMode, config.models, value]);
const options = useMemo(() => Array.from(new Set([...(config.channelMode === "local" && !capability ? [value] : []), ...selectableModelsByCapability(config, capability)].filter((model): model is string => Boolean(model)))), [capability, config, value]);
const current = value || "";
useEffect(() => {
@@ -37,10 +37,7 @@ export function ModelPicker({ config, value, onChange, capability, className, fu
open={open}
value={current}
onOpenChange={(nextOpen) => {
if (nextOpen && !options.length && config.channelMode === "local") {
onMissingConfig?.();
return;
}
if (nextOpen && !options.length && config.channelMode === "local") onMissingConfig?.();
if (nextOpen) window.dispatchEvent(new CustomEvent("model-picker-open", { detail: pickerId }));
setOpen(nextOpen);
}}
@@ -87,8 +84,9 @@ export function ModelPicker({ config, value, onChange, capability, className, fu
}
function emptyModelLabel(config: AiConfig, capability?: ModelCapability) {
const label = capability === "image" ? "生图" : capability === "video" ? "视频" : capability === "text" ? "文本" : "";
const label = capability === "image" ? "生图" : capability === "video" ? "视频" : capability === "text" ? "文本" : capability === "audio" ? "音频" : "";
if (config.channelMode === "remote") return `暂无可用${label}模型`;
if (capability && config.models.length) return "请先在上方配置可选模型";
return config.models.length ? `暂无匹配的${label}模型` : "请先到配置里拉取模型列表";
}