Skip to content

Commit

Permalink
fix: add context manager cache for clearing util
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashankar committed Oct 2, 2024
1 parent b344e3a commit 26104b4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docetl/operations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
cache = Cache(LLM_CACHE_DIR)
cache.close()


def freezeargs(func):
"""
Decorator to convert mutable dictionary arguments into immutable.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -455,6 +457,7 @@ def target():

return decorator


def call_llm_with_cache(
model: str,
op_type: str,
Expand Down

0 comments on commit 26104b4

Please sign in to comment.