|
|
|
|
|
|
|
|
name3 = 'westworld.pdf' |
|
|
name3 = 'westworld.pdf' |
|
|
path = 'test_data/westworld.pdf' |
|
|
path = 'test_data/westworld.pdf' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a document in the dataset using the file path |
|
|
# Create a document in the dataset using the file path |
|
|
rag.create_document(ds, name=name3, blob=open(path, "rb").read()) |
|
|
rag.create_document(ds, name=name3, blob=open(path, "rb").read()) |
|
|
|
|
|
|
|
|
# Retrieve the document by name |
|
|
# Retrieve the document by name |
|
|
doc = rag.get_document(name="westworld.pdf") |
|
|
doc = rag.get_document(name="westworld.pdf") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Initiate asynchronous parsing |
|
|
# Initiate asynchronous parsing |
|
|
doc.async_parse() |
|
|
doc.async_parse() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_document_and_chunk_list(self): |
|
|
def test_parse_document_and_chunk_list(self): |
|
|
rag = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
rag = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
ds = rag.create_dataset(name="God7") |
|
|
ds = rag.create_dataset(name="God7") |
|
|
name='story.txt' |
|
|
|
|
|
|
|
|
name = 'story.txt' |
|
|
path = 'test_data/story.txt' |
|
|
path = 'test_data/story.txt' |
|
|
# name = "Test Document rag.txt" |
|
|
# name = "Test Document rag.txt" |
|
|
# blob = " Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps.Sample document content for rag test66. rag wonderful apple os documents apps.Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps." |
|
|
# blob = " Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps.Sample document content for rag test66. rag wonderful apple os documents apps.Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps." |
|
|
|
|
|
|
|
|
assert chunk is not None, "Chunk is None" |
|
|
assert chunk is not None, "Chunk is None" |
|
|
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list" |
|
|
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list" |
|
|
doc = rag.get_document(name='story.txt') |
|
|
doc = rag.get_document(name='story.txt') |
|
|
chunk_count_before=doc.chunk_count |
|
|
|
|
|
|
|
|
chunk_count_before = doc.chunk_count |
|
|
chunk.delete() |
|
|
chunk.delete() |
|
|
doc = rag.get_document(name='story.txt') |
|
|
doc = rag.get_document(name='story.txt') |
|
|
assert doc.chunk_count == chunk_count_before-1, "Chunk was not deleted" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert doc.chunk_count == chunk_count_before - 1, "Chunk was not deleted" |
|
|
|
|
|
|
|
|
def test_update_chunk_content(self): |
|
|
def test_update_chunk_content(self): |
|
|
rag = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
rag = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
doc = rag.get_document(name='story.txt') |
|
|
doc = rag.get_document(name='story.txt') |
|
|
|
|
|
|
|
|
assert chunk is not None, "Chunk is None" |
|
|
assert chunk is not None, "Chunk is None" |
|
|
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list" |
|
|
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list" |
|
|
chunk.content = "ragflow123" |
|
|
chunk.content = "ragflow123" |
|
|
res=chunk.save() |
|
|
|
|
|
assert res is True, f"Failed to update chunk, error: {res}" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = chunk.save() |
|
|
|
|
|
assert res is True, f"Failed to update chunk content, error: {res}" |
|
|
|
|
|
|
|
|
|
|
|
def test_update_chunk_available(self): |
|
|
|
|
|
rag = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
|
|
doc = rag.get_document(name='story.txt') |
|
|
|
|
|
chunk = doc.add_chunk(content="ragflow") |
|
|
|
|
|
assert chunk is not None, "Chunk is None" |
|
|
|
|
|
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list" |
|
|
|
|
|
chunk.available = 0 |
|
|
|
|
|
res = chunk.save() |
|
|
|
|
|
assert res is True, f"Failed to update chunk status, error: {res}" |
|
|
|
|
|
|
|
|
def test_retrieval_chunks(self): |
|
|
def test_retrieval_chunks(self): |
|
|
rag = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
rag = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
ds = rag.create_dataset(name="God8") |
|
|
ds = rag.create_dataset(name="God8") |