Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 Chat, Chunk, DataSet, Document, RAGFlow, Session
  18. from utils.file_utils import create_txt_file
  19. # DATASET MANAGEMENT
  20. def batch_create_datasets(client: RAGFlow, num: int) -> list[DataSet]:
  21. return [client.create_dataset(name=f"dataset_{i}") for i in range(num)]
  22. # FILE MANAGEMENT WITHIN DATASET
  23. def bulk_upload_documents(dataset: DataSet, num: int, tmp_path: Path) -> list[Document]:
  24. document_infos = []
  25. for i in range(num):
  26. fp = create_txt_file(tmp_path / f"ragflow_test_upload_{i}.txt")
  27. with fp.open("rb") as f:
  28. blob = f.read()
  29. document_infos.append({"display_name": fp.name, "blob": blob})
  30. return dataset.upload_documents(document_infos)
  31. # CHUNK MANAGEMENT WITHIN DATASET
  32. def batch_add_chunks(document: Document, num: int) -> list[Chunk]:
  33. return [document.add_chunk(content=f"chunk test {i}") for i in range(num)]
  34. # CHAT ASSISTANT MANAGEMENT
  35. def batch_create_chat_assistants(client: RAGFlow, num: int) -> list[Chat]:
  36. return [client.create_chat(name=f"test_chat_assistant_{i}") for i in range(num)]
  37. # SESSION MANAGEMENT
  38. def batch_add_sessions_with_chat_assistant(chat_assistant: Chat, num) -> list[Session]:
  39. return [chat_assistant.create_session(name=f"session_with_chat_assistant_{i}") for i in range(num)]