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)
|
||||
else:
|
||||
content = Markdown(doc.content)
|
||||
title_part = (
|
||||
f" [repr.attrib_name]title[/repr.attrib_name]: {doc.title}"
|
||||
if doc.title
|
||||
else ""
|
||||
)
|
||||
self.console.print(
|
||||
f"[repr.attrib_name]id[/repr.attrib_name]: {doc.id} "
|
||||
f"[repr.attrib_name]uri[/repr.attrib_name]: {doc.uri}"
|
||||
+ title_part
|
||||
+ f" [repr.attrib_name]meta[/repr.attrib_name]: {doc.metadata}"
|
||||
)
|
||||
parts = [f"[repr.attrib_name]id[/repr.attrib_name]: {doc.id}"]
|
||||
if doc.uri:
|
||||
parts.append(f"[repr.attrib_name]uri[/repr.attrib_name]: {doc.uri}")
|
||||
if doc.title:
|
||||
parts.append(f"[repr.attrib_name]title[/repr.attrib_name]: {doc.title}")
|
||||
if doc.metadata:
|
||||
parts.append(f"[repr.attrib_name]meta[/repr.attrib_name]: {doc.metadata}")
|
||||
self.console.print(" ".join(parts))
|
||||
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}"
|
||||
)
|
||||
self.console.print("[repr.attrib_name]content[/repr.attrib_name]:")
|
||||
self.console.print(content)
|
||||
# `list` does not load content, which is where the docling blobs live, so
|
||||
# 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()
|
||||
|
||||
def _rich_print_search_result(self, result: "SearchResult"):
|
||||
|
|
|
|||
|
|
@ -59,6 +59,36 @@ def _doc(content: str = "body text", **kwargs) -> Document:
|
|||
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):
|
||||
client.list_documents.return_value = [_doc("first"), _doc("second")]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue