Skip to content

Commit

Permalink
Cleaned up table_formatter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Jan 16, 2025
1 parent 6c70323 commit 401a073
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions paperqa/agents/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ def table_formatter(
table.add_column("Title", style="cyan")
table.add_column("File", style="magenta")
for obj, filename in objects:
doc = cast(Docs, obj).texts[0].doc
try:
# Tries to use `doc` as a `DocDetails` object
doc = cast(DocDetails, doc)
display_name = cast(str, doc.title)
except AttributeError:
# Falls back to using `formatted_citation` from `Doc`
docs = cast(Docs, obj) # Assume homogeneous objects
doc = docs.texts[0].doc
if isinstance(doc, DocDetails) and doc.title:
display_name: str = doc.title # Prefer title if available
else:
display_name = doc.formatted_citation
table.add_row(display_name[:max_chars_per_column], filename)
return table
Expand Down

0 comments on commit 401a073

Please sign in to comment.