Skip to content

Commit 4e0e6c2

Browse files
committed
Removed all deprecated methods and attributes
1 parent e837ebe commit 4e0e6c2

File tree

8 files changed

+11
-500
lines changed

8 files changed

+11
-500
lines changed

src/paperqa/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
from lmi import (
42
EmbeddingModel,
53
HybridEmbeddingModel,
@@ -21,17 +19,10 @@
2119
VectorStore,
2220
)
2321
from paperqa.settings import Settings, get_settings
24-
from paperqa.types import Answer, Context, Doc, DocDetails, Text
22+
from paperqa.types import Context, Doc, DocDetails, Text
2523
from paperqa.version import __version__
2624

27-
# TODO: remove after refactoring all models to avoid using _* private vars
28-
warnings.filterwarnings(
29-
"ignore", message="Valid config keys have changed in V2:", module="pydantic"
30-
)
31-
32-
3325
__all__ = [
34-
"Answer",
3526
"Context",
3627
"Doc",
3728
"DocDetails",

src/paperqa/agents/search.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pickle
1010
import re
1111
import sys
12-
import warnings
1312
import zlib
1413
from collections import Counter
1514
from collections.abc import AsyncIterator, Callable, Sequence
@@ -616,38 +615,21 @@ def progress_bar_update() -> None:
616615
return contextlib.nullcontext(), None
617616

618617

619-
async def get_directory_index( # noqa: PLR0912
620-
index_name: str | None = None,
621-
sync_index_w_directory: bool = True,
622-
settings: MaybeSettings = None,
623-
build: bool = True,
618+
async def get_directory_index(
619+
settings: MaybeSettings = None, build: bool = True
624620
) -> SearchIndex:
625621
"""
626622
Create a Tantivy index by reading from a directory of text files.
627623
628624
This function only reads from the source directory, not edits or writes to it.
629625
630626
Args:
631-
index_name: Deprecated override on the name of the index. If unspecified,
632-
the default behavior is to generate the name from the input settings.
633-
sync_index_w_directory: Opt-out flag to sync the index (add or delete index
634-
files) with the source paper directory.
635627
settings: Application settings.
636628
build: Opt-out flag (default is True) to read the contents of the source paper
637629
directory and if sync_index_w_directory is enabled also update the index.
638630
"""
639631
_settings = get_settings(settings)
640632
index_settings = _settings.agent.index
641-
if index_name:
642-
warnings.warn(
643-
"The index_name argument has been moved to"
644-
f" {type(_settings.agent.index).__name__},"
645-
" this deprecation will conclude in version 6.",
646-
category=DeprecationWarning,
647-
stacklevel=2,
648-
)
649-
index_settings.name = index_name
650-
del index_name
651633

652634
search_index = SearchIndex(
653635
fields=[*SearchIndex.REQUIRED_FIELDS, "title", "year"],
@@ -663,17 +645,6 @@ async def get_directory_index( # noqa: PLR0912
663645
)
664646
return search_index
665647

666-
if not sync_index_w_directory:
667-
warnings.warn(
668-
"The sync_index_w_directory argument has been moved to"
669-
f" {type(_settings.agent.index).__name__},"
670-
" this deprecation will conclude in version 6.",
671-
category=DeprecationWarning,
672-
stacklevel=2,
673-
)
674-
index_settings.sync_with_paper_directory = sync_index_w_directory
675-
del sync_index_w_directory
676-
677648
paper_directory = anyio.Path(index_settings.paper_directory)
678649
manifest = await maybe_get_manifest(
679650
filename=await index_settings.finalize_manifest_file()

src/paperqa/agents/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def default_status(state: "EnvironmentState") -> str:
4747
class EnvironmentState(BaseModel):
4848
"""State here contains documents and answer being populated."""
4949

50-
model_config = ConfigDict(extra="forbid", populate_by_name=True)
50+
model_config = ConfigDict(extra="forbid")
5151

5252
docs: Docs
53-
session: PQASession = Field(..., alias="answer")
53+
session: PQASession
5454
status_fn: Callable[[Self], str] | None = Field(
5555
default=None,
5656
description=(

src/paperqa/contrib/openreview_paper_helper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(
4747
password: str | None = None,
4848
) -> None:
4949
self.settings = settings
50-
Path(settings.paper_directory).mkdir(parents=True, exist_ok=True)
50+
Path(settings.agent.index.paper_directory).mkdir(parents=True, exist_ok=True)
5151
if openreview is None:
5252
raise ImportError(
5353
"openreview requires the 'openreview-py' extra. Please run: `pip"
@@ -122,7 +122,9 @@ async def _get_relevant_papers_chunk(self, question: str, chunk: str) -> list[An
122122

123123
async def download_papers(self, submissions: list[Any]) -> None:
124124
"""Download PDFs for given submissions."""
125-
downloaded_papers = Path(self.settings.paper_directory).rglob("*.pdf")
125+
downloaded_papers = Path(self.settings.agent.index.paper_directory).rglob(
126+
"*.pdf"
127+
)
126128
downloaded_ids = [p.stem for p in downloaded_papers]
127129
logger.info("Downloading PDFs for relevant papers.")
128130
for submission in submissions:
@@ -136,7 +138,7 @@ async def _download_pdf(self, submission: Any) -> bool:
136138
response = await client.get(pdf_link)
137139
if response.status_code == httpx.codes.OK.value:
138140
async with await anyio.open_file(
139-
f"{self.settings.paper_directory}/{submission.id}.pdf", "wb"
141+
f"{self.settings.agent.index.paper_directory}/{submission.id}.pdf", "wb"
140142
) as f:
141143
await f.write(response.content)
142144
return True
@@ -151,7 +153,7 @@ async def aadd_docs(
151153
) -> Docs:
152154
if docs is None:
153155
docs = Docs()
154-
for doc_path in Path(self.settings.paper_directory).rglob("*.pdf"):
156+
for doc_path in Path(self.settings.agent.index.paper_directory).rglob("*.pdf"):
155157
sub = subs.get(doc_path.stem) if subs is not None else None
156158
if sub:
157159
await docs.aadd(

src/paperqa/docs.py

Lines changed: 0 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from paperqa.types import Doc, DocDetails, DocKey, PQASession, Text
3434
from paperqa.utils import (
3535
citation_to_docname,
36-
get_loop,
3736
maybe_is_html,
3837
maybe_is_pdf,
3938
maybe_is_text,
@@ -91,35 +90,6 @@ def _get_unique_name(self, docname: str) -> str:
9190
docname += suffix
9291
return docname
9392

94-
def add_file(
95-
self,
96-
file: BinaryIO,
97-
citation: str | None = None,
98-
docname: str | None = None,
99-
dockey: DocKey | None = None,
100-
settings: MaybeSettings = None,
101-
llm_model: LLMModel | None = None,
102-
embedding_model: EmbeddingModel | None = None,
103-
) -> str | None:
104-
warnings.warn(
105-
"The synchronous `add_file` method is being deprecated in favor of the"
106-
" asynchronous `aadd_file` method, this deprecation will conclude in"
107-
" version 6.",
108-
category=DeprecationWarning,
109-
stacklevel=2,
110-
)
111-
return get_loop().run_until_complete(
112-
self.aadd_file(
113-
file,
114-
citation=citation,
115-
docname=docname,
116-
dockey=dockey,
117-
settings=settings,
118-
llm_model=llm_model,
119-
embedding_model=embedding_model,
120-
)
121-
)
122-
12393
async def aadd_file(
12494
self,
12595
file: BinaryIO,
@@ -159,35 +129,6 @@ async def aadd_file(
159129
**kwargs,
160130
)
161131

162-
def add_url(
163-
self,
164-
url: str,
165-
citation: str | None = None,
166-
docname: str | None = None,
167-
dockey: DocKey | None = None,
168-
settings: MaybeSettings = None,
169-
llm_model: LLMModel | None = None,
170-
embedding_model: EmbeddingModel | None = None,
171-
) -> str | None:
172-
warnings.warn(
173-
"The synchronous `add_url` method is being deprecated in favor of the"
174-
" asynchronous `aadd_url` method, this deprecation will conclude in"
175-
" version 6.",
176-
category=DeprecationWarning,
177-
stacklevel=2,
178-
)
179-
return get_loop().run_until_complete(
180-
self.aadd_url(
181-
url,
182-
citation=citation,
183-
docname=docname,
184-
dockey=dockey,
185-
settings=settings,
186-
llm_model=llm_model,
187-
embedding_model=embedding_model,
188-
)
189-
)
190-
191132
async def aadd_url(
192133
self,
193134
url: str,
@@ -212,43 +153,6 @@ async def aadd_url(
212153
embedding_model=embedding_model,
213154
)
214155

215-
def add(
216-
self,
217-
path: str | os.PathLike,
218-
citation: str | None = None,
219-
docname: str | None = None,
220-
dockey: DocKey | None = None,
221-
title: str | None = None,
222-
doi: str | None = None,
223-
authors: list[str] | None = None,
224-
settings: MaybeSettings = None,
225-
llm_model: LLMModel | None = None,
226-
embedding_model: EmbeddingModel | None = None,
227-
**kwargs,
228-
) -> str | None:
229-
warnings.warn(
230-
"The synchronous `add` method is being deprecated in favor of the"
231-
" asynchronous `aadd` method, this deprecation will conclude in"
232-
" version 6.",
233-
category=DeprecationWarning,
234-
stacklevel=2,
235-
)
236-
return get_loop().run_until_complete(
237-
self.aadd(
238-
path,
239-
citation=citation,
240-
docname=docname,
241-
dockey=dockey,
242-
title=title,
243-
doi=doi,
244-
authors=authors,
245-
settings=settings,
246-
llm_model=llm_model,
247-
embedding_model=embedding_model,
248-
**kwargs,
249-
)
250-
)
251-
252156
async def aadd( # noqa: PLR0912
253157
self,
254158
path: str | os.PathLike,
@@ -429,26 +333,6 @@ async def aadd( # noqa: PLR0912
429333
return doc.docname
430334
return None
431335

432-
def add_texts(
433-
self,
434-
texts: list[Text],
435-
doc: Doc,
436-
settings: MaybeSettings = None,
437-
embedding_model: EmbeddingModel | None = None,
438-
) -> bool:
439-
warnings.warn(
440-
"The synchronous `add_texts` method is being deprecated in favor of the"
441-
" asynchronous `aadd_texts` method, this deprecation will conclude in"
442-
" version 6.",
443-
category=DeprecationWarning,
444-
stacklevel=2,
445-
)
446-
return get_loop().run_until_complete(
447-
self.aadd_texts(
448-
texts, doc, settings=settings, embedding_model=embedding_model
449-
)
450-
)
451-
452336
async def aadd_texts(
453337
self,
454338
texts: list[Text],
@@ -601,39 +485,9 @@ async def retrieve_texts(
601485
matches = [m for m in matches if m.doc.dockey not in self.deleted_dockeys]
602486
return matches[:k]
603487

604-
def get_evidence(
605-
self,
606-
query: PQASession | str,
607-
exclude_text_filter: set[str] | None = None,
608-
settings: MaybeSettings = None,
609-
callbacks: Sequence[Callable] | None = None,
610-
embedding_model: EmbeddingModel | None = None,
611-
summary_llm_model: LLMModel | None = None,
612-
partitioning_fn: Callable[[Embeddable], int] | None = None,
613-
) -> PQASession:
614-
warnings.warn(
615-
"The synchronous `get_evidence` method is being deprecated in favor of the"
616-
" asynchronous `aget_evidence` method, this deprecation will conclude in"
617-
" version 6.",
618-
category=DeprecationWarning,
619-
stacklevel=2,
620-
)
621-
return get_loop().run_until_complete(
622-
self.aget_evidence(
623-
query=query,
624-
exclude_text_filter=exclude_text_filter,
625-
settings=settings,
626-
callbacks=callbacks,
627-
embedding_model=embedding_model,
628-
summary_llm_model=summary_llm_model,
629-
partitioning_fn=partitioning_fn,
630-
)
631-
)
632-
633488
async def aget_evidence(
634489
self,
635490
query: PQASession | str,
636-
exclude_text_filter: set[str] | None = None,
637491
settings: MaybeSettings = None,
638492
callbacks: Sequence[Callable] | None = None,
639493
embedding_model: EmbeddingModel | None = None,
@@ -660,21 +514,6 @@ async def aget_evidence(
660514
if summary_llm_model is None:
661515
summary_llm_model = evidence_settings.get_summary_llm()
662516

663-
if exclude_text_filter is not None:
664-
text_name = Text.__name__
665-
warnings.warn(
666-
(
667-
"The 'exclude_text_filter' argument did not work as intended"
668-
f" due to a mix-up in excluding {text_name}.name vs {text_name}."
669-
f" This bug enabled us to have 2+ contexts per {text_name}, so to"
670-
" first-class that capability and simplify our implementation,"
671-
" we're removing the 'exclude_text_filter' argument."
672-
" This deprecation will conclude in version 6"
673-
),
674-
category=DeprecationWarning,
675-
stacklevel=2,
676-
)
677-
678517
if answer_config.evidence_retrieval:
679518
matches = await self.retrieve_texts(
680519
session.question,
@@ -735,35 +574,6 @@ async def aget_evidence(
735574
session.contexts += [c for c, _ in results if c is not None and c.score > 0]
736575
return session
737576

738-
def query(
739-
self,
740-
query: PQASession | str,
741-
settings: MaybeSettings = None,
742-
callbacks: Sequence[Callable] | None = None,
743-
llm_model: LLMModel | None = None,
744-
summary_llm_model: LLMModel | None = None,
745-
embedding_model: EmbeddingModel | None = None,
746-
partitioning_fn: Callable[[Embeddable], int] | None = None,
747-
) -> PQASession:
748-
warnings.warn(
749-
"The synchronous `query` method is being deprecated in favor of the"
750-
" asynchronous `aquery` method, this deprecation will conclude in"
751-
" version 6.",
752-
category=DeprecationWarning,
753-
stacklevel=2,
754-
)
755-
return get_loop().run_until_complete(
756-
self.aquery(
757-
query,
758-
settings=settings,
759-
callbacks=callbacks,
760-
llm_model=llm_model,
761-
summary_llm_model=summary_llm_model,
762-
embedding_model=embedding_model,
763-
partitioning_fn=partitioning_fn,
764-
)
765-
)
766-
767577
async def aquery(
768578
self,
769579
query: PQASession | str,

0 commit comments

Comments
 (0)