feat(knowledge): Add tag_id support for knowledge creation and file uploads
- Introduced tag_id parameter in various knowledge-related API functions to allow categorization of knowledge entries. - Updated frontend components to handle tag_id during knowledge creation and file uploads. - Enhanced UI store to manage the selected tag ID for better user experience in categorizing knowledge.
This commit is contained in:
@@ -2,175 +2,184 @@ import { get, post, put, del, postUpload, getDown } from "../../utils/request";
|
|||||||
|
|
||||||
// 知识库管理 API(列表、创建、获取、更新、删除、复制)
|
// 知识库管理 API(列表、创建、获取、更新、删除、复制)
|
||||||
export function listKnowledgeBases() {
|
export function listKnowledgeBases() {
|
||||||
return get(`/api/v1/knowledge-bases`);
|
return get(`/api/v1/knowledge-bases`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createKnowledgeBase(data: {
|
export function createKnowledgeBase(data: {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
type?: 'document' | 'faq';
|
type?: 'document' | 'faq';
|
||||||
chunking_config?: any;
|
chunking_config?: any;
|
||||||
embedding_model_id?: string;
|
embedding_model_id?: string;
|
||||||
summary_model_id?: string;
|
summary_model_id?: string;
|
||||||
vlm_config?: {
|
vlm_config?: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
model_id?: string;
|
model_id?: string;
|
||||||
};
|
};
|
||||||
cos_config?: any;
|
cos_config?: any;
|
||||||
extract_config?: any;
|
extract_config?: any;
|
||||||
faq_config?: { index_mode: string; question_index_mode?: string };
|
faq_config?: { index_mode: string; question_index_mode?: string };
|
||||||
}) {
|
}) {
|
||||||
return post(`/api/v1/knowledge-bases`, data);
|
return post(`/api/v1/knowledge-bases`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getKnowledgeBaseById(id: string) {
|
export function getKnowledgeBaseById(id: string) {
|
||||||
return get(`/api/v1/knowledge-bases/${id}`);
|
return get(`/api/v1/knowledge-bases/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) {
|
export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) {
|
||||||
return put(`/api/v1/knowledge-bases/${id}` , data);
|
return put(`/api/v1/knowledge-bases/${id}`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteKnowledgeBase(id: string) {
|
export function deleteKnowledgeBase(id: string) {
|
||||||
return del(`/api/v1/knowledge-bases/${id}`);
|
return del(`/api/v1/knowledge-bases/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function copyKnowledgeBase(data: { source_id: string; target_id?: string }) {
|
export function copyKnowledgeBase(data: { source_id: string; target_id?: string }) {
|
||||||
return post(`/api/v1/knowledge-bases/copy`, data);
|
return post(`/api/v1/knowledge-bases/copy`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 知识文件 API(基于具体知识库)
|
// 知识文件 API(基于具体知识库)
|
||||||
export function uploadKnowledgeFile(kbId: string, data = {}, onProgress?: (progressEvent: any) => void) {
|
// data.tag_id: 可选,指定知识所属的分类ID
|
||||||
return postUpload(`/api/v1/knowledge-bases/${kbId}/knowledge/file`, data, onProgress);
|
export function uploadKnowledgeFile(kbId: string, data: { file: File; tag_id?: string;[key: string]: any } = { file: new File([], '') }, onProgress?: (progressEvent: any) => void) {
|
||||||
|
const formData = new FormData();
|
||||||
|
Object.keys(data).forEach(key => {
|
||||||
|
if (data[key] !== undefined) formData.append(key, data[key]);
|
||||||
|
});
|
||||||
|
return postUpload(`/api/v1/knowledge-bases/${kbId}/knowledge/file`, formData, onProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createKnowledgeFromURL(kbId: string, data: { url: string; enable_multimodel?: boolean }) {
|
// 从URL创建知识
|
||||||
return post(`/api/v1/knowledge-bases/${kbId}/knowledge/url`, data);
|
// data.tag_id: 可选,指定知识所属的分类ID
|
||||||
|
export function createKnowledgeFromURL(kbId: string, data: { url: string; enable_multimodel?: boolean; tag_id?: string }) {
|
||||||
|
return post(`/api/v1/knowledge-bases/${kbId}/knowledge/url`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createManualKnowledge(kbId: string, data: { title: string; content: string; status: string }) {
|
// 手工创建知识
|
||||||
return post(`/api/v1/knowledge-bases/${kbId}/knowledge/manual`, data);
|
// data.tag_id: 可选,指定知识所属的分类ID
|
||||||
|
export function createManualKnowledge(kbId: string, data: { title: string; content: string; status: string; tag_id?: string }) {
|
||||||
|
return post(`/api/v1/knowledge-bases/${kbId}/knowledge/manual`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listKnowledgeFiles(
|
export function listKnowledgeFiles(
|
||||||
kbId: string,
|
kbId: string,
|
||||||
params: { page: number; page_size: number; tag_id?: string; keyword?: string; file_type?: string },
|
params: { page: number; page_size: number; tag_id?: string; keyword?: string; file_type?: string },
|
||||||
) {
|
) {
|
||||||
const query = new URLSearchParams();
|
const query = new URLSearchParams();
|
||||||
query.append('page', String(params.page));
|
query.append('page', String(params.page));
|
||||||
query.append('page_size', String(params.page_size));
|
query.append('page_size', String(params.page_size));
|
||||||
if (params.tag_id) {
|
if (params.tag_id) {
|
||||||
query.append('tag_id', params.tag_id);
|
query.append('tag_id', params.tag_id);
|
||||||
}
|
}
|
||||||
if (params.keyword) {
|
if (params.keyword) {
|
||||||
query.append('keyword', params.keyword);
|
query.append('keyword', params.keyword);
|
||||||
}
|
}
|
||||||
if (params.file_type) {
|
if (params.file_type) {
|
||||||
query.append('file_type', params.file_type);
|
query.append('file_type', params.file_type);
|
||||||
}
|
}
|
||||||
const qs = query.toString();
|
const qs = query.toString();
|
||||||
return get(`/api/v1/knowledge-bases/${kbId}/knowledge?${qs}`);
|
return get(`/api/v1/knowledge-bases/${kbId}/knowledge?${qs}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getKnowledgeDetails(id: string) {
|
export function getKnowledgeDetails(id: string) {
|
||||||
return get(`/api/v1/knowledge/${id}`);
|
return get(`/api/v1/knowledge/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateManualKnowledge(id: string, data: { title: string; content: string; status: string }) {
|
export function updateManualKnowledge(id: string, data: { title: string; content: string; status: string }) {
|
||||||
return put(`/api/v1/knowledge/manual/${id}`, data);
|
return put(`/api/v1/knowledge/manual/${id}`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function delKnowledgeDetails(id: string) {
|
export function delKnowledgeDetails(id: string) {
|
||||||
return del(`/api/v1/knowledge/${id}`);
|
return del(`/api/v1/knowledge/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function downKnowledgeDetails(id: string) {
|
export function downKnowledgeDetails(id: string) {
|
||||||
return getDown(`/api/v1/knowledge/${id}/download`);
|
return getDown(`/api/v1/knowledge/${id}/download`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function batchQueryKnowledge(idsQueryString: string) {
|
export function batchQueryKnowledge(idsQueryString: string) {
|
||||||
return get(`/api/v1/knowledge/batch?${idsQueryString}`);
|
return get(`/api/v1/knowledge/batch?${idsQueryString}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getKnowledgeDetailsCon(id: string, page: number) {
|
export function getKnowledgeDetailsCon(id: string, page: number) {
|
||||||
return get(`/api/v1/chunks/${id}?page=${page}&page_size=25`);
|
return get(`/api/v1/chunks/${id}?page=${page}&page_size=25`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get chunk by chunk_id only (new endpoint - to be added to backend)
|
// Get chunk by chunk_id only (new endpoint - to be added to backend)
|
||||||
export function getChunkByIdOnly(chunkId: string) {
|
export function getChunkByIdOnly(chunkId: string) {
|
||||||
return get(`/api/v1/chunks/by-id/${chunkId}`);
|
return get(`/api/v1/chunks/by-id/${chunkId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a single generated question from a chunk by question ID
|
// Delete a single generated question from a chunk by question ID
|
||||||
export function deleteGeneratedQuestion(chunkId: string, questionId: string) {
|
export function deleteGeneratedQuestion(chunkId: string, questionId: string) {
|
||||||
return del(`/api/v1/chunks/by-id/${chunkId}/questions`, { question_id: questionId });
|
return del(`/api/v1/chunks/by-id/${chunkId}/questions`, { question_id: questionId });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listKnowledgeTags(
|
export function listKnowledgeTags(
|
||||||
kbId: string,
|
kbId: string,
|
||||||
params?: { page?: number; page_size?: number; keyword?: string },
|
params?: { page?: number; page_size?: number; keyword?: string },
|
||||||
) {
|
) {
|
||||||
const query = buildQuery(params);
|
const query = buildQuery(params);
|
||||||
return get(`/api/v1/knowledge-bases/${kbId}/tags${query}`);
|
return get(`/api/v1/knowledge-bases/${kbId}/tags${query}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createKnowledgeBaseTag(
|
export function createKnowledgeBaseTag(
|
||||||
kbId: string,
|
kbId: string,
|
||||||
data: { name: string; color?: string; sort_order?: number },
|
data: { name: string; color?: string; sort_order?: number },
|
||||||
) {
|
) {
|
||||||
return post(`/api/v1/knowledge-bases/${kbId}/tags`, data);
|
return post(`/api/v1/knowledge-bases/${kbId}/tags`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateKnowledgeBaseTag(
|
export function updateKnowledgeBaseTag(
|
||||||
kbId: string,
|
kbId: string,
|
||||||
tagId: string,
|
tagId: string,
|
||||||
data: { name?: string; color?: string; sort_order?: number },
|
data: { name?: string; color?: string; sort_order?: number },
|
||||||
) {
|
) {
|
||||||
return put(`/api/v1/knowledge-bases/${kbId}/tags/${tagId}`, data);
|
return put(`/api/v1/knowledge-bases/${kbId}/tags/${tagId}`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteKnowledgeBaseTag(kbId: string, tagId: string, params?: { force?: boolean }) {
|
export function deleteKnowledgeBaseTag(kbId: string, tagId: string, params?: { force?: boolean }) {
|
||||||
const forceQuery = params?.force ? '?force=true' : '';
|
const forceQuery = params?.force ? '?force=true' : '';
|
||||||
return del(`/api/v1/knowledge-bases/${kbId}/tags/${tagId}${forceQuery}`);
|
return del(`/api/v1/knowledge-bases/${kbId}/tags/${tagId}${forceQuery}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateKnowledgeTagBatch(data: { updates: Record<string, string | null> }) {
|
export function updateKnowledgeTagBatch(data: { updates: Record<string, string | null> }) {
|
||||||
return put(`/api/v1/knowledge/tags`, data);
|
return put(`/api/v1/knowledge/tags`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFAQEntryTagBatch(kbId: string, data: { updates: Record<string, string | null> }) {
|
export function updateFAQEntryTagBatch(kbId: string, data: { updates: Record<string, string | null> }) {
|
||||||
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/tags`, data);
|
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/tags`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildQuery = (params?: Record<string, any>) => {
|
const buildQuery = (params?: Record<string, any>) => {
|
||||||
if (!params) return '';
|
if (!params) return '';
|
||||||
const query = new URLSearchParams();
|
const query = new URLSearchParams();
|
||||||
Object.entries(params).forEach(([key, value]) => {
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
if (value === undefined || value === null || value === '') return;
|
if (value === undefined || value === null || value === '') return;
|
||||||
query.append(key, String(value));
|
query.append(key, String(value));
|
||||||
});
|
});
|
||||||
const queryString = query.toString();
|
const queryString = query.toString();
|
||||||
return queryString ? `?${queryString}` : '';
|
return queryString ? `?${queryString}` : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
export function listFAQEntries(
|
export function listFAQEntries(
|
||||||
kbId: string,
|
kbId: string,
|
||||||
params?: { page?: number; page_size?: number; tag_id?: string; keyword?: string },
|
params?: { page?: number; page_size?: number; tag_id?: string; keyword?: string },
|
||||||
) {
|
) {
|
||||||
const query = buildQuery(params);
|
const query = buildQuery(params);
|
||||||
return get(`/api/v1/knowledge-bases/${kbId}/faq/entries${query}`);
|
return get(`/api/v1/knowledge-bases/${kbId}/faq/entries${query}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function upsertFAQEntries(kbId: string, data: { entries: any[]; mode: 'append' | 'replace' }) {
|
export function upsertFAQEntries(kbId: string, data: { entries: any[]; mode: 'append' | 'replace' }) {
|
||||||
return post(`/api/v1/knowledge-bases/${kbId}/faq/entries`, data);
|
return post(`/api/v1/knowledge-bases/${kbId}/faq/entries`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFAQEntry(kbId: string, data: any) {
|
export function createFAQEntry(kbId: string, data: any) {
|
||||||
return post(`/api/v1/knowledge-bases/${kbId}/faq/entry`, data);
|
return post(`/api/v1/knowledge-bases/${kbId}/faq/entry`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFAQEntry(kbId: string, entryId: string, data: any) {
|
export function updateFAQEntry(kbId: string, entryId: string, data: any) {
|
||||||
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/${entryId}`, data);
|
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/${entryId}`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unified batch update API - supports is_enabled, is_recommended, tag_id
|
// Unified batch update API - supports is_enabled, is_recommended, tag_id
|
||||||
@@ -178,64 +187,64 @@ export function updateFAQEntry(kbId: string, entryId: string, data: any) {
|
|||||||
// 1. By entry ID: use by_id field
|
// 1. By entry ID: use by_id field
|
||||||
// 2. By Tag: use by_tag field to apply the same update to all entries under a tag
|
// 2. By Tag: use by_tag field to apply the same update to all entries under a tag
|
||||||
export interface FAQEntryFieldsUpdate {
|
export interface FAQEntryFieldsUpdate {
|
||||||
is_enabled?: boolean
|
is_enabled?: boolean
|
||||||
is_recommended?: boolean
|
is_recommended?: boolean
|
||||||
tag_id?: string | null
|
tag_id?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FAQEntryFieldsBatchRequest {
|
export interface FAQEntryFieldsBatchRequest {
|
||||||
by_id?: Record<string, FAQEntryFieldsUpdate>
|
by_id?: Record<string, FAQEntryFieldsUpdate>
|
||||||
by_tag?: Record<string, FAQEntryFieldsUpdate>
|
by_tag?: Record<string, FAQEntryFieldsUpdate>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFAQEntryFieldsBatch(kbId: string, data: FAQEntryFieldsBatchRequest) {
|
export function updateFAQEntryFieldsBatch(kbId: string, data: FAQEntryFieldsBatchRequest) {
|
||||||
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/fields`, data);
|
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/fields`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteFAQEntries(kbId: string, ids: string[]) {
|
export function deleteFAQEntries(kbId: string, ids: string[]) {
|
||||||
return del(`/api/v1/knowledge-bases/${kbId}/faq/entries`, { ids });
|
return del(`/api/v1/knowledge-bases/${kbId}/faq/entries`, { ids });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function searchFAQEntries(
|
export function searchFAQEntries(
|
||||||
kbId: string,
|
kbId: string,
|
||||||
data: {
|
data: {
|
||||||
query_text: string
|
query_text: string
|
||||||
vector_threshold?: number
|
vector_threshold?: number
|
||||||
match_count?: number
|
match_count?: number
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
return post(`/api/v1/knowledge-bases/${kbId}/faq/search`, data);
|
return post(`/api/v1/knowledge-bases/${kbId}/faq/search`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export FAQ entries as CSV file
|
// Export FAQ entries as CSV file
|
||||||
export async function exportFAQEntries(kbId: string): Promise<Blob> {
|
export async function exportFAQEntries(kbId: string): Promise<Blob> {
|
||||||
const response = await getDown(`/api/v1/knowledge-bases/${kbId}/faq/entries/export`);
|
const response = await getDown(`/api/v1/knowledge-bases/${kbId}/faq/entries/export`);
|
||||||
return response as unknown as Blob;
|
return response as unknown as Blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FAQ Import Progress API
|
// FAQ Import Progress API
|
||||||
export interface FAQImportProgress {
|
export interface FAQImportProgress {
|
||||||
task_id: string
|
task_id: string
|
||||||
kb_id: string
|
kb_id: string
|
||||||
knowledge_id: string
|
knowledge_id: string
|
||||||
status: 'pending' | 'processing' | 'completed' | 'failed'
|
status: 'pending' | 'processing' | 'completed' | 'failed'
|
||||||
progress: number
|
progress: number
|
||||||
total: number
|
total: number
|
||||||
processed: number
|
processed: number
|
||||||
message: string
|
message: string
|
||||||
error: string
|
error: string
|
||||||
created_at: number
|
created_at: number
|
||||||
updated_at: number
|
updated_at: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFAQImportProgress(taskId: string) {
|
export function getFAQImportProgress(taskId: string) {
|
||||||
return get(`/api/v1/faq/import/progress/${taskId}`);
|
return get(`/api/v1/faq/import/progress/${taskId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function searchKnowledge(keyword: string, offset = 0, limit = 20, fileTypes?: string[]) {
|
export function searchKnowledge(keyword: string, offset = 0, limit = 20, fileTypes?: string[]) {
|
||||||
let url = `/api/v1/knowledge/search?keyword=${encodeURIComponent(keyword)}&offset=${offset}&limit=${limit}`;
|
let url = `/api/v1/knowledge/search?keyword=${encodeURIComponent(keyword)}&offset=${offset}&limit=${limit}`;
|
||||||
if (fileTypes && fileTypes.length > 0) {
|
if (fileTypes && fileTypes.length > 0) {
|
||||||
url += `&file_types=${encodeURIComponent(fileTypes.join(','))}`;
|
url += `&file_types=${encodeURIComponent(fileTypes.join(','))}`;
|
||||||
}
|
}
|
||||||
return get(url);
|
return get(url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -579,7 +579,7 @@ const handleSave = async (targetStatus: ManualStatus) => {
|
|||||||
saving.value = true
|
saving.value = true
|
||||||
savingAction.value = targetStatus
|
savingAction.value = targetStatus
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload: { title: string; content: string; status: string; tag_id?: string } = {
|
||||||
title: form.title.trim(),
|
title: form.title.trim(),
|
||||||
content: form.content,
|
content: form.content,
|
||||||
status: targetStatus,
|
status: targetStatus,
|
||||||
@@ -591,6 +591,11 @@ const handleSave = async (targetStatus: ManualStatus) => {
|
|||||||
if (mode.value === 'edit' && knowledgeId.value) {
|
if (mode.value === 'edit' && knowledgeId.value) {
|
||||||
response = await updateManualKnowledge(knowledgeId.value, payload)
|
response = await updateManualKnowledge(knowledgeId.value, payload)
|
||||||
} else {
|
} else {
|
||||||
|
// 创建新知识时,从 store 获取当前选中的分类ID
|
||||||
|
const tagIdToUpload = uiStore.selectedTagId !== '__untagged__' ? uiStore.selectedTagId : undefined
|
||||||
|
if (tagIdToUpload) {
|
||||||
|
payload.tag_id = tagIdToUpload
|
||||||
|
}
|
||||||
response = await createManualKnowledge(form.kbId, payload)
|
response = await createManualKnowledge(form.kbId, payload)
|
||||||
knowledgeID = response?.data?.id || knowledgeID
|
knowledgeID = response?.data?.id || knowledgeID
|
||||||
kbId = form.kbId
|
kbId = form.kbId
|
||||||
|
|||||||
@@ -823,9 +823,11 @@ const handleDocFileChange = async (event: Event) => {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 获取当前选中的分类ID
|
||||||
|
const tagIdToUpload = uiStore.selectedTagId !== '__untagged__' ? uiStore.selectedTagId : undefined
|
||||||
await uploadKnowledgeFile(
|
await uploadKnowledgeFile(
|
||||||
kbId,
|
kbId,
|
||||||
{ file },
|
{ file, tag_id: tagIdToUpload },
|
||||||
(progressEvent: any) => {
|
(progressEvent: any) => {
|
||||||
if (progressEvent.total) {
|
if (progressEvent.total) {
|
||||||
progress = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
progress = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||||
@@ -1067,9 +1069,11 @@ const handleDocFolderChange = async (event: Event) => {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 获取当前选中的分类ID
|
||||||
|
const tagIdToUpload = uiStore.selectedTagId !== '__untagged__' ? uiStore.selectedTagId : undefined
|
||||||
await uploadKnowledgeFile(
|
await uploadKnowledgeFile(
|
||||||
kbId,
|
kbId,
|
||||||
{ file, fileName },
|
{ file, fileName, tag_id: tagIdToUpload },
|
||||||
(progressEvent: any) => {
|
(progressEvent: any) => {
|
||||||
if (progressEvent?.total) {
|
if (progressEvent?.total) {
|
||||||
progress = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
progress = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
getKnowledgeDetailsCon,
|
getKnowledgeDetailsCon,
|
||||||
} from "@/api/knowledge-base/index";
|
} from "@/api/knowledge-base/index";
|
||||||
import { knowledgeStore } from "@/stores/knowledge";
|
import { knowledgeStore } from "@/stores/knowledge";
|
||||||
|
import { useUIStore } from "@/stores/ui";
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
const usemenuStore = knowledgeStore();
|
const usemenuStore = knowledgeStore();
|
||||||
@@ -110,7 +111,11 @@ export default function (knowledgeBaseId?: string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadKnowledgeFile(currentKbId, { file })
|
// 获取当前选中的分类ID
|
||||||
|
const uiStore = useUIStore();
|
||||||
|
const tagIdToUpload = uiStore.selectedTagId !== '__untagged__' ? uiStore.selectedTagId : undefined;
|
||||||
|
|
||||||
|
uploadKnowledgeFile(currentKbId, { file, tag_id: tagIdToUpload })
|
||||||
.then((result: any) => {
|
.then((result: any) => {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
MessagePlugin.info("上传成功!");
|
MessagePlugin.info("上传成功!");
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export const useUIStore = defineStore('ui', {
|
|||||||
kbEditorMode: 'create' as 'create' | 'edit',
|
kbEditorMode: 'create' as 'create' | 'edit',
|
||||||
currentKBId: null as string | null,
|
currentKBId: null as string | null,
|
||||||
kbEditorType: 'document' as 'document' | 'faq',
|
kbEditorType: 'document' as 'document' | 'faq',
|
||||||
|
// 当前选中的分类ID,用于文件上传时传递
|
||||||
|
selectedTagId: '__untagged__' as string,
|
||||||
kbEditorInitialSection: null as string | null,
|
kbEditorInitialSection: null as string | null,
|
||||||
settingsInitialSection: null as string | null,
|
settingsInitialSection: null as string | null,
|
||||||
settingsInitialSubSection: null as string | null,
|
settingsInitialSubSection: null as string | null,
|
||||||
@@ -101,6 +103,11 @@ export const useUIStore = defineStore('ui', {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.manualEditorOnSuccess = null
|
this.manualEditorOnSuccess = null
|
||||||
|
},
|
||||||
|
|
||||||
|
// 设置当前选中的分类ID
|
||||||
|
setSelectedTagId(tagId: string) {
|
||||||
|
this.selectedTagId = tagId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -220,6 +220,8 @@ const loadTags = async (kbIdValue: string, reset = false) => {
|
|||||||
|
|
||||||
const handleTagFilterChange = (value: string) => {
|
const handleTagFilterChange = (value: string) => {
|
||||||
selectedTagId.value = value;
|
selectedTagId.value = value;
|
||||||
|
// 同步更新 store 中的 selectedTagId,供 menu.vue 上传时使用
|
||||||
|
uiStore.setSelectedTagId(value);
|
||||||
page = 1;
|
page = 1;
|
||||||
loadKnowledgeFiles(kbId.value);
|
loadKnowledgeFiles(kbId.value);
|
||||||
};
|
};
|
||||||
@@ -657,9 +659,12 @@ const handleDocumentUpload = async (event: Event) => {
|
|||||||
let failCount = 0;
|
let failCount = 0;
|
||||||
const totalCount = validFiles.length;
|
const totalCount = validFiles.length;
|
||||||
|
|
||||||
|
// 获取当前选中的分类ID(如果不是"未分类"则传递)
|
||||||
|
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||||
|
|
||||||
for (const file of validFiles) {
|
for (const file of validFiles) {
|
||||||
try {
|
try {
|
||||||
const responseData: any = await uploadKnowledgeFile(kbId.value, { file });
|
const responseData: any = await uploadKnowledgeFile(kbId.value, { file, tag_id: tagIdToUpload });
|
||||||
const isSuccess = responseData?.success || responseData?.code === 200 || responseData?.status === 'success' || (!responseData?.error && responseData);
|
const isSuccess = responseData?.success || responseData?.code === 200 || responseData?.status === 'success' || (!responseData?.error && responseData);
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
successCount++;
|
successCount++;
|
||||||
@@ -763,7 +768,9 @@ const handleURLImportConfirm = async () => {
|
|||||||
|
|
||||||
urlImporting.value = true;
|
urlImporting.value = true;
|
||||||
try {
|
try {
|
||||||
const responseData: any = await createKnowledgeFromURL(kbId.value, { url });
|
// 获取当前选中的分类ID
|
||||||
|
const tagIdToUpload = selectedTagId.value !== '__untagged__' ? selectedTagId.value : undefined;
|
||||||
|
const responseData: any = await createKnowledgeFromURL(kbId.value, { url, tag_id: tagIdToUpload });
|
||||||
window.dispatchEvent(new CustomEvent('knowledgeFileUploaded', {
|
window.dispatchEvent(new CustomEvent('knowledgeFileUploaded', {
|
||||||
detail: { kbId: kbId.value }
|
detail: { kbId: kbId.value }
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ func (s *knowledgeService) isKnowledgeDeleting(ctx context.Context, tenantID uin
|
|||||||
|
|
||||||
// CreateKnowledgeFromFile creates a knowledge entry from an uploaded file
|
// CreateKnowledgeFromFile creates a knowledge entry from an uploaded file
|
||||||
func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
||||||
kbID string, file *multipart.FileHeader, metadata map[string]string, enableMultimodel *bool, customFileName string,
|
kbID string, file *multipart.FileHeader, metadata map[string]string, enableMultimodel *bool, customFileName string, tagID string,
|
||||||
) (*types.Knowledge, error) {
|
) (*types.Knowledge, error) {
|
||||||
logger.Info(ctx, "Start creating knowledge from file")
|
logger.Info(ctx, "Start creating knowledge from file")
|
||||||
|
|
||||||
@@ -261,6 +261,7 @@ func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
|||||||
knowledge := &types.Knowledge{
|
knowledge := &types.Knowledge{
|
||||||
TenantID: tenantID,
|
TenantID: tenantID,
|
||||||
KnowledgeBaseID: kbID,
|
KnowledgeBaseID: kbID,
|
||||||
|
TagID: tagID, // 设置分类ID,用于知识分类管理
|
||||||
Type: "file",
|
Type: "file",
|
||||||
Title: safeFilename,
|
Title: safeFilename,
|
||||||
FileName: safeFilename,
|
FileName: safeFilename,
|
||||||
@@ -358,8 +359,9 @@ func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateKnowledgeFromURL creates a knowledge entry from a URL source
|
// CreateKnowledgeFromURL creates a knowledge entry from a URL source
|
||||||
|
// tagID is optional - when provided, the knowledge will be assigned to the specified tag/category.
|
||||||
func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
|
func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
|
||||||
kbID string, url string, enableMultimodel *bool, title string,
|
kbID string, url string, enableMultimodel *bool, title string, tagID string,
|
||||||
) (*types.Knowledge, error) {
|
) (*types.Knowledge, error) {
|
||||||
logger.Info(ctx, "Start creating knowledge from URL")
|
logger.Info(ctx, "Start creating knowledge from URL")
|
||||||
logger.Infof(ctx, "Knowledge base ID: %s, URL: %s", kbID, url)
|
logger.Infof(ctx, "Knowledge base ID: %s, URL: %s", kbID, url)
|
||||||
@@ -426,6 +428,7 @@ func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
|
|||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
EmbeddingModelID: kb.EmbeddingModelID,
|
EmbeddingModelID: kb.EmbeddingModelID,
|
||||||
|
TagID: tagID, // 设置分类ID,用于知识分类管理
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save knowledge record
|
// Save knowledge record
|
||||||
@@ -557,6 +560,7 @@ func (s *knowledgeService) CreateKnowledgeFromManual(ctx context.Context,
|
|||||||
EmbeddingModelID: kb.EmbeddingModelID,
|
EmbeddingModelID: kb.EmbeddingModelID,
|
||||||
FileName: fileName,
|
FileName: fileName,
|
||||||
FileType: types.KnowledgeTypeManual,
|
FileType: types.KnowledgeTypeManual,
|
||||||
|
TagID: payload.TagID, // 设置分类ID,用于知识分类管理
|
||||||
}
|
}
|
||||||
if err := knowledge.SetManualMetadata(meta); err != nil {
|
if err := knowledge.SetManualMetadata(meta); err != nil {
|
||||||
logger.Errorf(ctx, "Failed to set manual metadata: %v", err)
|
logger.Errorf(ctx, "Failed to set manual metadata: %v", err)
|
||||||
|
|||||||
@@ -164,8 +164,15 @@ func (h *KnowledgeHandler) CreateKnowledgeFromFile(c *gin.Context) {
|
|||||||
enableMultimodel = &parseBool
|
enableMultimodel = &parseBool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取分类ID(如果提供),用于知识分类管理
|
||||||
|
tagID := c.PostForm("tag_id")
|
||||||
|
// 过滤特殊值,空字符串或 "__untagged__" 表示未分类
|
||||||
|
if tagID == "__untagged__" || tagID == "" {
|
||||||
|
tagID = ""
|
||||||
|
}
|
||||||
|
|
||||||
// Create knowledge entry from the file
|
// Create knowledge entry from the file
|
||||||
knowledge, err := h.kgService.CreateKnowledgeFromFile(ctx, kbID, file, metadata, enableMultimodel, customFileName)
|
knowledge, err := h.kgService.CreateKnowledgeFromFile(ctx, kbID, file, metadata, enableMultimodel, customFileName, tagID)
|
||||||
// Check for duplicate knowledge error
|
// Check for duplicate knowledge error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if h.handleDuplicateKnowledgeError(c, err, knowledge, "file") {
|
if h.handleDuplicateKnowledgeError(c, err, knowledge, "file") {
|
||||||
@@ -199,7 +206,7 @@ func (h *KnowledgeHandler) CreateKnowledgeFromFile(c *gin.Context) {
|
|||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path string true "知识库ID"
|
// @Param id path string true "知识库ID"
|
||||||
// @Param request body object{url=string,enable_multimodel=bool,title=string} true "URL请求"
|
// @Param request body object{url=string,enable_multimodel=bool,title=string,tag_id=string} true "URL请求"
|
||||||
// @Success 201 {object} map[string]interface{} "创建的知识"
|
// @Success 201 {object} map[string]interface{} "创建的知识"
|
||||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||||
// @Failure 409 {object} map[string]interface{} "URL重复"
|
// @Failure 409 {object} map[string]interface{} "URL重复"
|
||||||
@@ -222,6 +229,7 @@ func (h *KnowledgeHandler) CreateKnowledgeFromURL(c *gin.Context) {
|
|||||||
URL string `json:"url" binding:"required"`
|
URL string `json:"url" binding:"required"`
|
||||||
EnableMultimodel *bool `json:"enable_multimodel"`
|
EnableMultimodel *bool `json:"enable_multimodel"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
TagID string `json:"tag_id"`
|
||||||
}
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
logger.Error(ctx, "Failed to parse URL request", err)
|
logger.Error(ctx, "Failed to parse URL request", err)
|
||||||
@@ -238,7 +246,7 @@ func (h *KnowledgeHandler) CreateKnowledgeFromURL(c *gin.Context) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Create knowledge entry from the URL
|
// Create knowledge entry from the URL
|
||||||
knowledge, err := h.kgService.CreateKnowledgeFromURL(ctx, kbID, req.URL, req.EnableMultimodel, req.Title)
|
knowledge, err := h.kgService.CreateKnowledgeFromURL(ctx, kbID, req.URL, req.EnableMultimodel, req.Title, req.TagID)
|
||||||
// Check for duplicate knowledge error
|
// Check for duplicate knowledge error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if h.handleDuplicateKnowledgeError(c, err, knowledge, "url") {
|
if h.handleDuplicateKnowledgeError(c, err, knowledge, "url") {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
// KnowledgeService defines the interface for knowledge services.
|
// KnowledgeService defines the interface for knowledge services.
|
||||||
type KnowledgeService interface {
|
type KnowledgeService interface {
|
||||||
// CreateKnowledgeFromFile creates knowledge from a file.
|
// CreateKnowledgeFromFile creates knowledge from a file.
|
||||||
|
// tagID is optional - when provided, the file will be assigned to the specified tag/category.
|
||||||
CreateKnowledgeFromFile(
|
CreateKnowledgeFromFile(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
kbID string,
|
kbID string,
|
||||||
@@ -19,14 +20,17 @@ type KnowledgeService interface {
|
|||||||
metadata map[string]string,
|
metadata map[string]string,
|
||||||
enableMultimodel *bool,
|
enableMultimodel *bool,
|
||||||
customFileName string,
|
customFileName string,
|
||||||
|
tagID string,
|
||||||
) (*types.Knowledge, error)
|
) (*types.Knowledge, error)
|
||||||
// CreateKnowledgeFromURL creates knowledge from a URL.
|
// CreateKnowledgeFromURL creates knowledge from a URL.
|
||||||
|
// tagID is optional - when provided, the knowledge will be assigned to the specified tag/category.
|
||||||
CreateKnowledgeFromURL(
|
CreateKnowledgeFromURL(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
kbID string,
|
kbID string,
|
||||||
url string,
|
url string,
|
||||||
enableMultimodel *bool,
|
enableMultimodel *bool,
|
||||||
title string,
|
title string,
|
||||||
|
tagID string,
|
||||||
) (*types.Knowledge, error)
|
) (*types.Knowledge, error)
|
||||||
// CreateKnowledgeFromPassage creates knowledge from text passages.
|
// CreateKnowledgeFromPassage creates knowledge from text passages.
|
||||||
CreateKnowledgeFromPassage(ctx context.Context, kbID string, passage []string) (*types.Knowledge, error)
|
CreateKnowledgeFromPassage(ctx context.Context, kbID string, passage []string) (*types.Knowledge, error)
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ type ManualKnowledgePayload struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
TagID string `json:"tag_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManualKnowledgeMetadata creates a new ManualKnowledgeMetadata instance.
|
// NewManualKnowledgeMetadata creates a new ManualKnowledgeMetadata instance.
|
||||||
|
|||||||
Reference in New Issue
Block a user