diff --git a/docetl/operations/utils.py b/docetl/operations/utils.py index e7fbd917..d3b5e3da 100644 --- a/docetl/operations/utils.py +++ b/docetl/operations/utils.py @@ -35,6 +35,7 @@ cache = Cache(LLM_CACHE_DIR) cache.close() + def freezeargs(func): """ Decorator to convert mutable dictionary arguments into immutable. @@ -135,8 +136,8 @@ def clear_cache(console: Console = Console()): """ console.log("[bold yellow]Clearing LLM cache...[/bold yellow]") try: - cache.clear() - cache.close() + with cache as c: + c.clear() # Remove all files in the cache directory cache_dir = CACHE_DIR if not os.path.exists(cache_dir): @@ -413,6 +414,7 @@ def call_llm( # TODO: HITL return {} + class InvalidOutputError(Exception): """ Custom exception raised when the LLM output is invalid or cannot be parsed. @@ -455,6 +457,7 @@ def target(): return decorator + def call_llm_with_cache( model: str, op_type: str,