Skip to content

Commit

Permalink
Merge pull request #458 from parea-ai/fix-target-dumping
Browse files Browse the repository at this point in the history
fix: make using target safe
  • Loading branch information
joschkabraun authored Feb 14, 2024
2 parents 9857d4f + db8c4b4 commit fbb7979
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
2 changes: 2 additions & 0 deletions parea/parea_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def default_log(self, data: TraceLog) -> None:
if self._redis_cache:
self.write_log(data)
if self._client:
if data.target:
data.target = json_dumps(data.target)
self.record_log(data)

def record_vendor_log(self, data: dict[str, Any], vendor: TraceIntegrations) -> None:
Expand Down
15 changes: 1 addition & 14 deletions parea/utils/trace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,14 @@ def wrapper(*args, **kwargs):

def call_eval_funcs_then_log(trace_id: str, eval_funcs: list[Callable] = None):
data = trace_data.get()[trace_id]
data_evals = data
if data.target is not None and not isinstance(data.target, str):
data_evals = deepcopy(data)
target = data.target
try:
target = json.dumps(target)
except TypeError:
try:
target = json_dumps(target)
except TypeError:
# if we can't serialize the value, just convert it to a string
target = str(target)
data.target = target
parea_logger.default_log(data=data)

if eval_funcs and data.status == "success" and random() <= data.apply_eval_frac:
thread_ids_running_evals.get().append(trace_id)
scores = []
for func in eval_funcs:
try:
scores.append(NamedEvaluationScore(name=func.__name__, score=func(data_evals)))
scores.append(NamedEvaluationScore(name=func.__name__, score=func(data)))
except Exception as e:
logger.exception(f"Error occurred calling evaluation function '{func.__name__}', {e}", exc_info=e)
parea_logger.update_log(data=UpdateLog(trace_id=trace_id, field_name_to_value_map={"scores": scores}))
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.70"
version = "0.2.71"
description = "Parea python sdk"
readme = "README.md"
authors = ["joel-parea-ai <[email protected]>"]
Expand Down

0 comments on commit fbb7979

Please sign in to comment.