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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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, Agent
  17. from common import HOST_ADDRESS
  18. import pytest
  19. def test_create_session_with_success(get_api_key_fixture):
  20. API_KEY = get_api_key_fixture
  21. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  22. kb = rag.create_dataset(name="test_create_session")
  23. display_name = "ragflow.txt"
  24. with open("test_data/ragflow.txt", "rb") as file:
  25. blob = file.read()
  26. document = {"display_name": display_name, "blob": blob}
  27. documents = []
  28. documents.append(document)
  29. docs = kb.upload_documents(documents)
  30. for doc in docs:
  31. doc.add_chunk("This is a test to add chunk")
  32. assistant = rag.create_chat("test_create_session", dataset_ids=[kb.id])
  33. assistant.create_session()
  34. def test_create_conversation_with_success(get_api_key_fixture):
  35. API_KEY = get_api_key_fixture
  36. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  37. kb = rag.create_dataset(name="test_create_conversation")
  38. display_name = "ragflow.txt"
  39. with open("test_data/ragflow.txt", "rb") as file:
  40. blob = file.read()
  41. document = {"display_name": display_name, "blob": blob}
  42. documents = []
  43. documents.append(document)
  44. docs = kb.upload_documents(documents)
  45. for doc in docs:
  46. doc.add_chunk("This is a test to add chunk")
  47. assistant = rag.create_chat("test_create_conversation", dataset_ids=[kb.id])
  48. session = assistant.create_session()
  49. question = "What is AI"
  50. for ans in session.ask(question):
  51. pass
  52. # assert not ans.content.startswith("**ERROR**"), "Please check this error."
  53. def test_delete_sessions_with_success(get_api_key_fixture):
  54. API_KEY = get_api_key_fixture
  55. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  56. kb = rag.create_dataset(name="test_delete_session")
  57. display_name = "ragflow.txt"
  58. with open("test_data/ragflow.txt", "rb") as file:
  59. blob = file.read()
  60. document = {"display_name": display_name, "blob": blob}
  61. documents = []
  62. documents.append(document)
  63. docs = kb.upload_documents(documents)
  64. for doc in docs:
  65. doc.add_chunk("This is a test to add chunk")
  66. assistant = rag.create_chat("test_delete_session", dataset_ids=[kb.id])
  67. session = assistant.create_session()
  68. assistant.delete_sessions(ids=[session.id])
  69. def test_update_session_with_name(get_api_key_fixture):
  70. API_KEY = get_api_key_fixture
  71. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  72. kb = rag.create_dataset(name="test_update_session")
  73. display_name = "ragflow.txt"
  74. with open("test_data/ragflow.txt", "rb") as file:
  75. blob = file.read()
  76. document = {"display_name": display_name, "blob": blob}
  77. documents = []
  78. documents.append(document)
  79. docs = kb.upload_documents(documents)
  80. for doc in docs:
  81. doc.add_chunk("This is a test to add chunk")
  82. assistant = rag.create_chat("test_update_session", dataset_ids=[kb.id])
  83. session = assistant.create_session(name="old session")
  84. session.update({"name": "new session"})
  85. def test_list_sessions_with_success(get_api_key_fixture):
  86. API_KEY = get_api_key_fixture
  87. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  88. kb = rag.create_dataset(name="test_list_session")
  89. display_name = "ragflow.txt"
  90. with open("test_data/ragflow.txt", "rb") as file:
  91. blob = file.read()
  92. document = {"display_name": display_name, "blob": blob}
  93. documents = []
  94. documents.append(document)
  95. docs = kb.upload_documents(documents)
  96. for doc in docs:
  97. doc.add_chunk("This is a test to add chunk")
  98. assistant = rag.create_chat("test_list_session", dataset_ids=[kb.id])
  99. assistant.create_session("test_1")
  100. assistant.create_session("test_2")
  101. assistant.list_sessions()
  102. @pytest.mark.skip(reason="")
  103. def test_create_agent_session_with_success(get_api_key_fixture):
  104. API_KEY = "ragflow-BkOGNhYjIyN2JiODExZWY5MzVhMDI0Mm"
  105. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  106. Agent.create_session("2e45b5209c1011efa3e90242ac120006", rag)
  107. @pytest.mark.skip(reason="")
  108. def test_create_agent_conversation_with_success(get_api_key_fixture):
  109. API_KEY = "ragflow-BkOGNhYjIyN2JiODExZWY5MzVhMDI0Mm"
  110. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  111. session = Agent.create_session("2e45b5209c1011efa3e90242ac120006", rag)
  112. session.ask("What is this job")
  113. @pytest.mark.skip(reason="")
  114. def test_list_agent_sessions_with_success(get_api_key_fixture):
  115. API_KEY = "ragflow-BkOGNhYjIyN2JiODExZWY5MzVhMDI0Mm"
  116. agent_id = "2710f2269b4611ef8fdf0242ac120006"
  117. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  118. Agent.list_sessions(agent_id, rag)