Skip to content

Commit

Permalink
Fix file reading and saving errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Oosterop committed Nov 21, 2023
1 parent 642b461 commit 7340275
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
<!-- insertion marker -->
## [Unreleased]

## [0.8.1]

### Fixed
- Error with reading and saving files.

## [0.8.0]

### Added
Expand Down
12 changes: 8 additions & 4 deletions src/crewcal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def convert(json: str, ical: str, overwrite: bool) -> int:
)
json_path = json_path_modified

sched = schedule.Schedule.from_json(json_path)
sched.to_icalendar_file(ical_path)
sched = schedule.Schedule.from_json(str(json_path))
sched.to_icalendar_file(str(ical_path))

return 0

Expand Down Expand Up @@ -125,9 +125,13 @@ def extract(sourcefile: str, targetfile: str, to_json: bool, overwrite: bool) ->
text="Extracting schedule, saving to crewcal json format.", spinner="dots"
):
sched = (
OpenAISchedule(schedule_path=source_path, to_icalendar_file=out_path)
OpenAISchedule(
schedule_path=str(source_path), to_icalendar_file=str(out_path)
)
if not to_json
else OpenAISchedule(schedule_path=source_path, to_json_file=out_path)
else OpenAISchedule(
schedule_path=str(source_path), to_json_file=str(out_path)
)
)

click.echo(f"Extracted schedule saved to {out_path}.")
Expand Down
16 changes: 8 additions & 8 deletions src/crewcal/llm_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def __init__(
- sched = OpenAISchedule("schedule.pdf", to_icalendar_file="schedule.ics") - to extract data from a PDF file and save it to a JSON file
Parameters:
schedule_path (Path): The path to the schedule PDF file.
to_json_file (Path, optional): The path to the file where the schedule will be extracted.
to_icalendar_file (Path, optional): The path to the file where the iCalendar representation of the schedule will be saved.
schedule_path (str): The path to the schedule PDF file.
to_json_file (str, optional): The path to the file where the schedule will be extracted.
to_icalendar_file (str, optional): The path to the file where the iCalendar representation of the schedule will be saved.
Returns:
None
Expand All @@ -77,7 +77,7 @@ def extract(self, to_file: str = "") -> None:
"""Uses LLM to extract event data from a schedule PDF file and optionally saves it to a JSON file.
Parameters:
to_file (Path, optional): The path to the output JSON file. If not provided, the extracted data will not be saved.
to_file (str, optional): The path to the output JSON file. If not provided, the extracted data will not be saved.
Returns:
None
Expand Down Expand Up @@ -105,7 +105,7 @@ def extract(self, to_file: str = "") -> None:
| JsonKeyOutputFunctionsParser(key_name="events")
)

logging.WARNING(
logging.warning(
"WARNING - This script costs 0.75 US cents per call in OpenAI API costs."
)

Expand All @@ -118,13 +118,13 @@ def read_schedule_pdf(self, filepath: str = "") -> str:
"""Reads the contents of a schedule PDF file and returns as a document for an LLM input.
Args:
filepath (pathlib.Path): The path to the PDF file.
filepath (str): The path to the PDF file.
Returns:
str: The concatenated text of all pages in the PDF file.
"""
if filepath:
loader = PyPDFLoader(filepath)
loader = PyPDFLoader(str(filepath))
documents = loader.load()
full_sched_doc = "".join([doc.page_content for doc in documents])
else:
Expand Down Expand Up @@ -156,7 +156,7 @@ def from_json(filepath: str) -> "OpenAISchedule":
"""Initializes a new OpenAISchedule object from a JSON file.
Args:
filepath (Path): The path to the JSON file.
filepath (str): The path to the JSON file.
Returns:
OpenAISchedule: The initialized OpenAISchedule object.
Expand Down

0 comments on commit 7340275

Please sign in to comment.