From 734ec8acd9147a8a9e161030787e1e7111ab85c1 Mon Sep 17 00:00:00 2001 From: leslie2046 <253605712@qq.com> Date: Sun, 16 Feb 2025 10:49:42 +0800 Subject: [PATCH] fix --- api/services/annotation_service.py | 12 ------------ .../components/app/annotation/header-opts/index.tsx | 3 ++- web/service/annotation.ts | 4 ++++ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/api/services/annotation_service.py b/api/services/annotation_service.py index 07cf662731..87deef3162 100644 --- a/api/services/annotation_service.py +++ b/api/services/annotation_service.py @@ -443,13 +443,6 @@ class AppAnnotationService: @classmethod def clear_all_annotations(cls, app_id: str) -> dict: - """ - 清空指定应用的所有标注及其相关的命中历史记录。 - - :param app_id: 应用的ID - :return: 返回操作结果 - """ - # 获取应用信息 app = ( db.session.query(App) .filter(App.id == app_id, App.tenant_id == current_user.current_tenant_id, App.status == "normal") @@ -459,10 +452,8 @@ class AppAnnotationService: if not app: raise NotFound("App not found") - # 删除所有标注 annotations = db.session.query(MessageAnnotation).filter(MessageAnnotation.app_id == app_id).all() for annotation in annotations: - # 删除标注的命中历史记录 annotation_hit_histories = ( db.session.query(AppAnnotationHitHistory) .filter(AppAnnotationHitHistory.annotation_id == annotation.id) @@ -471,13 +462,10 @@ class AppAnnotationService: for annotation_hit_history in annotation_hit_histories: db.session.delete(annotation_hit_history) - # 删除标注本身 db.session.delete(annotation) - # 提交事务 db.session.commit() - # 如果标注回复功能已启用,清理相关的索引任务 annotation_setting = ( db.session.query(AppAnnotationSetting).filter(AppAnnotationSetting.app_id == app_id).first() ) diff --git a/web/app/components/app/annotation/header-opts/index.tsx b/web/app/components/app/annotation/header-opts/index.tsx index e072e577de..2f14af0755 100644 --- a/web/app/components/app/annotation/header-opts/index.tsx +++ b/web/app/components/app/annotation/header-opts/index.tsx @@ -22,6 +22,7 @@ import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows import I18n from '@/context/i18n' import { fetchExportAnnotationList } from '@/service/annotation' +import { clearAllAnnotations } from '@/service/annotation' import { LanguagesSupported } from '@/i18n/language' const CSV_HEADER_QA_EN = ['Question', 'Answer'] @@ -141,7 +142,7 @@ const HeaderOptions: FC = ({ onClick={handleClearAll} className='h-9 py-2 px-3 mx-1 flex items-center space-x-2 hover:bg-red-50 rounded-lg cursor-pointer disabled:opacity-50 w-[calc(100%_-_8px)] text-red-600' > - + {t('appAnnotation.table.header.clearAll')} diff --git a/web/service/annotation.ts b/web/service/annotation.ts index 5096a4f58a..0b268ed5d0 100644 --- a/web/service/annotation.ts +++ b/web/service/annotation.ts @@ -63,3 +63,7 @@ export const delAnnotation = (appId: string, annotationId: string) => { export const fetchHitHistoryList = (appId: string, annotationId: string, params: Record) => { return get(`apps/${appId}/annotations/${annotationId}/hit-histories`, { params }) } + +export const clearAllAnnotations = (appId: string): Promise => { + return post(`apps/${appId}/annotations/${annotationId}/clear-all`) +}