Skip to content

Commit

Permalink
Only use the thread-safe lock
Browse files Browse the repository at this point in the history
  • Loading branch information
ankrgyl committed Nov 3, 2023
1 parent 3d80143 commit c47d88f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions py/autoevals/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ def run_cached_request(Completion=None, **kwargs):
return resp


ACACHE_LOCK = asyncio.Lock()


@traced(name="OpenAI Completion")
async def arun_cached_request(Completion=None, **kwargs):
# OpenAI is very slow to import, so we only do it if we need it
Expand All @@ -103,7 +100,7 @@ async def arun_cached_request(Completion=None, **kwargs):

param_key = json.dumps(kwargs)
conn = open_cache()
with ACACHE_LOCK:
with CACHE_LOCK:
cursor = conn.cursor()
resp = cursor.execute("""SELECT response FROM "cache" WHERE params=?""", [param_key]).fetchone()
cached = False
Expand All @@ -122,7 +119,7 @@ async def arun_cached_request(Completion=None, **kwargs):
await asyncio.sleep(sleep_time)
retries += 1

with ACACHE_LOCK:
with CACHE_LOCK:
cursor = conn.cursor()
cursor.execute("""INSERT INTO "cache" VALUES (?, ?)""", [param_key, json.dumps(resp)])
conn.commit()
Expand Down
2 changes: 1 addition & 1 deletion py/autoevals/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.0.26"
VERSION = "0.0.27"

0 comments on commit c47d88f

Please sign in to comment.