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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from ragflow_sdk import RAGFlow, DataSet, Document, Chunk
  2. from common import HOST_ADDRESS
  3. def test_upload_document_with_success(get_api_key_fixture):
  4. API_KEY = get_api_key_fixture
  5. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  6. ds = rag.create_dataset(name="test_upload_document")
  7. blob = b"Sample document content for test."
  8. with open("ragflow.txt","rb") as file:
  9. blob_2=file.read()
  10. document_infos = []
  11. document_infos.append({"displayed_name": "test_1.txt","blob": blob})
  12. document_infos.append({"displayed_name": "test_2.txt","blob": blob_2})
  13. ds.upload_documents(document_infos)
  14. def test_update_document_with_success(get_api_key_fixture):
  15. API_KEY = get_api_key_fixture
  16. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  17. ds = rag.create_dataset(name="test_update_document")
  18. blob = b"Sample document content for test."
  19. document_infos=[{"displayed_name":"test.txt","blob":blob}]
  20. docs=ds.upload_documents(document_infos)
  21. doc = docs[0]
  22. doc.update({"chunk_method": "manual", "name": "manual.txt"})
  23. def test_download_document_with_success(get_api_key_fixture):
  24. API_KEY = get_api_key_fixture
  25. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  26. ds = rag.create_dataset(name="test_download_document")
  27. blob = b"Sample document content for test."
  28. document_infos=[{"displayed_name": "test_1.txt","blob": blob}]
  29. docs=ds.upload_documents(document_infos)
  30. doc = docs[0]
  31. with open("test_download.txt","wb+") as file:
  32. file.write(doc.download())
  33. def test_list_documents_in_dataset_with_success(get_api_key_fixture):
  34. API_KEY = get_api_key_fixture
  35. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  36. ds = rag.create_dataset(name="test_list_documents")
  37. blob = b"Sample document content for test."
  38. document_infos = [{"displayed_name": "test.txt","blob":blob}]
  39. ds.upload_documents(document_infos)
  40. ds.list_documents(keywords="test", page=1, page_size=12)
  41. def test_delete_documents_in_dataset_with_success(get_api_key_fixture):
  42. API_KEY = get_api_key_fixture
  43. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  44. ds = rag.create_dataset(name="test_delete_documents")
  45. name = "test_delete_documents.txt"
  46. blob = b"Sample document content for test."
  47. document_infos=[{"displayed_name": name, "blob": blob}]
  48. docs = ds.upload_documents(document_infos)
  49. ds.delete_documents([docs[0].id])