Skip to content

Commit

Permalink
feat: Add support for searching Python modules in cache CLI
Browse files Browse the repository at this point in the history
This commit adds the ability to specify a comma-separated list of directories to search for Python modules in the cache command line interface (CLI). The `--search-dirs` option allows users to provide custom directories to search for modules so that unpickling from Diskcache works
  • Loading branch information
provos committed Sep 24, 2024
1 parent 717fbb4 commit bf3b719
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/planai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@

import argparse
import sys
from typing import List

from planai import llm_from_config

from .cli_cache import handle_cache_subcommand
from .cli_optimize_prompt import optimize_prompt


def parse_comma_separated_list(arg: str) -> List[str]:
# Split the argument by commas and strip any extra whitespace
return [item.strip() for item in arg.split(",")]


def create_parser():
parser = argparse.ArgumentParser(description="planai command line interface")

Expand Down Expand Up @@ -114,6 +120,12 @@ def create_parser():
"--delete", type=str, help="Delete a specific cache key", default=None
)
cache_parser.add_argument("--clear", action="store_true", help="Clear the cache")
cache_parser.add_argument(
"--search-dirs",
type=parse_comma_separated_list,
help="Comma-separated list of directories to search for Python modules",
default=None,
)

return parser

Expand Down
4 changes: 4 additions & 0 deletions src/planai/cli_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

def handle_cache_subcommand(parsed_args):
cache = Cache(parsed_args.cache_dir)
if parsed_args.search_dirs:
for search_dir in parsed_args.search_dirs:
sys.path.append(search_dir)

if parsed_args.clear:
cache.clear()
print("Cache cleared successfully.")
Expand Down

0 comments on commit bf3b719

Please sign in to comment.