perf(rag): ui and related apis

This commit is contained in:
Junyan Qin
2025-07-18 00:37:22 +08:00
parent bb672d8f46
commit b61bd36b14
17 changed files with 89 additions and 32 deletions
@@ -28,7 +28,7 @@ export default function KBDoc({ kbId }: { kbId: string }) {
setDocumentsList(
resp.files.map((file: KnowledgeBaseFile) => {
return {
id: file.id,
uuid: file.uuid,
name: file.file_name,
status: file.status,
};
@@ -14,7 +14,7 @@ import {
import { useTranslation } from 'react-i18next';
export type DocumentFile = {
id: string;
uuid: string;
name: string;
status: string;
};
@@ -52,7 +52,7 @@ export const columns = (
{t('knowledge.documentsTab.actions')}
</DropdownMenuLabel>
<DropdownMenuItem onClick={() => onDelete(document.id)}>
<DropdownMenuItem onClick={() => onDelete(document.uuid)}>
{t('knowledge.documentsTab.delete')}
</DropdownMenuItem>
</DropdownMenuContent>
@@ -24,6 +24,7 @@ import {
SelectValue,
} from '@/components/ui/select';
import { KnowledgeBase } from '@/app/infra/entities/api';
import { toast } from 'sonner';
const getFormSchema = (t: (key: string) => string) =>
z.object({
@@ -42,6 +43,7 @@ export default function KBForm({
onFormCancel,
onKbDeleted,
onNewKbCreated,
onKbUpdated,
}: {
initKbId?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -49,6 +51,7 @@ export default function KBForm({
onFormCancel: () => void;
onKbDeleted: () => void;
onNewKbCreated: (kbId: string) => void;
onKbUpdated: (kbId: string) => void;
}) {
const { t } = useTranslation();
const formSchema = getFormSchema(t);
@@ -114,6 +117,17 @@ export default function KBForm({
description: data.description,
embedding_model_uuid: data.embeddingModelUUID,
};
httpClient
.updateKnowledgeBase(initKbId, updateKb)
.then((res) => {
console.log('update knowledge base success', res);
onKbUpdated(res.uuid);
toast.success(t('knowledge.updateKnowledgeBaseSuccess'));
})
.catch((err) => {
console.error('update knowledge base failed', err);
toast.error(t('knowledge.updateKnowledgeBaseFailed'));
});
} else {
// create knowledge base
const newKb: KnowledgeBase = {
@@ -186,6 +200,7 @@ export default function KBForm({
<FormControl>
<div className="relative">
<Select
disabled={!!initKbId}
onValueChange={(value) => {
field.onChange(value);
console.log('value', value);
@@ -210,7 +225,9 @@ export default function KBForm({
</div>
</FormControl>
<FormDescription>
{t('knowledge.embeddingModelDescription')}
{initKbId
? t('knowledge.cannotChangeEmbeddingModel')
: t('knowledge.embeddingModelDescription')}
</FormDescription>
<FormMessage />
</FormItem>