You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ragflow.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #
  2. # Copyright 2024 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. import os
  17. from abc import ABC
  18. import requests
  19. class RAGFLow(ABC):
  20. def __init__(self, user_key, base_url):
  21. self.user_key = user_key
  22. self.base_url = base_url
  23. def create_dataset(self, name):
  24. return name
  25. def delete_dataset(self, name):
  26. return name
  27. def list_dataset(self):
  28. endpoint = f"{self.base_url}/api/v1/dataset"
  29. response = requests.get(endpoint)
  30. if response.status_code == 200:
  31. return response.json()['datasets']
  32. else:
  33. return None
  34. def get_dataset(self, dataset_id):
  35. endpoint = f"{self.base_url}/api/v1/dataset/{dataset_id}"
  36. response = requests.get(endpoint)
  37. if response.status_code == 200:
  38. return response.json()
  39. else:
  40. return None
  41. def update_dataset(self, dataset_id, params):
  42. endpoint = f"{self.base_url}/api/v1/dataset/{dataset_id}"
  43. response = requests.put(endpoint, json=params)
  44. if response.status_code == 200:
  45. return True
  46. else:
  47. return False