Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

base.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. class Base:
  17. def __init__(self, rag, res_dict):
  18. self.rag = rag
  19. self._update_from_dict(rag, res_dict)
  20. def _update_from_dict(self, rag, res_dict):
  21. for k, v in res_dict.items():
  22. if isinstance(v, dict):
  23. self.__dict__[k] = Base(rag, v)
  24. else:
  25. self.__dict__[k] = v
  26. def to_json(self):
  27. pr = {}
  28. for name in dir(self):
  29. value = getattr(self, name)
  30. if not name.startswith("__") and not callable(value) and name != "rag":
  31. if isinstance(value, Base):
  32. pr[name] = value.to_json()
  33. else:
  34. pr[name] = value
  35. return pr
  36. def post(self, path, json=None, stream=False, files=None):
  37. res = self.rag.post(path, json, stream=stream, files=files)
  38. return res
  39. def get(self, path, params=None):
  40. res = self.rag.get(path, params)
  41. return res
  42. def rm(self, path, json):
  43. res = self.rag.delete(path, json)
  44. return res
  45. def put(self, path, json):
  46. res = self.rag.put(path, json)
  47. return res
  48. def __str__(self):
  49. return str(self.to_json())