|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | +from uuid import uuid4 |
| 5 | + |
| 6 | +from lance_context import Context |
| 7 | + |
| 8 | + |
| 9 | +def main() -> None: |
| 10 | + project_root = Path(__file__).resolve().parent.parent.parent |
| 11 | + artifacts_dir = project_root / ".artifacts" |
| 12 | + artifacts_dir.mkdir(exist_ok=True) |
| 13 | + |
| 14 | + dataset_path = artifacts_dir / f"travel_context_{uuid4().hex}.lance" |
| 15 | + ctx = Context.create(dataset_path.as_posix()) |
| 16 | + print(f"Created context store at {dataset_path}") |
| 17 | + |
| 18 | + ctx.add("system", "You are a friendly travel agent who compares destinations.") |
| 19 | + ctx.add("user", "Where should I travel in spring if I love street food?") |
| 20 | + ctx.add( |
| 21 | + "assistant", |
| 22 | + "Consider Osaka, Japan for cherry blossoms and the Kuromon market.", |
| 23 | + ) |
| 24 | + |
| 25 | + first_version = ctx.version() |
| 26 | + |
| 27 | + ctx.add("user", "Any budget-friendly option in Europe?") |
| 28 | + ctx.add( |
| 29 | + "assistant", |
| 30 | + "Porto, Portugal offers great food, coastal views, and reasonable prices.", |
| 31 | + ) |
| 32 | + |
| 33 | + print(f"Entries stored: {ctx.entries()}") |
| 34 | + print(f"Current version: {ctx.version()}") |
| 35 | + |
| 36 | + ctx.checkout(first_version) |
| 37 | + print(f"Rolled back to version {first_version}; entries now {ctx.entries()}") |
| 38 | + |
| 39 | + print( |
| 40 | + "Re-run this script to create a fresh dataset, or reuse the printed path to " |
| 41 | + "append more entries from another process." |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +if __name__ == "__main__": # pragma: no cover - manual invocation |
| 46 | + main() |
0 commit comments