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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 .document import Document
  17. from .base import Base
  18. class DataSet(Base):
  19. class ParserConfig(Base):
  20. def __init__(self, rag, res_dict):
  21. super().__init__(rag, res_dict)
  22. def __init__(self, rag, res_dict):
  23. self.id = ""
  24. self.name = ""
  25. self.avatar = ""
  26. self.tenant_id = None
  27. self.description = ""
  28. self.embedding_model = ""
  29. self.permission = "me"
  30. self.document_count = 0
  31. self.chunk_count = 0
  32. self.chunk_method = "naive"
  33. self.parser_config = None
  34. self.pagerank = 0
  35. for k in list(res_dict.keys()):
  36. if k not in self.__dict__:
  37. res_dict.pop(k)
  38. super().__init__(rag, res_dict)
  39. def update(self, update_message: dict):
  40. res = self.put(f'/datasets/{self.id}',
  41. update_message)
  42. res = res.json()
  43. if res.get("code") != 0:
  44. raise Exception(res["message"])
  45. def upload_documents(self, document_list: list[dict]):
  46. url = f"/datasets/{self.id}/documents"
  47. files = [("file", (ele["display_name"], ele["blob"])) for ele in document_list]
  48. res = self.post(path=url, json=None, files=files)
  49. res = res.json()
  50. if res.get("code") == 0:
  51. doc_list = []
  52. for doc in res["data"]:
  53. document = Document(self.rag, doc)
  54. doc_list.append(document)
  55. return doc_list
  56. raise Exception(res.get("message"))
  57. def list_documents(self, id: str | None = None, keywords: str | None = None, page: int = 1, page_size: int = 30,
  58. orderby: str = "create_time", desc: bool = True):
  59. res = self.get(f"/datasets/{self.id}/documents",
  60. params={"id": id, "keywords": keywords, "page": page, "page_size": page_size, "orderby": orderby,
  61. "desc": desc})
  62. res = res.json()
  63. documents = []
  64. if res.get("code") == 0:
  65. for document in res["data"].get("docs"):
  66. documents.append(Document(self.rag, document))
  67. return documents
  68. raise Exception(res["message"])
  69. def delete_documents(self, ids: list[str] | None = None):
  70. res = self.rm(f"/datasets/{self.id}/documents", {"ids": ids})
  71. res = res.json()
  72. if res.get("code") != 0:
  73. raise Exception(res["message"])
  74. def async_parse_documents(self, document_ids):
  75. res = self.post(f"/datasets/{self.id}/chunks", {"document_ids": document_ids})
  76. res = res.json()
  77. if res.get("code") != 0:
  78. raise Exception(res.get("message"))
  79. def async_cancel_parse_documents(self, document_ids):
  80. res = self.rm(f"/datasets/{self.id}/chunks", {"document_ids": document_ids})
  81. res = res.json()
  82. if res.get("code") != 0:
  83. raise Exception(res.get("message"))