Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

t_session.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from ragflow_sdk import RAGFlow,Agent
  2. from common import HOST_ADDRESS
  3. import pytest
  4. def test_create_session_with_success(get_api_key_fixture):
  5. API_KEY = get_api_key_fixture
  6. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  7. kb = rag.create_dataset(name="test_create_session")
  8. displayed_name = "ragflow.txt"
  9. with open("ragflow.txt", "rb") as file:
  10. blob = file.read()
  11. document = {"displayed_name":displayed_name,"blob":blob}
  12. documents = []
  13. documents.append(document)
  14. docs= kb.upload_documents(documents)
  15. for doc in docs:
  16. doc.add_chunk("This is a test to add chunk")
  17. assistant=rag.create_chat("test_create_session", dataset_ids=[kb.id])
  18. assistant.create_session()
  19. def test_create_conversation_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_conversation")
  23. displayed_name = "ragflow.txt"
  24. with open("ragflow.txt", "rb") as file:
  25. blob = file.read()
  26. document = {"displayed_name": displayed_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_conversation", dataset_ids=[kb.id])
  33. session = assistant.create_session()
  34. question = "What is AI"
  35. for ans in session.ask(question, stream=True):
  36. pass
  37. # assert not ans.content.startswith("**ERROR**"), "Please check this error."
  38. def test_delete_sessions_with_success(get_api_key_fixture):
  39. API_KEY = get_api_key_fixture
  40. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  41. kb = rag.create_dataset(name="test_delete_session")
  42. displayed_name = "ragflow.txt"
  43. with open("ragflow.txt", "rb") as file:
  44. blob = file.read()
  45. document = {"displayed_name":displayed_name,"blob":blob}
  46. documents = []
  47. documents.append(document)
  48. docs= kb.upload_documents(documents)
  49. for doc in docs:
  50. doc.add_chunk("This is a test to add chunk")
  51. assistant=rag.create_chat("test_delete_session", dataset_ids=[kb.id])
  52. session = assistant.create_session()
  53. assistant.delete_sessions(ids=[session.id])
  54. def test_update_session_with_name(get_api_key_fixture):
  55. API_KEY = get_api_key_fixture
  56. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  57. kb = rag.create_dataset(name="test_update_session")
  58. displayed_name = "ragflow.txt"
  59. with open("ragflow.txt", "rb") as file:
  60. blob = file.read()
  61. document = {"displayed_name": displayed_name, "blob": blob}
  62. documents = []
  63. documents.append(document)
  64. docs = kb.upload_documents(documents)
  65. for doc in docs:
  66. doc.add_chunk("This is a test to add chunk")
  67. assistant = rag.create_chat("test_update_session", dataset_ids=[kb.id])
  68. session = assistant.create_session(name="old session")
  69. session.update({"name": "new session"})
  70. def test_list_sessions_with_success(get_api_key_fixture):
  71. API_KEY = get_api_key_fixture
  72. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  73. kb = rag.create_dataset(name="test_list_session")
  74. displayed_name = "ragflow.txt"
  75. with open("ragflow.txt", "rb") as file:
  76. blob = file.read()
  77. document = {"displayed_name":displayed_name,"blob":blob}
  78. documents = []
  79. documents.append(document)
  80. docs= kb.upload_documents(documents)
  81. for doc in docs:
  82. doc.add_chunk("This is a test to add chunk")
  83. assistant=rag.create_chat("test_list_session", dataset_ids=[kb.id])
  84. assistant.create_session("test_1")
  85. assistant.create_session("test_2")
  86. assistant.list_sessions()
  87. @pytest.mark.skip(reason="")
  88. def test_create_agent_session_with_success(get_api_key_fixture):
  89. API_KEY = "ragflow-BkOGNhYjIyN2JiODExZWY5MzVhMDI0Mm"
  90. rag = RAGFlow(API_KEY,HOST_ADDRESS)
  91. Agent.create_session("2e45b5209c1011efa3e90242ac120006", rag)
  92. @pytest.mark.skip(reason="")
  93. def test_create_agent_conversation_with_success(get_api_key_fixture):
  94. API_KEY = "ragflow-BkOGNhYjIyN2JiODExZWY5MzVhMDI0Mm"
  95. rag = RAGFlow(API_KEY,HOST_ADDRESS)
  96. session = Agent.create_session("2e45b5209c1011efa3e90242ac120006", rag)
  97. session.ask("What is this job")