Skip to content

Commit b5cd3f9

Browse files
committed
feat: add reset_meta function and update meta handling in Document model
1 parent 7756d02 commit b5cd3f9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

apps/application/chat_pipeline/step/search_dataset_step/impl/base_search_dataset_step.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
from models_provider.tools import get_model, get_model_by_id
2828

2929

30+
def reset_meta(meta):
31+
if not meta.get('allow_download', False):
32+
return {'allow_download': False}
33+
return meta
34+
35+
3036
def get_embedding_id(knowledge_id_list):
3137
knowledge_list = QuerySet(Knowledge).filter(id__in=knowledge_id_list)
3238
if len(set([knowledge.embedding_model_id for knowledge in knowledge_list])) > 1:
@@ -84,7 +90,7 @@ def reset_paragraph(paragraph: Dict, embedding_list: List) -> ParagraphPipelineM
8490
.add_document_name(paragraph.get('document_name'))
8591
.add_hit_handling_method(paragraph.get('hit_handling_method'))
8692
.add_directly_return_similarity(paragraph.get('directly_return_similarity'))
87-
.add_meta(paragraph.get('meta'))
93+
.add_meta(reset_meta(paragraph.get('meta')))
8894
.build())
8995

9096
@staticmethod

apps/knowledge/serializers/document.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import json
23
import os
34
import re
45
import traceback
@@ -9,11 +10,13 @@
910
import openpyxl
1011
import uuid_utils.compat as uuid
1112
from celery_once import AlreadyQueued
13+
from django.contrib.postgres.fields import JSONField
1214
from django.core import validators
1315
from django.db import transaction, models
14-
from django.db.models import QuerySet
16+
from django.db.models import QuerySet, Func, F, Value
1517
from django.db.models.aggregates import Max
16-
from django.db.models.functions import Substr, Reverse
18+
from django.db.models.fields.json import KeyTextTransform
19+
from django.db.models.functions import Substr, Reverse, Coalesce, Cast
1720
from django.http import HttpResponse
1821
from django.utils.translation import gettext_lazy as _, gettext, get_language, to_locale
1922
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
@@ -1256,6 +1259,19 @@ def batch_edit_hit_handling(self, instance: Dict, with_valid=True):
12561259
if directly_return_similarity is not None:
12571260
update_dict['directly_return_similarity'] = directly_return_similarity
12581261
QuerySet(Document).filter(id__in=document_id_list).update(**update_dict)
1262+
allow_download = instance.get('allow_download')
1263+
if allow_download is not None:
1264+
# 我需要修改meta meta是存在Document的字段 是一个json字段 但是allow_download可能不存在
1265+
Document.objects.filter(id__in=document_id_list).update(
1266+
meta=Func(
1267+
F("meta"),
1268+
Value(["allow_download"]),
1269+
Value(json.dumps(allow_download)), # 转成 "true"/"false"
1270+
Value(True), # create_missing = true
1271+
function="jsonb_set",
1272+
output_field=JSONField(),
1273+
)
1274+
)
12591275

12601276
def batch_refresh(self, instance: Dict, with_valid=True):
12611277
if with_valid:

0 commit comments

Comments
 (0)