Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions server/routers/data_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,18 @@ async def add_graph_entity(file_path: str = Body(...), kgdb_name: Optional[str]
logger.error(f"添加实体失败: {e}, {traceback.format_exc()}")
return {"message": f"添加实体失败: {e}", "status": "failed"}

@data.post("/update")
async def update_database_info(
db_id: str = Body(...),
name: str = Body(...),
description: str = Body(...),
current_user: User = Depends(get_admin_user)
):
logger.debug(f"Update database {db_id} info: {name}, {description}")
try:
database = knowledge_base.update_database(db_id, name, description)
return {"message": "更新成功", "database": database}
except Exception as e:
logger.error(f"更新数据库失败 {e}, {traceback.format_exc()}")
raise HTTPException(status_code=400, detail=f"更新数据库失败: {e}")

15 changes: 15 additions & 0 deletions src/core/kb_db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ def delete_database(self, db_id):
return True
return False

def update_database(self, db_id, name, description):
"""更新知识库信息"""
with self.get_session() as session:
db = session.query(KnowledgeDatabase).filter_by(db_id=db_id).first()
if not db:
raise ValueError(f"数据库 {db_id} 不存在")

# 更新字段
db.name = name
db.description = description
session.commit()

# 返回更新后的数据库信息
return self._to_dict_safely(db)

# 文件操作方法
def add_file(self, db_id, file_id, filename, path, file_type, status="waiting"):
"""添加文件"""
Expand Down
18 changes: 18 additions & 0 deletions src/core/knowledgebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,15 @@ def get_database_info(self, db_id):
else:
db_copy = db_dict.copy()
try:
# 保存原始描述
original_description = db_copy.get("description")

milvus_info = self.get_collection_info(db_id)
db_copy.update(milvus_info)

# 如果原始描述不为空,恢复它
if original_description:
db_copy["description"] = original_description
except Exception as e:
logger.warning(f"获取知识库 ID: {db_id} 的Milvus信息失败: {e}")
# 添加一个默认的Milvus状态
Expand Down Expand Up @@ -553,3 +560,14 @@ def check_embed_model(self, db_id):
db = self.db_manager.get_database_by_id(db_id)
return db["embed_model"] == self.embed_model.embed_model_fullname

def update_database(self, db_id, name, description):
"""更新知识库信息"""
# 检查知识库是否存在
db = self.db_manager.get_database_by_id(db_id)
if db is None:
raise Exception(f"数据库不存在: {db_id}")

# 调用db_manager更新知识库信息
updated_db = self.db_manager.update_database(db_id, name, description)
return updated_db

14 changes: 14 additions & 0 deletions web/src/apis/admin_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ export const knowledgeBaseApi = {
checkAdminPermission()
return apiPost('/api/data/url-to-chunk', data, {}, true)
},

/**
* 更新知识库信息
* @param {string} dbId - 知识库ID
* @param {Object} data - 包含name和description的数据对象
* @returns {Promise} - 更新结果
*/
updateDatabaseInfo: async (dbId, data) => {
checkAdminPermission()
return apiPost('/api/data/update', {
db_id: dbId,
...data
}, {}, true)
},
}

// 图数据库管理API
Expand Down
67 changes: 66 additions & 1 deletion web/src/views/DataBaseInfoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@
<a-button type="primary" @click="backToDatabase">
<LeftOutlined /> 返回
</a-button>
<a-button type="primary" @click="showEditModal">
<EditOutlined />
</a-button>
<a-button type="primary" danger @click="deleteDatabse">
<DeleteOutlined /> 删除数据库
<DeleteOutlined />
</a-button>
</template>
</HeaderComponent>
<a-alert v-if="configStore.config.embed_model &&database.embed_model != configStore.config.embed_model" message="向量模型不匹配,请重新选择" type="warning" style="margin: 10px 20px;" />

<!-- 添加编辑对话框 -->
<a-modal v-model:open="editModalVisible" title="编辑知识库信息" @ok="handleEditSubmit">
<a-form :model="editForm" :rules="rules" ref="editFormRef" layout="vertical">
<a-form-item label="知识库名称" name="name" required>
<a-input v-model:value="editForm.name" placeholder="请输入知识库名称" />
</a-form-item>
<a-form-item label="知识库描述" name="description">
<a-textarea v-model:value="editForm.description" placeholder="请输入知识库描述" :rows="4" />
</a-form-item>
</a-form>
</a-modal>

<div class="db-main-container">
<a-tabs v-model:activeKey="state.curPage" class="atab-container" type="card">

Expand Down Expand Up @@ -333,6 +349,7 @@ import {
LoadingOutlined,
FileOutlined,
LinkOutlined,
EditOutlined,
} from '@ant-design/icons-vue'


Expand Down Expand Up @@ -806,6 +823,54 @@ const getAuthHeaders = () => {
return userStore.getAuthHeaders();
};

// 编辑知识库表单
const editModalVisible = ref(false);
const editFormRef = ref(null);
const editForm = reactive({
name: '',
description: ''
});

const rules = {
name: [{ required: true, message: '请输入知识库名称' }]
};

// 显示编辑对话框
const showEditModal = () => {
editForm.name = database.value.name || '';
editForm.description = database.value.description || '';
editModalVisible.value = true;
};

// 提交编辑表单
const handleEditSubmit = () => {
editFormRef.value.validate().then(() => {
updateDatabaseInfo();
}).catch(err => {
console.error('表单验证失败:', err);
});
};

// 更新知识库信息
const updateDatabaseInfo = async () => {
try {
state.lock = true;
const response = await knowledgeBaseApi.updateDatabaseInfo(databaseId.value, {
name: editForm.name,
description: editForm.description
});

message.success('知识库信息更新成功');
editModalVisible.value = false;
await getDatabaseInfo(); // 刷新数据
} catch (error) {
console.error(error);
message.error(error.message || '更新失败');
} finally {
state.lock = false;
}
};

</script>

<style lang="less" scoped>
Expand Down