您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from ragflow_sdk import RAGFlow
  2. HOST_ADDRESS = 'http://127.0.0.1:9380'
  3. def test_create_session_with_success(get_api_key_fixture):
  4. API_KEY = get_api_key_fixture
  5. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  6. kb = rag.create_dataset(name="test_create_session")
  7. displayed_name = "ragflow.txt"
  8. with open("./ragflow.txt", "rb") as file:
  9. blob = file.read()
  10. document = {"displayed_name":displayed_name,"blob":blob}
  11. documents = []
  12. documents.append(document)
  13. docs= kb.upload_documents(documents)
  14. for doc in docs:
  15. doc.add_chunk("This is a test to add chunk")
  16. assistant=rag.create_chat("test_create", dataset_ids=[kb.id])
  17. assistant.create_session()
  18. def test_create_conversation_with_success(get_api_key_fixture):
  19. API_KEY = get_api_key_fixture
  20. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  21. kb = rag.create_dataset(name="test_create_conversation")
  22. displayed_name = "ragflow.txt"
  23. with open("./ragflow.txt","rb") as file:
  24. blob = file.read()
  25. document = {"displayed_name": displayed_name, "blob": blob}
  26. documents = []
  27. documents.append(document)
  28. docs = kb.upload_documents(documents)
  29. for doc in docs:
  30. doc.add_chunk("This is a test to add chunk")
  31. assistant = rag.create_chat("test_create", dataset_ids=[kb.id])
  32. session = assistant.create_session()
  33. question = "What is AI"
  34. for ans in session.ask(question, stream=True):
  35. pass
  36. assert not ans.content.startswith("**ERROR**"), "Please check this error."
  37. def test_delete_sessions_with_success(get_api_key_fixture):
  38. API_KEY = get_api_key_fixture
  39. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  40. kb = rag.create_dataset(name="test_delete_session")
  41. displayed_name = "ragflow.txt"
  42. with open("./ragflow.txt","rb") as file:
  43. blob = file.read()
  44. document = {"displayed_name":displayed_name,"blob":blob}
  45. documents = []
  46. documents.append(document)
  47. docs= kb.upload_documents(documents)
  48. for doc in docs:
  49. doc.add_chunk("This is a test to add chunk")
  50. assistant=rag.create_chat("test_create", dataset_ids=[kb.id])
  51. session = assistant.create_session()
  52. assistant.delete_sessions(ids=[session.id])
  53. def test_update_session_with_name(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_update_session")
  57. displayed_name = "ragflow.txt"
  58. with open("./ragflow.txt","rb") as file:
  59. blob = file.read()
  60. document = {"displayed_name": displayed_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_create", dataset_ids=[kb.id])
  67. session = assistant.create_session(name="old session")
  68. session.update({"name": "new session"})
  69. def test_list_sessions_with_success(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_list_session")
  73. displayed_name = "ragflow.txt"
  74. with open("./ragflow.txt","rb") as file:
  75. blob = file.read()
  76. document = {"displayed_name":displayed_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_create", dataset_ids=[kb.id])
  83. assistant.create_session("test_1")
  84. assistant.create_session("test_2")
  85. assistant.list_sessions()