Skip to content

Commit

Permalink
Merge pull request #168 from parea-ai/PAI-346-fix-bug-https-github-co…
Browse files Browse the repository at this point in the history
…m-parea-ai-parea-sdk-py-issues-166

fix: exception swallowed
  • Loading branch information
joschkabraun committed Oct 20, 2023
2 parents 568186e + a8724e2 commit c1137c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
14 changes: 7 additions & 7 deletions parea/utils/trace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ def call_eval_funcs_then_log(trace_id: str, eval_funcs: list[Callable] = None, a
try:
inputs = data.inputs
target = data.target
if access_output_of_func:
output = json.loads(data.output)
output = access_output_of_func(output)
output_for_eval_metrics = json.dumps(output)
else:
output_for_eval_metrics = data.output
data.output_for_eval_metrics = output_for_eval_metrics
if eval_funcs and data.status == "success":
if access_output_of_func:
output = json.loads(data.output)
output = access_output_of_func(output)
output_for_eval_metrics = json.dumps(output)
else:
output_for_eval_metrics = data.output
data.output_for_eval_metrics = output_for_eval_metrics
data.scores = []
for func in eval_funcs:
try:
Expand Down
18 changes: 14 additions & 4 deletions parea/wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def async_decorator(self, orig_func: Callable) -> Callable:
async def wrapper(*args, **kwargs):
trace_id, start_time = self._init_trace()
response = None
exception = None
error = None
cache_hit = False
cache_key = self.convert_kwargs_to_cache_request(args, kwargs)
Expand All @@ -106,12 +107,16 @@ async def wrapper(*args, **kwargs):
if response is None:
response = await orig_func(*args, **kwargs)
except Exception as e:
exception = e
error = str(e)
if self.cache:
await self.cache.ainvalidate(cache_key)
raise
finally:
return await self._acleanup_trace(trace_id, start_time, error, cache_hit, args, kwargs, response)
if exception is not None:
self._cleanup_trace(trace_id, start_time, error, cache_hit, args, kwargs, response)
raise exception
else:
return self._cleanup_trace(trace_id, start_time, error, cache_hit, args, kwargs, response)

return wrapper

Expand All @@ -123,6 +128,7 @@ def wrapper(*args, **kwargs):
error = None
cache_hit = False
cache_key = self.convert_kwargs_to_cache_request(args, kwargs)
exception = None
try:
if self.cache:
cache_result = self.cache.get(cache_key)
Expand All @@ -132,12 +138,16 @@ def wrapper(*args, **kwargs):
if response is None:
response = orig_func(*args, **kwargs)
except Exception as e:
exception = e
error = str(e)
if self.cache:
self.cache.invalidate(cache_key)
raise e
finally:
return self._cleanup_trace(trace_id, start_time, error, cache_hit, args, kwargs, response)
if exception is not None:
self._cleanup_trace(trace_id, start_time, error, cache_hit, args, kwargs, response)
raise exception
else:
return self._cleanup_trace(trace_id, start_time, error, cache_hit, args, kwargs, response)

return wrapper

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "parea-ai"
packages = [{ include = "parea" }]
version = "0.2.13"
version = "0.2.14"
description = "Parea python sdk"
readme = "README.md"
authors = ["joel-parea-ai <[email protected]>"]
Expand Down

0 comments on commit c1137c2

Please sign in to comment.