You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

t_session.py 1.2KB

123456789101112131415161718192021222324252627
  1. from ragflow import RAGFlow
  2. from common import API_KEY, HOST_ADDRESS
  3. class TestChatSession:
  4. def test_create_session(self):
  5. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  6. kb = rag.create_dataset(name="test_create_session")
  7. assistant = rag.create_assistant(name="test_create_session", knowledgebases=[kb])
  8. session = assistant.create_session()
  9. assert assistant is not None, "Failed to get the assistant."
  10. assert session is not None, "Failed to create a session."
  11. def test_create_chat_with_success(self):
  12. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  13. kb = rag.create_dataset(name="test_create_chat")
  14. assistant = rag.create_assistant(name="test_create_chat", knowledgebases=[kb])
  15. session = assistant.create_session()
  16. assert session is not None, "Failed to create a session."
  17. prologue = assistant.get_prologue()
  18. assert isinstance(prologue, str), "Prologue is not a string."
  19. assert len(prologue) > 0, "Prologue is empty."
  20. question = "What is AI"
  21. ans = session.chat(question, stream=True)
  22. response = ans[-1].content
  23. assert len(response) > 0, "Assistant did not return any response."