|
|
|
|
@ -15,6 +15,7 @@ from configs import dify_config
|
|
|
|
|
from core.errors.error import LLMBadRequestError, ProviderTokenNotInitError
|
|
|
|
|
from core.model_manager import ModelManager
|
|
|
|
|
from core.model_runtime.entities.model_entities import ModelType
|
|
|
|
|
from core.rag.index_processor.constant.built_in_field import BuiltInField
|
|
|
|
|
from core.rag.index_processor.constant.index_type import IndexType
|
|
|
|
|
from core.rag.retrieval.retrieval_methods import RetrievalMethod
|
|
|
|
|
from events.dataset_event import dataset_was_deleted
|
|
|
|
|
@ -687,8 +688,12 @@ class DocumentService:
|
|
|
|
|
|
|
|
|
|
if document.tenant_id != current_user.current_tenant_id:
|
|
|
|
|
raise ValueError("No permission.")
|
|
|
|
|
|
|
|
|
|
document.name = name
|
|
|
|
|
|
|
|
|
|
if dataset.built_in_field_enabled:
|
|
|
|
|
if document.doc_metadata:
|
|
|
|
|
document.doc_metadata[BuiltInField.document_name] = name
|
|
|
|
|
else:
|
|
|
|
|
document.name = name
|
|
|
|
|
|
|
|
|
|
db.session.add(document)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
@ -1086,9 +1091,20 @@ class DocumentService:
|
|
|
|
|
doc_form=document_form,
|
|
|
|
|
doc_language=document_language,
|
|
|
|
|
)
|
|
|
|
|
doc_metadata = {}
|
|
|
|
|
if dataset.built_in_field_enabled:
|
|
|
|
|
doc_metadata = {
|
|
|
|
|
BuiltInField.document_name: name,
|
|
|
|
|
BuiltInField.uploader: account.name,
|
|
|
|
|
BuiltInField.upload_date: datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
|
BuiltInField.last_update_date: datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
|
BuiltInField.source: data_source_type,
|
|
|
|
|
}
|
|
|
|
|
if metadata is not None:
|
|
|
|
|
document.doc_metadata = metadata.doc_metadata
|
|
|
|
|
doc_metadata.update(metadata.doc_metadata)
|
|
|
|
|
document.doc_type = metadata.doc_type
|
|
|
|
|
if doc_metadata:
|
|
|
|
|
document.doc_metadata = doc_metadata
|
|
|
|
|
return document
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|