Skip to content

Commit 6183692

Browse files
committed
The large language model automatically summarizes the knowledge base, defaulting to the previously configured model #1335
Signed-off-by: Zhi Wang <[email protected]>
1 parent 0f29c6b commit 6183692

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

frontend/app/[locale]/setup/knowledges/components/document/DocumentList.tsx

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Document } from "@/types/knowledgeBase";
2323
import { ModelOption } from "@/types/modelConfig";
2424
import { formatFileSize, sortByStatusAndDate } from "@/lib/utils";
2525
import log from "@/lib/logger";
26+
import { useConfig } from "@/hooks/useConfig";
2627

2728
import DocumentStatus from "./DocumentStatus";
2829
import UploadArea from "../upload/UploadArea";
@@ -85,6 +86,7 @@ const DocumentListContainer = forwardRef<DocumentListRef, DocumentListProps>(
8586
const { message } = App.useApp();
8687
const uploadAreaRef = useRef<any>(null);
8788
const { state: docState } = useDocumentContext();
89+
const { modelConfig } = useConfig();
8890

8991
// Use fixed height instead of percentage
9092
const titleBarHeight = UI_CONFIG.TITLE_BAR_HEIGHT;
@@ -148,9 +150,57 @@ const DocumentListContainer = forwardRef<DocumentListRef, DocumentListProps>(
148150
try {
149151
const models = await modelService.getLLMModels();
150152
setAvailableModels(models);
151-
// Set first available model as default
152-
if (models.length > 0) {
153-
setSelectedModel(models[0].id);
153+
154+
// Determine initial selection order:
155+
// 1) Knowledge base's own configured model (server-side config)
156+
// 2) Globally configured default LLM from quick setup (create mode or no KB model)
157+
// 3) First available model
158+
159+
let initialModelId: number | null = null;
160+
161+
// 1) Knowledge base model (if provided)
162+
if (knowledgeBaseModel) {
163+
const matchedByName = models.find((m) => m.name === knowledgeBaseModel);
164+
const matchedByDisplay = matchedByName
165+
? null
166+
: models.find((m) => m.displayName === knowledgeBaseModel);
167+
if (matchedByName) {
168+
initialModelId = matchedByName.id;
169+
} else if (matchedByDisplay) {
170+
initialModelId = matchedByDisplay.id;
171+
}
172+
}
173+
174+
// 2) Fallback to globally configured default LLM
175+
if (initialModelId === null) {
176+
const configuredDisplayName = modelConfig?.llm?.displayName || "";
177+
const configuredModelName = modelConfig?.llm?.modelName || "";
178+
179+
const matchedByDisplay = models.find(
180+
(m) => m.displayName === configuredDisplayName && configuredDisplayName !== ""
181+
);
182+
const matchedByName = matchedByDisplay
183+
? null
184+
: models.find(
185+
(m) => m.name === configuredModelName && configuredModelName !== ""
186+
);
187+
188+
if (matchedByDisplay) {
189+
initialModelId = matchedByDisplay.id;
190+
} else if (matchedByName) {
191+
initialModelId = matchedByName.id;
192+
}
193+
}
194+
195+
// 3) Final fallback to first available model
196+
if (initialModelId === null) {
197+
if (models.length > 0) {
198+
initialModelId = models[0].id;
199+
}
200+
}
201+
202+
if (initialModelId !== null) {
203+
setSelectedModel(initialModelId);
154204
} else {
155205
message.warning(t("businessLogic.config.error.noAvailableModels"));
156206
}

0 commit comments

Comments
 (0)