Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

t_chat.py 2.5KB

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