Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

dataset_example.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. '''
  17. The example is about CRUD operations (Create, Read, Update, Delete) on a dataset.
  18. '''
  19. from ragflow_sdk import RAGFlow
  20. import sys
  21. HOST_ADDRESS = "http://127.0.0.1"
  22. API_KEY = "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm"
  23. try:
  24. # create a ragflow instance
  25. ragflow_instance = RAGFlow(api_key=API_KEY, base_url=HOST_ADDRESS)
  26. # crate a dataset instance
  27. dataset_instance = ragflow_instance.create_dataset(name="dataset_instance")
  28. # update the dataset instance
  29. updated_message = {"name":"updated_dataset"}
  30. updated_dataset = dataset_instance.update(updated_message)
  31. # get the dataset (list datasets)
  32. dataset_list = ragflow_instance.list_datasets(id=dataset_instance.id)
  33. dataset_instance_2 = dataset_list[0]
  34. print(dataset_instance)
  35. print(dataset_instance_2)
  36. # delete the dataset (delete datasets)
  37. to_be_deleted_datasets = [dataset_instance.id]
  38. ragflow_instance.delete_datasets(ids=to_be_deleted_datasets)
  39. print("test done")
  40. sys.exit(0)
  41. except Exception as e:
  42. print(str(e))
  43. sys.exit(-1)