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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import os
  2. from ragflow_sdk import RAGFlow
  3. HOST_ADDRESS = os.getenv('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. docs= kb.upload_documents(documents)
  15. for doc in docs:
  16. doc.add_chunk("This is a test to add chunk")
  17. rag.create_chat("test_create", dataset_ids=[kb.id])
  18. def test_update_chat_with_name(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_update_chat")
  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. chat = rag.create_chat("test_update", dataset_ids=[kb.id])
  32. chat.update({"name": "new_chat"})
  33. def test_delete_chats_with_success(get_api_key_fixture):
  34. API_KEY = get_api_key_fixture
  35. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  36. kb = rag.create_dataset(name="test_delete_chat")
  37. displayed_name = "ragflow.txt"
  38. with open("ragflow.txt", "rb") as file:
  39. blob = file.read()
  40. document = {"displayed_name": displayed_name, "blob": blob}
  41. documents = []
  42. documents.append(document)
  43. docs = kb.upload_documents(documents)
  44. for doc in docs:
  45. doc.add_chunk("This is a test to add chunk")
  46. chat = rag.create_chat("test_delete", dataset_ids=[kb.id])
  47. rag.delete_chats(ids=[chat.id])
  48. def test_list_chats_with_success(get_api_key_fixture):
  49. API_KEY = get_api_key_fixture
  50. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  51. kb = rag.create_dataset(name="test_list_chats")
  52. displayed_name = "ragflow.txt"
  53. with open("ragflow.txt", "rb") as file:
  54. blob = file.read()
  55. document = {"displayed_name": displayed_name, "blob": blob}
  56. documents = []
  57. documents.append(document)
  58. docs = kb.upload_documents(documents)
  59. for doc in docs:
  60. doc.add_chunk("This is a test to add chunk")
  61. rag.create_chat("test_list_1", dataset_ids=[kb.id])
  62. rag.create_chat("test_list_2", dataset_ids=[kb.id])
  63. rag.list_chats()