mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:49:51 +08:00
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.
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { getEngineModelOptions } from "@/features/knowledge/api/engines";
|
|
import type {
|
|
EmbeddingModelSelection,
|
|
ModelOption,
|
|
} from "@/features/knowledge/model/types";
|
|
|
|
export function useEmbeddingModels(
|
|
preferred?: EmbeddingModelSelection,
|
|
enabled = true,
|
|
) {
|
|
const [options, setOptions] = useState<ModelOption[]>([]);
|
|
const [selection, setSelection] = useState<EmbeddingModelSelection | null>(
|
|
preferred || null,
|
|
);
|
|
const [loading, setLoading] = useState(enabled);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const profileId = preferred?.profile_id;
|
|
const modelId = preferred?.model_id;
|
|
useEffect(() => {
|
|
if (!enabled) return;
|
|
let cancelled = false;
|
|
void Promise.resolve()
|
|
.then(() => {
|
|
if (cancelled) return;
|
|
setLoading(true);
|
|
setError(null);
|
|
return getEngineModelOptions(["embedding"]);
|
|
})
|
|
.then((data) => {
|
|
if (cancelled || !data) return;
|
|
const choices = data.embedding?.options || [];
|
|
setOptions(choices);
|
|
const target =
|
|
profileId && modelId
|
|
? { profile_id: profileId, model_id: modelId }
|
|
: data.embedding?.active;
|
|
const match = choices.find(
|
|
(option) =>
|
|
option.profile_id === target?.profile_id &&
|
|
option.model_id === target?.model_id,
|
|
);
|
|
const selected = match || (!profileId ? choices[0] : null);
|
|
setSelection(
|
|
selected
|
|
? { profile_id: selected.profile_id, model_id: selected.model_id }
|
|
: null,
|
|
);
|
|
})
|
|
.catch((err) => {
|
|
if (!cancelled)
|
|
setError(err instanceof Error ? err.message : String(err));
|
|
})
|
|
.finally(() => {
|
|
if (!cancelled) setLoading(false);
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [enabled, profileId, modelId]);
|
|
return { options, selection, setSelection, loading, error };
|
|
}
|