Print only the document fields there are
`list` does not load content, which is where the docling blobs live, so the
`content:` header announced a field the command declined to fetch. A document
without a uri or metadata printed `uri: None` and `meta: {}`, where `title`
was already omitted when absent.
This commit is contained in:
parent
db5f61d740
commit
ab0bdff14c
2 changed files with 43 additions and 13 deletions
|
|
@ -855,22 +855,22 @@ class HaikuRAGApp:
|
||||||
content = Markdown(content)
|
content = Markdown(content)
|
||||||
else:
|
else:
|
||||||
content = Markdown(doc.content)
|
content = Markdown(doc.content)
|
||||||
title_part = (
|
parts = [f"[repr.attrib_name]id[/repr.attrib_name]: {doc.id}"]
|
||||||
f" [repr.attrib_name]title[/repr.attrib_name]: {doc.title}"
|
if doc.uri:
|
||||||
if doc.title
|
parts.append(f"[repr.attrib_name]uri[/repr.attrib_name]: {doc.uri}")
|
||||||
else ""
|
if doc.title:
|
||||||
)
|
parts.append(f"[repr.attrib_name]title[/repr.attrib_name]: {doc.title}")
|
||||||
self.console.print(
|
if doc.metadata:
|
||||||
f"[repr.attrib_name]id[/repr.attrib_name]: {doc.id} "
|
parts.append(f"[repr.attrib_name]meta[/repr.attrib_name]: {doc.metadata}")
|
||||||
f"[repr.attrib_name]uri[/repr.attrib_name]: {doc.uri}"
|
self.console.print(" ".join(parts))
|
||||||
+ title_part
|
|
||||||
+ f" [repr.attrib_name]meta[/repr.attrib_name]: {doc.metadata}"
|
|
||||||
)
|
|
||||||
self.console.print(
|
self.console.print(
|
||||||
f"[repr.attrib_name]created at[/repr.attrib_name]: {doc.created_at} [repr.attrib_name]updated at[/repr.attrib_name]: {doc.updated_at}"
|
f"[repr.attrib_name]created at[/repr.attrib_name]: {doc.created_at} [repr.attrib_name]updated at[/repr.attrib_name]: {doc.updated_at}"
|
||||||
)
|
)
|
||||||
self.console.print("[repr.attrib_name]content[/repr.attrib_name]:")
|
# `list` does not load content, which is where the docling blobs live, so
|
||||||
self.console.print(content)
|
# the header would otherwise announce a field the command declined to fetch.
|
||||||
|
if doc.content:
|
||||||
|
self.console.print("[repr.attrib_name]content[/repr.attrib_name]:")
|
||||||
|
self.console.print(content)
|
||||||
self.console.rule()
|
self.console.rule()
|
||||||
|
|
||||||
def _rich_print_search_result(self, result: "SearchResult"):
|
def _rich_print_search_result(self, result: "SearchResult"):
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,36 @@ def _doc(content: str = "body text", **kwargs) -> Document:
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
|
async def test_a_listing_omits_the_fields_it_did_not_fetch(app, client):
|
||||||
|
"""`list` does not load content, and a document need not carry a uri, a
|
||||||
|
title or metadata. Printing a header for each regardless announced fields
|
||||||
|
the command declined to fetch or the document never had."""
|
||||||
|
bare = Document(content="", uri=None)
|
||||||
|
bare.id = "doc-bare"
|
||||||
|
client.list_documents.return_value = [bare]
|
||||||
|
|
||||||
|
await app.list_documents()
|
||||||
|
|
||||||
|
printed = out(app)
|
||||||
|
assert "doc-bare" in printed
|
||||||
|
for absent in ("uri:", "title:", "meta:", "content:"):
|
||||||
|
assert absent not in printed, absent
|
||||||
|
|
||||||
|
|
||||||
|
async def test_a_listing_prints_the_fields_it_has(app, client):
|
||||||
|
client.list_documents.return_value = [
|
||||||
|
_doc("body text", title="A title", metadata={"k": "v"})
|
||||||
|
]
|
||||||
|
|
||||||
|
await app.list_documents()
|
||||||
|
|
||||||
|
printed = out(app)
|
||||||
|
assert "uri: test://doc" in printed
|
||||||
|
assert "title: A title" in printed
|
||||||
|
assert "meta:" in printed
|
||||||
|
assert "content:" in printed
|
||||||
|
|
||||||
|
|
||||||
async def test_list_documents_prints_each_document(app, client):
|
async def test_list_documents_prints_each_document(app, client):
|
||||||
client.list_documents.return_value = [_doc("first"), _doc("second")]
|
client.list_documents.return_value = [_doc("first"), _doc("second")]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue