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.

t_dataset.py 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 ragflow_sdk import RAGFlow
  17. import random
  18. import pytest
  19. from common import HOST_ADDRESS
  20. def test_create_dataset_with_name(get_api_key_fixture):
  21. API_KEY = get_api_key_fixture
  22. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  23. rag.create_dataset("test_create_dataset_with_name")
  24. def test_create_dataset_with_duplicated_name(get_api_key_fixture):
  25. API_KEY = get_api_key_fixture
  26. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  27. rag.create_dataset("test_create_dataset_with_duplicated_name")
  28. with pytest.raises(Exception) as exc_info:
  29. rag.create_dataset("test_create_dataset_with_duplicated_name")
  30. assert str(exc_info.value) == "Duplicated dataset name in creating dataset."
  31. def test_create_dataset_with_random_chunk_method(get_api_key_fixture):
  32. API_KEY = get_api_key_fixture
  33. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  34. valid_chunk_methods = ["naive", "manual", "qa", "table", "paper", "book", "laws", "presentation", "picture", "one", "email"]
  35. random_chunk_method = random.choice(valid_chunk_methods)
  36. rag.create_dataset("test_create_dataset_with_random_chunk_method", chunk_method=random_chunk_method)
  37. def test_create_dataset_with_invalid_parameter(get_api_key_fixture):
  38. API_KEY = get_api_key_fixture
  39. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  40. valid_chunk_methods = ["naive", "manual", "qa", "table", "paper", "book", "laws", "presentation", "picture", "one", "email", "tag"]
  41. chunk_method = "invalid_chunk_method"
  42. with pytest.raises(Exception) as exc_info:
  43. rag.create_dataset("test_create_dataset_with_invalid_chunk_method", chunk_method=chunk_method)
  44. assert str(exc_info.value) == f"'{chunk_method}' is not in {valid_chunk_methods}"
  45. def test_update_dataset_with_name(get_api_key_fixture):
  46. API_KEY = get_api_key_fixture
  47. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  48. ds = rag.create_dataset("test_update_dataset")
  49. ds.update({"name": "updated_dataset"})
  50. def test_delete_datasets_with_success(get_api_key_fixture):
  51. API_KEY = get_api_key_fixture
  52. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  53. ds = rag.create_dataset("test_delete_dataset")
  54. rag.delete_datasets(ids=[ds.id])
  55. def test_list_datasets_with_success(get_api_key_fixture):
  56. API_KEY = get_api_key_fixture
  57. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  58. rag.create_dataset("test_list_datasets")
  59. rag.list_datasets()