add knowledgebase page (#39)

* feat: Update site name to DataMate and refine text for AI data processing

* feat: Refactor settings page and implement model access functionality

- Created a new ModelAccess component for managing model configurations.
- Removed the old Settings component and replaced it with a new SettingsPage component that integrates ModelAccess, SystemConfig, and WebhookConfig.
- Added SystemConfig component for managing system settings.
- Implemented WebhookConfig component for managing webhook configurations.
- Updated API functions for model management in settings.apis.ts.
- Adjusted routing to point to the new SettingsPage component.

* feat: Implement Data Collection Page with Task Management and Execution Log

- Created DataCollectionPage component to manage data collection tasks.
- Added TaskManagement and ExecutionLog components for task handling and logging.
- Integrated task operations including start, stop, edit, and delete functionalities.
- Implemented filtering and searching capabilities in task management.
- Introduced SimpleCronScheduler for scheduling tasks with cron expressions.
- Updated CreateTask component to utilize new scheduling and template features.
- Enhanced BasicInformation component to conditionally render fields based on visibility settings.
- Refactored ImportConfiguration component to remove NAS import section.

* feat: Update task creation API endpoint and enhance task creation form with new fields and validation

* Refactor file upload and operator management components

- Removed unnecessary console logs from file download and export functions.
- Added size property to TaskItem interface for better task management.
- Simplified TaskUpload component by utilizing useFileSliceUpload hook for file upload logic.
- Enhanced OperatorPluginCreate component to handle file uploads and parsing more efficiently.
- Updated ConfigureStep component to use Ant Design Form for better data handling and validation.
- Improved PreviewStep component to navigate back to the operator market.
- Added support for additional file types in UploadStep component.
- Implemented delete operator functionality in OperatorMarketPage with confirmation prompts.
- Cleaned up unused API functions in operator.api.ts to streamline the codebase.
- Fixed number formatting utility to handle zero values correctly.

* Refactor Knowledge Generation to Knowledge Base

- Created new API service for Knowledge Base operations including querying, creating, updating, and deleting knowledge bases and files.
- Added constants for Knowledge Base status and type mappings.
- Defined models for Knowledge Base and related files.
- Removed obsolete Knowledge Base creation and home components, replacing them with new implementations under the Knowledge Base structure.
- Updated routing to reflect the new Knowledge Base paths.
- Adjusted menu items to align with the new Knowledge Base terminology.
- Modified ModelAccess interface to include modelName and type properties.
This commit is contained in:
chenghh-9609
2025-10-30 21:33:33 +08:00
committed by GitHub
parent ba6caabbc6
commit d89811f238
16 changed files with 1119 additions and 1166 deletions

View File

@@ -0,0 +1,66 @@
export default function AddDataDialog() {
const [isOpen, setIsOpen] = useState(false);
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
const { message } = App.useApp();
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
setSelectedFiles(Array.from(e.target.files));
}
};
const handleUpload = async () => {
if (selectedFiles.length === 0) {
message.error("请先选择文件");
return;
}
try {
const formData = new FormData();
selectedFiles.forEach((file) => {
formData.append("files", file);
});
await uploadDataFilesUsingPost(formData);
message.success("文件上传成功");
setIsOpen(false);
setSelectedFiles([]);
} catch (error) {
message.error("文件上传失败");
}
};
return (
<>
<Button type="primary" onClick={() => setIsOpen(true)}>
</Button>
<Modal
title="添加数据文件"
open={isOpen}
onCancel={() => setIsOpen(false)}
onOk={handleUpload}
okText="上传"
>
<input
type="file"
multiple
onChange={handleFileChange}
accept=".txt,.pdf,.docx,.csv,.json"
/>
{selectedFiles.length > 0 && (
<div className="mt-4">
<h4></h4>
<ul>
{selectedFiles.map((file, index) => (
<li key={index}>
{file.name} - {(file.size / 1024).toFixed(2)} KB
</li>
))}
</ul>
</div>
)}
</Modal>
</>
);
}

View File

@@ -0,0 +1,136 @@
import { Button, Form, Input, message, Modal, Select } from "antd";
import { PlusOutlined } from "@ant-design/icons";
import { useEffect, useState } from "react";
import { queryModelListUsingGet } from "@/pages/SettingsPage/settings.apis";
import { ModelI } from "@/pages/SettingsPage/ModelAccess";
import {
createKnowledgeBaseUsingPost,
updateKnowledgeBaseByIdUsingPut,
} from "../knowledge-base.api";
import { KnowledgeBaseItem } from "../knowledge-base.model";
export default function CreateKnowledgeBase({
isEdit,
data,
onUpdate,
}: {
isEdit?: boolean;
data?: Partial<KnowledgeBaseItem> | null;
onUpdate: () => void;
}) {
const [open, setOpen] = useState(false);
const [form] = Form.useForm();
const [models, setModels] = useState<ModelI[]>([]);
const embeddingModelOptions = models
.filter((model) => model.type === "EMBEDDING")
.map((model) => ({
label: model.modelName + " (" + model.provider + ")",
value: model.id,
}));
const chatModelOptions = models
.filter((model) => model.type === "CHAT")
.map((model) => ({
label: model.modelName + " (" + model.provider + ")",
value: model.id,
}));
const fetchModels = async () => {
const { data } = await queryModelListUsingGet({ page: 0, size: 1000 });
setModels(data.content || []);
};
useEffect(() => {
if (open) fetchModels();
}, [open]);
useEffect(() => {
if (isEdit && data) {
setOpen(true);
form.setFieldsValue({
name: data.name,
description: data.description,
embeddingModel: data.embeddingModel,
chatModel: data.chatModel,
});
}
}, [isEdit, data, form]);
const handleCreateKnowledgeBase = async () => {
try {
const values = await form.validateFields();
if (isEdit && data) {
await updateKnowledgeBaseByIdUsingPut(data.id!, values);
message.success("知识库更新成功");
} else {
await createKnowledgeBaseUsingPost(values);
message.success("知识库创建成功");
}
setOpen(false);
onUpdate();
} catch (error) {
message.error("操作失败:", error.data.message);
}
};
return (
<>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => {
form.resetFields();
setOpen(true);
}}
>
</Button>
<Modal
title={isEdit ? "编辑知识库" : "创建知识库"}
open={open}
okText="确定"
cancelText="取消"
onCancel={() => setOpen(false)}
onOk={handleCreateKnowledgeBase}
>
<Form form={form} layout="vertical">
<Form.Item
label="知识库名称"
name="name"
rules={[{ required: true, message: "请输入知识库名称" }]}
>
<Input placeholder="请输入知识库名称" />
</Form.Item>
<Form.Item
label="描述"
name="description"
rules={[{ required: false }]}
>
<Input.TextArea placeholder="请输入知识库描述(可选)" rows={4} />
</Form.Item>
<Form.Item
label="索引模型"
name="embeddingModel"
rules={[{ required: true, message: "请选择索引模型" }]}
>
<Select
placeholder="请选择索引模型"
options={embeddingModelOptions}
/>
</Form.Item>
<Form.Item
label="文本理解模型"
name="chatModel"
rules={[{ required: true, message: "请选择文本理解模型" }]}
>
<Select
placeholder="请选择文本理解模型"
options={chatModelOptions}
/>
</Form.Item>
</Form>
</Modal>
</>
);
}