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

t_chat.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from ragflow import RAGFlow, Chat
  2. import time
  3. HOST_ADDRESS = 'http://127.0.0.1:9380'
  4. def test_create_chat_with_name(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_chat")
  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. doc_ids = []
  15. docs= kb.upload_documents(documents)
  16. for doc in docs:
  17. doc_ids.append(doc.id)
  18. kb.async_parse_documents(doc_ids)
  19. time.sleep(60)
  20. rag.create_chat("test_create", datasets=[kb])
  21. def test_update_chat_with_name(get_api_key_fixture):
  22. API_KEY = get_api_key_fixture
  23. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  24. kb = rag.create_dataset(name="test_update_chat")
  25. displayed_name = "ragflow.txt"
  26. with open("./ragflow.txt", "rb") as file:
  27. blob = file.read()
  28. document = {"displayed_name": displayed_name, "blob": blob}
  29. documents = []
  30. documents.append(document)
  31. doc_ids = []
  32. docs = kb.upload_documents(documents)
  33. for doc in docs:
  34. doc_ids.append(doc.id)
  35. kb.async_parse_documents(doc_ids)
  36. time.sleep(60)
  37. chat = rag.create_chat("test_update", datasets=[kb])
  38. chat.update({"name": "new_chat"})
  39. def test_delete_chats_with_success(get_api_key_fixture):
  40. API_KEY = get_api_key_fixture
  41. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  42. kb = rag.create_dataset(name="test_delete_chat")
  43. displayed_name = "ragflow.txt"
  44. with open("./ragflow.txt", "rb") as file:
  45. blob = file.read()
  46. document = {"displayed_name": displayed_name, "blob": blob}
  47. documents = []
  48. documents.append(document)
  49. doc_ids = []
  50. docs = kb.upload_documents(documents)
  51. for doc in docs:
  52. doc_ids.append(doc.id)
  53. kb.async_parse_documents(doc_ids)
  54. time.sleep(60)
  55. chat = rag.create_chat("test_delete", datasets=[kb])
  56. rag.delete_chats(ids=[chat.id])
  57. API_KEY = get_api_key_fixture
  58. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  59. rag.list_chats()