Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

chunk.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 .base import Base
  17. class ChunkUpdateError(Exception):
  18. def __init__(self, code=None, message=None, details=None):
  19. self.code = code
  20. self.message = message
  21. self.details = details
  22. super().__init__(message)
  23. class Chunk(Base):
  24. def __init__(self, rag, res_dict):
  25. self.id = ""
  26. self.content = ""
  27. self.important_keywords = []
  28. self.questions = []
  29. self.create_time = ""
  30. self.create_timestamp = 0.0
  31. self.dataset_id = None
  32. self.document_name = ""
  33. self.document_id = ""
  34. self.available = True
  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.dataset_id}/documents/{self.document_id}/chunks/{self.id}", update_message)
  41. res = res.json()
  42. if res.get("code") != 0:
  43. raise ChunkUpdateError(
  44. code=res.get("code"),
  45. message=res.get("message"),
  46. details=res.get("details")
  47. )