Skip to content

Fixes cache issue from 703 and 679 #707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 20, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ def yes_or_no_filter(context, response):
cache_seed = extra_kwargs.get("cache_seed", 41)
filter_func = extra_kwargs.get("filter_func")
context = extra_kwargs.get("context")
with diskcache.Cache(f"{self.cache_path_root}/{cache_seed}") as cache:
if cache_seed is not None:

# Try to load the response from cache
if cache_seed is not None:
with diskcache.Cache(f"{self.cache_path_root}/{cache_seed}") as cache:
# Try to get the response from cache
key = get_key(params)
response = cache.get(key, None)
Expand All @@ -240,17 +242,18 @@ def yes_or_no_filter(context, response):
response.pass_filter = pass_filter
# TODO: add response.cost
return response
try:
response = self._completions_create(client, params)
except APIError:
logger.debug(f"config {i} failed", exc_info=1)
if i == last:
raise
else:
if cache_seed is not None:
# Cache the response
try:
response = self._completions_create(client, params)
except APIError:
logger.debug(f"config {i} failed", exc_info=1)
if i == last:
raise
else:
if cache_seed is not None:
# Cache the response
with diskcache.Cache(f"{self.cache_path_root}/{cache_seed}") as cache:
cache.set(key, response)
return response
return response

def _completions_create(self, client, params):
completions = client.chat.completions if "messages" in params else client.completions
Expand Down