Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. import random
  17. import pytest
  18. from common import HOST_ADDRESS
  19. from ragflow_sdk import RAGFlow
  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) == "Dataset name 'test_create_dataset_with_duplicated_name' already exists"
  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. chunk_method = "invalid_chunk_method"
  41. with pytest.raises(Exception) as exc_info:
  42. rag.create_dataset("test_create_dataset_with_invalid_chunk_method", chunk_method=chunk_method)
  43. assert (
  44. str(exc_info.value)
  45. == f"Field: <chunk_method> - Message: <Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'> - Value: <{chunk_method}>"
  46. )
  47. def test_update_dataset_with_name(get_api_key_fixture):
  48. API_KEY = get_api_key_fixture
  49. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  50. ds = rag.create_dataset("test_update_dataset")
  51. ds.update({"name": "updated_dataset"})
  52. def test_delete_datasets_with_success(get_api_key_fixture):
  53. API_KEY = get_api_key_fixture
  54. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  55. ds = rag.create_dataset("test_delete_dataset")
  56. rag.delete_datasets(ids=[ds.id])
  57. def test_list_datasets_with_success(get_api_key_fixture):
  58. API_KEY = get_api_key_fixture
  59. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  60. rag.create_dataset("test_list_datasets")
  61. rag.list_datasets()