pull/22878/head
leslie2046 12 months ago
parent 5bc3293ef4
commit 734ec8acd9

@ -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()
)

@ -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<Props> = ({
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'
>
<Trash03 className='w-4 h-4'/>
<FileDownload02 className='w-4 h-4'/>
<span className='grow system-sm-regular text-left'>
{t('appAnnotation.table.header.clearAll')}
</span>

@ -63,3 +63,7 @@ export const delAnnotation = (appId: string, annotationId: string) => {
export const fetchHitHistoryList = (appId: string, annotationId: string, params: Record<string, any>) => {
return get(`apps/${appId}/annotations/${annotationId}/hit-histories`, { params })
}
export const clearAllAnnotations = (appId: string): Promise<any> => {
return post(`apps/${appId}/annotations/${annotationId}/clear-all`)
}

Loading…
Cancel
Save