Skip to content

Commit 6a0a603

Browse files
authored
blackened code to prevent IDE scrolling (#330)
1 parent a9738c8 commit 6a0a603

19 files changed

+262
-181
lines changed

paperqa/agents/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
except ImportError as e:
2323
raise ImportError(
24-
'"agents" module is not installed please install it using "pip install paper-qa[agents]"'
24+
'"agents" module is not installed please install it using "pip install'
25+
' paper-qa[agents]"'
2526
) from e
2627

2728
logger = logging.getLogger(__name__)
@@ -181,7 +182,10 @@ def main():
181182
"--settings",
182183
"-s",
183184
default="default",
184-
help="Named settings to use. Will search in local, pqa directory, and package last",
185+
help=(
186+
"Named settings to use. Will search in local, pqa directory, and package"
187+
" last"
188+
),
185189
)
186190

187191
parser.add_argument(
@@ -205,8 +209,10 @@ def main():
205209

206210
search_parser = subparsers.add_parser(
207211
"search",
208-
help="Search the index specified by --index."
209-
" Pass `--index answers` to search previous answers.",
212+
help=(
213+
"Search the index specified by --index."
214+
" Pass `--index answers` to search previous answers."
215+
),
210216
)
211217
search_parser.add_argument("query", help="Keyword search")
212218

paperqa/agents/helpers.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ async def litellm_get_search_query(
3535
"{count}" in template and "{question}" in template and "{date}" in template
3636
):
3737
logger.warning(
38-
"Template does not contain {count}, {question} and {date} variables. Ignoring template."
38+
"Template does not contain {count}, {question} and {date} variables."
39+
" Ignoring template."
3940
)
4041
template = None
4142

@@ -45,15 +46,13 @@ async def litellm_get_search_query(
4546

4647
if template is None:
4748
search_prompt = (
48-
"We want to answer the following question: {question} \n"
49-
"Provide {count} unique keyword searches (one search per line) and year ranges "
50-
"that will find papers to help answer the question. "
51-
"Do not use boolean operators. "
52-
"Make sure not to repeat searches without changing the keywords or year ranges. "
53-
"Make some searches broad and some narrow. "
54-
"Use this format: [keyword search], [start year]-[end year]. "
55-
"where end year is optional. "
56-
f"The current year is {get_year()}."
49+
"We want to answer the following question: {question} \nProvide"
50+
" {count} unique keyword searches (one search per line) and year ranges"
51+
" that will find papers to help answer the question. Do not use boolean"
52+
" operators. Make sure not to repeat searches without changing the"
53+
" keywords or year ranges. Make some searches broad and some narrow. Use"
54+
" this format: [keyword search], [start year]-[end year]. where end year"
55+
f" is optional. The current year is {get_year()}."
5756
)
5857

5958
model = LiteLLMModel(name=llm)

paperqa/agents/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ async def agent_query(
6565
truncation_chars = 1_000_000 if verbosity > 1 else 1500 * (verbosity + 1)
6666
agent_logger.info(
6767
f"[bold blue]Answer: {response.answer.answer[:truncation_chars]}"
68-
f'{"...(truncated)" if len(response.answer.answer) > truncation_chars else ""}[/bold blue]'
68+
f"{'...(truncated)' if len(response.answer.answer) > truncation_chars else ''}"
69+
"[/bold blue]"
6970
)
7071

7172
await search_index.add_document(
@@ -104,7 +105,8 @@ async def run_agent(
104105
profiler.start(outer_profile_name)
105106

106107
logger.info(
107-
f"Beginning agent {agent_type!r} run with question {query.query!r} and full query {query.model_dump()}."
108+
f"Beginning agent {agent_type!r} run with question {query.query!r} and full"
109+
f" query {query.model_dump()}."
108110
)
109111

110112
if agent_type == "fake":
@@ -118,7 +120,8 @@ async def run_agent(
118120
agent_status = AgentStatus.UNSURE
119121
# stop after, so overall isn't reported as long-running step.
120122
logger.info(
121-
f"Finished agent {agent_type!r} run with question {query.query!r} and status {agent_status}."
123+
f"Finished agent {agent_type!r} run with question {query.query!r} and status"
124+
f" {agent_status}."
122125
)
123126
return AnswerResponse(
124127
answer=answer,
@@ -290,7 +293,8 @@ async def aplan_with_injected_callbacks(
290293
if "Agent stopped" in call_response["output"]:
291294
# Log that this agent has gone over timeout, and then answer directly
292295
logger.warning(
293-
f"Agent timeout after {query.settings.agent.timeout}-sec, just answering."
296+
f"Agent timeout after {query.settings.agent.timeout}-sec, just"
297+
" answering."
294298
)
295299
await answer_tool.arun(answer.question)
296300
agent_status = AgentStatus.TIMEOUT

paperqa/agents/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ async def timer(self, name: str):
158158
elapsed = end_time - start_time
159159
self.timers.setdefault(name, []).append(elapsed)
160160
logger.info(
161-
f"[Profiling] | UUID: {self.uid} | NAME: {name} | TIME: {elapsed:.3f}s | VERSION: {__version__}"
161+
f"[Profiling] | UUID: {self.uid} | NAME: {name} | TIME: {elapsed:.3f}s"
162+
f" | VERSION: {__version__}"
162163
)
163164

164165
def start(self, name: str) -> None:
@@ -177,7 +178,8 @@ def stop(self, name: str):
177178
elapsed = t_stop - timer_data.start_time
178179
self.timers.setdefault(name, []).append(elapsed)
179180
logger.info(
180-
f"[Profiling] | UUID: {self.uid} | NAME: {name} | TIME: {elapsed:.3f}s | VERSION: {__version__}"
181+
f"[Profiling] | UUID: {self.uid} | NAME: {name} | TIME: {elapsed:.3f}s"
182+
f" | VERSION: {__version__}"
181183
)
182184
else:
183185
logger.warning(f"Timer {name} not running")

paperqa/agents/search.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ async def _add_document_with_retry():
228228
await _add_document_with_retry()
229229
except RetryError:
230230
logger.exception(
231-
f"Failed to add document after {max_retries} attempts: {index_doc['file_location']}"
231+
f"Failed to add document after {max_retries} attempts:"
232+
f" {index_doc['file_location']}"
232233
)
233234
raise
234235

@@ -450,7 +451,8 @@ async def get_directory_index(
450451
logger.warning("[bold red]Files removed![/bold red]")
451452
else:
452453
logger.warning(
453-
f"[bold red]Indexed files are missing from index folder ({directory}).[/bold red]"
454+
"[bold red]Indexed files are missing from index folder"
455+
f" ({directory}).[/bold red]"
454456
)
455457
logger.warning(f"[bold red]files: {missing}[/bold red]")
456458

paperqa/agents/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
async def status(docs: Docs, answer: Answer, relevant_score_cutoff: int = 5) -> str:
2929
"""Create a string that provides a summary of the input doc/answer."""
3030
return (
31-
f"Status: Paper Count={len(docs.docs)}"
32-
f" | Relevant Papers={len({c.text.doc.dockey for c in answer.contexts if c.score > relevant_score_cutoff})}"
31+
f"Status: Paper Count={len(docs.docs)} | Relevant Papers="
32+
f"{len({c.text.doc.dockey for c in answer.contexts if c.score > relevant_score_cutoff})}"
3333
f" | Current Evidence={len([c for c in answer.contexts if c.score > relevant_score_cutoff])}"
3434
f" | Current Cost=${answer.cost:.2f}"
3535
)

paperqa/clients/client_models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ async def query(self, query: dict) -> DocDetails | None:
112112
# this service from failing us when it's down or slow.
113113
except DOINotFoundError:
114114
logger.warning(
115-
f"Metadata not found for "
116-
f"{client_query.doi if isinstance(client_query, DOIQuery) else client_query.title}"
117-
f" in {self.__class__.__name__}."
115+
"Metadata not found for"
116+
f" {client_query.doi if isinstance(client_query, DOIQuery) else client_query.title} in"
117+
f" {self.__class__.__name__}."
118118
)
119119
except (TimeoutError, asyncio.exceptions.TimeoutError):
120120
logger.warning(
121-
f"Request to {self.__class__.__name__} for "
122-
f"{client_query.doi if isinstance(client_query, DOIQuery) else client_query.title}"
123-
" timed out."
121+
f"Request to {self.__class__.__name__} for"
122+
f" {client_query.doi if isinstance(client_query, DOIQuery) else client_query.title} timed"
123+
" out."
124124
)
125125
return None
126126

paperqa/clients/crossref.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def crossref_headers() -> dict[str, str]:
9696
if api_key := os.environ.get("CROSSREF_API_KEY"):
9797
return {CROSSREF_HEADER_KEY: f"Bearer {api_key}"}
9898
logger.warning(
99-
"CROSSREF_API_KEY environment variable not set. Crossref API rate limits may apply."
99+
"CROSSREF_API_KEY environment variable not set. Crossref API rate limits may"
100+
" apply."
100101
)
101102
return {}
102103

@@ -253,7 +254,8 @@ async def get_doc_details_from_crossref( # noqa: PLR0912
253254

254255
if not (CROSSREF_MAILTO := os.getenv("CROSSREF_MAILTO")):
255256
logger.warning(
256-
"CROSSREF_MAILTO environment variable not set. Crossref API rate limits may apply."
257+
"CROSSREF_MAILTO environment variable not set. Crossref API rate limits may"
258+
" apply."
257259
)
258260
CROSSREF_MAILTO = "[email protected]"
259261
quoted_doi = f"/{quote(doi, safe='')}" if doi else ""

paperqa/clients/semantic_scholar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ def semantic_scholar_headers() -> dict[str, str]:
194194
if api_key := os.environ.get("SEMANTIC_SCHOLAR_API_KEY"):
195195
return {SEMANTIC_SCHOLAR_HEADER_KEY: api_key}
196196
logger.warning(
197-
"SEMANTIC_SCHOLAR_API_KEY environment variable not set. Semantic Scholar API rate limits may apply."
197+
"SEMANTIC_SCHOLAR_API_KEY environment variable not set. Semantic Scholar API"
198+
" rate limits may apply."
198199
)
199200
return {}
200201

paperqa/clients/unpaywall.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ async def get_doc_details(
8888
results = UnpaywallResponse(
8989
**(
9090
await _get_with_retrying(
91-
url=f"{UNPAYWALL_BASE_URL}{doi}?email={os.environ.get('UNPAYWALL_EMAIL', '[email protected]')}",
91+
url=(
92+
f"{UNPAYWALL_BASE_URL}{doi}?email={os.environ.get('UNPAYWALL_EMAIL', '[email protected]')}"
93+
),
9294
params={},
9395
session=session,
9496
timeout=UNPAYWALL_TIMEOUT,

paperqa/contrib/zotero.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class ZoteroPaper(BaseModel):
4343
def __str__(self) -> str:
4444
"""Return the title of the paper."""
4545
return (
46-
f'ZoteroPaper(\n key = "{self.key}",\n'
47-
f'title = "{self.title}",\n pdf = "{self.pdf}",\n '
48-
f'num_pages = {self.num_pages},\n zotero_key = "{self.zotero_key}",\n details = ...\n)'
46+
f'ZoteroPaper(\n key = "{self.key}",\ntitle = "{self.title}",\n pdf ='
47+
f' "{self.pdf}",\n num_pages = {self.num_pages},\n zotero_key ='
48+
f' "{self.zotero_key}",\n details = ...\n)'
4949
)
5050

5151

@@ -205,7 +205,8 @@ def iterate( # noqa: PLR0912
205205

206206
if collection_name is not None and len(query_kwargs) > 0:
207207
raise ValueError(
208-
"You cannot specify a `collection_name` and search query simultaneously!"
208+
"You cannot specify a `collection_name` and search query"
209+
" simultaneously!"
209210
)
210211

211212
max_limit = 100

paperqa/docs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ async def aadd( # noqa: PLR0912
368368
)
369369
):
370370
raise ValueError(
371-
f"This does not look like a text document: {path}. Pass disable_check to ignore this error."
371+
f"This does not look like a text document: {path}. Pass disable_check"
372+
" to ignore this error."
372373
)
373374
if await self.aadd_texts(texts, doc, all_settings, embedding_model):
374375
return docname

paperqa/llms.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ class LLMModel(ABC, BaseModel):
126126
Callable[[LLMResult], None] | Callable[[LLMResult], Awaitable[None]] | None
127127
) = Field(
128128
default=None,
129-
description="An async callback that will be executed on each"
130-
" LLMResult (different than callbacks that execute on each chunk)",
129+
description=(
130+
"An async callback that will be executed on each"
131+
" LLMResult (different than callbacks that execute on each chunk)"
132+
),
131133
exclude=True,
132134
)
133135
config: dict = Field(default_factory=dict)

paperqa/prompts.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
summary_prompt = (
2-
"Summarize the excerpt below to help answer a question.\n\n"
3-
"Excerpt from {citation}\n\n----\n\n{text}\n\n----\n\n"
4-
"Question: {question}\n\n"
5-
"Do not directly answer the question, instead summarize to give evidence to help "
6-
"answer the question. Stay detailed; report specific numbers, equations, or "
7-
'direct quotes (marked with quotation marks). Reply "Not applicable" if the '
8-
"excerpt is irrelevant. At the end of your response, provide an integer score "
9-
"from 1-10 on a newline indicating relevance to question. Do not explain your score."
10-
"\n\nRelevant Information Summary ({summary_length}):"
2+
"Summarize the excerpt below to help answer a question.\n\nExcerpt from"
3+
" {citation}\n\n----\n\n{text}\n\n----\n\nQuestion: {question}\n\nDo not directly"
4+
" answer the question, instead summarize to give evidence to help answer the"
5+
" question. Stay detailed; report specific numbers, equations, or direct quotes"
6+
' (marked with quotation marks). Reply "Not applicable" if the excerpt is'
7+
" irrelevant. At the end of your response, provide an integer score from 1-10 on a"
8+
" newline indicating relevance to question. Do not explain your score.\n\nRelevant"
9+
" Information Summary ({summary_length}):"
1110
)
1211

1312
summary_json_prompt = (

0 commit comments

Comments
 (0)