Various improvements
This commit is contained in:
parent
b7d95f26ec
commit
442ae98463
3 changed files with 100 additions and 3 deletions
|
|
@ -37,6 +37,8 @@ class BookingConfig:
|
|||
booking_type: str
|
||||
yaml_filename: str
|
||||
spec_heading: str
|
||||
start_field: str
|
||||
excluded_top_level_keys: tuple[str, ...]
|
||||
json_key: str = "booking"
|
||||
|
||||
|
||||
|
|
@ -45,11 +47,22 @@ BOOKING_CONFIGS: dict[str, BookingConfig] = {
|
|||
booking_type="flight",
|
||||
yaml_filename="flights.yaml",
|
||||
spec_heading="flights.yaml",
|
||||
start_field="depart",
|
||||
excluded_top_level_keys=("trip",),
|
||||
),
|
||||
"train": BookingConfig(
|
||||
booking_type="train",
|
||||
yaml_filename="trains.yaml",
|
||||
spec_heading="trains.yaml",
|
||||
start_field="depart",
|
||||
excluded_top_level_keys=("trip",),
|
||||
),
|
||||
"accommodation": BookingConfig(
|
||||
booking_type="accommodation",
|
||||
yaml_filename="accommodation.yaml",
|
||||
spec_heading="accommodation.yaml",
|
||||
start_field="from",
|
||||
excluded_top_level_keys=("trip", "latitude", "longitude"),
|
||||
),
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +122,7 @@ def build_prompt(
|
|||
bookings = current_bookings
|
||||
if bookings is None:
|
||||
bookings = read_existing_bookings(config)
|
||||
excluded_keys = ", ".join(f'"{key}"' for key in config.excluded_top_level_keys)
|
||||
|
||||
return f"""
|
||||
I keep a record of all my {config.booking_type} bookings in a YAML file.
|
||||
|
|
@ -131,7 +145,7 @@ Rules:
|
|||
- Wrap the response in a JSON object with a single key "{config.json_key}" that
|
||||
contains the booking in YAML.
|
||||
- The value of "{config.json_key}" must be YAML text, not JSON.
|
||||
- Exclude the top-level "trip" key from the YAML.
|
||||
- Exclude these top-level keys from the YAML: {excluded_keys}.
|
||||
- Do not invent details that are not present in the booking text.
|
||||
- Quote prices and identifiers that might otherwise be parsed as numbers.
|
||||
|
||||
|
|
@ -218,7 +232,7 @@ def first_departure(booking: dict[str, typing.Any], config: BookingConfig) -> da
|
|||
assert isinstance(first_flight, dict)
|
||||
return datetime_from_yaml_value(first_flight["depart"])
|
||||
|
||||
return datetime_from_yaml_value(booking["depart"])
|
||||
return datetime_from_yaml_value(booking[config.start_field])
|
||||
|
||||
|
||||
def comparable_departure(
|
||||
|
|
@ -246,6 +260,13 @@ def trip_key_position(booking: dict[str, typing.Any], config: BookingConfig) ->
|
|||
return keys.index("booking_reference") + 1
|
||||
return 0
|
||||
|
||||
if config.booking_type == "accommodation":
|
||||
if "country" in booking:
|
||||
return keys.index("country") + 1
|
||||
if "location" in booking:
|
||||
return keys.index("location") + 1
|
||||
return 0
|
||||
|
||||
if "to" in booking:
|
||||
return keys.index("to") + 1
|
||||
if "from" in booking:
|
||||
|
|
@ -455,3 +476,8 @@ def train_main(argv: list[str] | None = None) -> int:
|
|||
def flight_main(argv: list[str] | None = None) -> int:
|
||||
"""CLI entrypoint for flight booking YAML generation."""
|
||||
return main_for_type("flight", argv)
|
||||
|
||||
|
||||
def accommodation_main(argv: list[str] | None = None) -> int:
|
||||
"""CLI entrypoint for accommodation booking YAML generation."""
|
||||
return main_for_type("accommodation", argv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue