|
42 | 42 | from paperqa.settings import MaybeSettings, get_settings
|
43 | 43 | from paperqa.types import Doc, DocDetails, DocKey, PQASession, Text
|
44 | 44 | from paperqa.utils import (
|
| 45 | + citation_to_docname, |
45 | 46 | gather_with_concurrency,
|
46 | 47 | get_loop,
|
47 | 48 | maybe_is_html,
|
@@ -306,23 +307,7 @@ async def aadd( # noqa: PLR0912
|
306 | 307 | ):
|
307 | 308 | citation = f"Unknown, {os.path.basename(path)}, {datetime.now().year}"
|
308 | 309 |
|
309 |
| - if docname is None: |
310 |
| - # get first name and year from citation |
311 |
| - match = re.search(r"([A-Z][a-z]+)", citation) |
312 |
| - if match is not None: |
313 |
| - author = match.group(1) |
314 |
| - else: |
315 |
| - # panicking - no word?? |
316 |
| - raise ValueError( |
317 |
| - f"Could not parse docname from citation {citation}. " |
318 |
| - "Consider just passing key explicitly - e.g. docs.py " |
319 |
| - "(path, citation, key='mykey')" |
320 |
| - ) |
321 |
| - year = "" |
322 |
| - match = re.search(r"(\d{4})", citation) |
323 |
| - if match is not None: |
324 |
| - year = match.group(1) |
325 |
| - docname = f"{author}{year}" |
| 310 | + docname = citation_to_docname(citation) if docname is None else docname |
326 | 311 | docname = self._get_unique_name(docname)
|
327 | 312 |
|
328 | 313 | doc = Doc(docname=docname, citation=citation, dockey=dockey)
|
@@ -801,8 +786,8 @@ async def aquery( # noqa: PLR0912
|
801 | 786 | answer_text = answer_result.text
|
802 | 787 | session.add_tokens(answer_result)
|
803 | 788 | # it still happens
|
804 |
| - if prompt_config.EXAMPLE_CITATION in answer_text: |
805 |
| - answer_text = answer_text.replace(prompt_config.EXAMPLE_CITATION, "") |
| 789 | + if (ex_citation := prompt_config.EXAMPLE_CITATION) in answer_text: |
| 790 | + answer_text = answer_text.replace(ex_citation, "") |
806 | 791 | for c in filtered_contexts:
|
807 | 792 | name = c.text.name
|
808 | 793 | citation = c.text.doc.formatted_citation
|
|
0 commit comments