Files
DeepTutor/web/components/knowledge/EmbeddingModelSelector.tsx
Bingxi Zhao (Frank) da856ad670 release: v1.6.9
Ship folder-based workspaces and data migration, daily practice, redesigned
provider and model settings, and streaming conversation improvements.
Synchronize README translations and document the archive/permanent-delete
upgrade behavior in assets/releases/ver1-6-9.md.

Reduce initial JavaScript by deduplicating English resources and loading
animation features after hydration. Keep the existing route size budgets.
Update regression fixtures and browser audits for scoped URLs and the new
settings and learning interfaces.
2026-09-21 02:30:40 +08:00

71 lines
2.3 KiB
TypeScript

"use client";
import { useId } from "react";
import { useTranslation } from "react-i18next";
import Link from "next/link";
import type { useEmbeddingModels } from "@/hooks/useEmbeddingModels";
export default function EmbeddingModelSelector({
catalog,
disabled = false,
}: {
catalog: ReturnType<typeof useEmbeddingModels>;
disabled?: boolean;
}) {
const { t } = useTranslation();
const id = useId();
const key = (selection: { profile_id: string; model_id: string }) =>
JSON.stringify([selection.profile_id, selection.model_id]);
return (
<div className="space-y-2">
<label htmlFor={id} className="block text-xs font-medium">
{t("Embedding model")}
</label>
<select
id={id}
value={catalog.selection ? key(catalog.selection) : ""}
disabled={disabled || catalog.loading || !!catalog.error}
onChange={(event) => {
const selected = catalog.options.find(
(option) => key(option) === event.target.value,
);
catalog.setSelection(
selected
? { profile_id: selected.profile_id, model_id: selected.model_id }
: null,
);
}}
className="w-full rounded-lg border border-[var(--border)] bg-[var(--background)] px-3 py-2 text-sm"
>
<option value="">
{catalog.loading ? t("Loading...") : t("Select an embedding model")}
</option>
{catalog.options.map((option) => (
<option key={key(option)} value={key(option)}>
{option.label} · {option.profile_name}
{option.detail ? ` · ${option.detail}` : ""}
</option>
))}
</select>
<p className="text-xs text-[var(--muted-foreground)]">
{t(
"This knowledge base keeps using the selected model when the global default changes.",
)}
</p>
{catalog.error && (
<p role="alert" className="text-xs text-red-600">
{catalog.error}
</p>
)}
{!catalog.loading && !catalog.error && catalog.options.length === 0 && (
<Link
href="/settings/embedding"
className="text-xs text-[var(--primary)]"
>
{t("Configure an embedding model in Settings first.")}
</Link>
)}
</div>
);
}