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.

t_dataset.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from ragflow_sdk import RAGFlow
  2. import random
  3. import pytest
  4. HOST_ADDRESS = 'http://127.0.0.1:9380'
  5. def test_create_dataset_with_name(get_api_key_fixture):
  6. API_KEY = get_api_key_fixture
  7. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  8. rag.create_dataset("test_create_dataset_with_name")
  9. def test_create_dataset_with_duplicated_name(get_api_key_fixture):
  10. API_KEY = get_api_key_fixture
  11. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  12. with pytest.raises(Exception) as exc_info:
  13. rag.create_dataset("test_create_dataset_with_name")
  14. assert str(exc_info.value) == "Duplicated dataset name in creating dataset."
  15. def test_create_dataset_with_random_chunk_method(get_api_key_fixture):
  16. API_KEY = get_api_key_fixture
  17. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  18. valid_chunk_methods = ["naive","manual","qa","table","paper","book","laws","presentation","picture","one","knowledge_graph","email"]
  19. random_chunk_method = random.choice(valid_chunk_methods)
  20. rag.create_dataset("test_create_dataset_with_random_chunk_method",chunk_method=random_chunk_method)
  21. def test_create_dataset_with_invalid_parameter(get_api_key_fixture):
  22. API_KEY = get_api_key_fixture
  23. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  24. valid_chunk_methods = ["naive", "manual", "qa", "table", "paper", "book", "laws", "presentation", "picture", "one",
  25. "knowledge_graph", "email"]
  26. chunk_method = "invalid_chunk_method"
  27. with pytest.raises(Exception) as exc_info:
  28. rag.create_dataset("test_create_dataset_with_name",chunk_method=chunk_method)
  29. assert str(exc_info.value) == f"{chunk_method} is not in {valid_chunk_methods}"
  30. def test_update_dataset_with_name(get_api_key_fixture):
  31. API_KEY = get_api_key_fixture
  32. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  33. ds = rag.create_dataset("test_update_dataset")
  34. ds.update({"name": "updated_dataset"})
  35. def test_delete_datasets_with_success(get_api_key_fixture):
  36. API_KEY = get_api_key_fixture
  37. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  38. ds = rag.create_dataset("MA")
  39. rag.delete_datasets(ids=[ds.id])
  40. def test_list_datasets_with_success(get_api_key_fixture):
  41. API_KEY = get_api_key_fixture
  42. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  43. rag.list_datasets()