Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: fix create-by-file doc_form (#31346)

wangxiaolei056095238b16
diff --git a/api/controllers/service_api/dataset/document.py b/api/controllers/service_api/dataset/document.py
index c800c0e4e16..49ff4f57dc8 100644
--- a/api/controllers/service_api/dataset/document.py
+++ b/api/controllers/service_api/dataset/document.py
@@ -261,24 +261,25 @@ class DocumentAddByFileApi(DatasetApiResource):
@cloud_edition_billing_rate_limit_check("knowledge", "dataset")
def post(self, tenant_id, dataset_id):
"""Create document by upload file."""
+ dataset = db.session.query(Dataset).where(Dataset.tenant_id == tenant_id, Dataset.id == dataset_id).first()
+
+ if not dataset:
+ raise ValueError("Dataset does not exist.")
+
+ if dataset.provider == "external":
+ raise ValueError("External datasets are not supported.")
+
args = {}
if "data" in request.form:
args = json.loads(request.form["data"])
if "doc_form" not in args:
- args["doc_form"] = "text_model"
+ args["doc_form"] = dataset.chunk_structure or "text_model"
if "doc_language" not in args:
args["doc_language"] = "English"
# get dataset info
dataset_id = str(dataset_id)
tenant_id = str(tenant_id)
- dataset = db.session.query(Dataset).where(Dataset.tenant_id == tenant_id, Dataset.id == dataset_id).first()
-
- if not dataset:
- raise ValueError("Dataset does not exist.")
-
- if dataset.provider == "external":
- raise ValueError("External datasets are not supported.")
indexing_technique = args.get("indexing_technique") or dataset.indexing_technique
if not indexing_technique:
@@ -370,24 +371,25 @@ class DocumentUpdateByFileApi(DatasetApiResource):
@cloud_edition_billing_rate_limit_check("knowledge", "dataset")
def post(self, tenant_id, dataset_id, document_id):
"""Update document by upload file."""
+ dataset = db.session.query(Dataset).where(Dataset.tenant_id == tenant_id, Dataset.id == dataset_id).first()
+
+ if not dataset:
+ raise ValueError("Dataset does not exist.")
+
+ if dataset.provider == "external":
+ raise ValueError("External datasets are not supported.")
+
args = {}
if "data" in request.form:
args = json.loads(request.form["data"])
if "doc_form" not in args:
- args["doc_form"] = "text_model"
+ args["doc_form"] = dataset.chunk_structure or "text_model"
if "doc_language" not in args:
args["doc_language"] = "English"
# get dataset info
dataset_id = str(dataset_id)
tenant_id = str(tenant_id)
- dataset = db.session.query(Dataset).where(Dataset.tenant_id == tenant_id, Dataset.id == dataset_id).first()
-
- if not dataset:
- raise ValueError("Dataset does not exist.")
-
- if dataset.provider == "external":
- raise ValueError("External datasets are not supported.")
# indexing_technique is already set in dataset since this is an update
args["indexing_technique"] = dataset.indexing_technique