Enhance knowledge base functionality and integrate S3 storage support
- Add new models for `KnowledgeDocument` and `KnowledgeChunk` to manage document ingestion and chunking. - Implement S3-compatible storage integration for knowledge documents, allowing for file uploads and retrieval. - Introduce API endpoints for managing knowledge bases and documents, including creation, deletion, and searching. - Update frontend components to support knowledge base configuration and document management, improving user interaction. - Enhance backend services for knowledge processing and retrieval, ensuring robust handling of document statuses and errors.
This commit is contained in:
@@ -12,8 +12,9 @@ export const API_BASE =
|
||||
|
||||
export type ModelType = "LLM" | "ASR" | "TTS" | "Realtime" | "Embedding" | "Agent";
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const isFormData = init?.body instanceof FormData;
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
headers: isFormData ? undefined : { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
...init,
|
||||
});
|
||||
@@ -344,8 +345,71 @@ export type KnowledgeBase = {
|
||||
updatedAt?: string | null;
|
||||
};
|
||||
|
||||
export type KnowledgeDocument = {
|
||||
id: string;
|
||||
knowledgeBaseId: string;
|
||||
name: string;
|
||||
sourceType: "file" | "text";
|
||||
mimeType: string;
|
||||
sizeBytes: number;
|
||||
status: string;
|
||||
errorMessage: string;
|
||||
chunkCount: number;
|
||||
createdAt?: string | null;
|
||||
};
|
||||
|
||||
export type KnowledgeSearchResult = {
|
||||
content: string;
|
||||
document: string;
|
||||
score: number;
|
||||
};
|
||||
|
||||
export type KnowledgeChunk = {
|
||||
id: string;
|
||||
chunkIndex: number;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export type KnowledgeBaseUpsert = Pick<
|
||||
KnowledgeBase,
|
||||
"name" | "description" | "embeddingModelResourceId"
|
||||
>;
|
||||
|
||||
export const knowledgeBasesApi = {
|
||||
list: () => request<KnowledgeBase[]>("/api/knowledge-bases"),
|
||||
create: (body: KnowledgeBaseUpsert) =>
|
||||
request<KnowledgeBase>("/api/knowledge-bases", { method: "POST", body: JSON.stringify(body) }),
|
||||
update: (id: string, body: KnowledgeBaseUpsert) =>
|
||||
request<KnowledgeBase>(`/api/knowledge-bases/${id}`, { method: "PUT", body: JSON.stringify(body) }),
|
||||
remove: (id: string) =>
|
||||
request<{ ok: boolean }>(`/api/knowledge-bases/${id}`, { method: "DELETE" }),
|
||||
documents: (id: string) =>
|
||||
request<KnowledgeDocument[]>(`/api/knowledge-bases/${id}/documents`),
|
||||
addText: (id: string, body: { name: string; content: string }) =>
|
||||
request<KnowledgeDocument>(`/api/knowledge-bases/${id}/documents/text`, {
|
||||
method: "POST", body: JSON.stringify(body),
|
||||
}),
|
||||
addFile: (id: string, file: File) => {
|
||||
const body = new FormData();
|
||||
body.append("file", file);
|
||||
return request<KnowledgeDocument>(`/api/knowledge-bases/${id}/documents/file`, {
|
||||
method: "POST", body,
|
||||
});
|
||||
},
|
||||
removeDocument: (id: string, documentId: string) =>
|
||||
request<{ ok: boolean }>(`/api/knowledge-bases/${id}/documents/${documentId}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
retryDocument: (id: string, documentId: string) =>
|
||||
request<KnowledgeDocument>(`/api/knowledge-bases/${id}/documents/${documentId}/retry`, {
|
||||
method: "POST",
|
||||
}),
|
||||
chunks: (id: string, documentId: string) =>
|
||||
request<KnowledgeChunk[]>(`/api/knowledge-bases/${id}/documents/${documentId}/chunks`),
|
||||
search: (id: string, query: string, topK = 5) =>
|
||||
request<KnowledgeSearchResult[]>(`/api/knowledge-bases/${id}/search`, {
|
||||
method: "POST", body: JSON.stringify({ query, topK }),
|
||||
}),
|
||||
};
|
||||
|
||||
// ---------- 工作流节点类型目录 ----------
|
||||
|
||||
Reference in New Issue
Block a user