Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

common.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from pathlib import Path
  17. from ragflow_sdk import DataSet, Document, RAGFlow
  18. from utils.file_utils import create_txt_file
  19. # DATASET MANAGEMENT
  20. def batch_create_datasets(client: RAGFlow, num: int) -> list[DataSet]:
  21. datasets = []
  22. for i in range(num):
  23. dataset = client.create_dataset(name=f"dataset_{i}")
  24. datasets.append(dataset)
  25. return datasets
  26. # FILE MANAGEMENT WITHIN DATASET
  27. def bulk_upload_documents(dataset: DataSet, num: int, tmp_path: Path) -> list[Document]:
  28. document_infos = []
  29. for i in range(num):
  30. fp = create_txt_file(tmp_path / f"ragflow_test_upload_{i}.txt")
  31. with fp.open("rb") as f:
  32. blob = f.read()
  33. document_infos.append({"display_name": fp.name, "blob": blob})
  34. return dataset.upload_documents(document_infos)