Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing parse_text to be given a str path #491

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion paperqa/readers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from math import ceil
from pathlib import Path
from typing import Literal, overload
Expand Down Expand Up @@ -85,7 +86,10 @@ def chunk_pdf(


def parse_text(
path: Path, html: bool = False, split_lines: bool = False, use_tiktoken: bool = True
path: str | os.PathLike,
html: bool = False,
split_lines: bool = False,
use_tiktoken: bool = True,
) -> ParsedText:
"""Simple text splitter, can optionally use tiktoken, parse html, or split into newlines.

Expand All @@ -95,6 +99,7 @@ def parse_text(
split_lines: flag to split lines into a list.
use_tiktoken: flag to use tiktoken library to encode text.
"""
path = Path(path)
try:
with path.open() as f:
text = list(f) if split_lines else f.read()
Expand Down
Loading