Skip to content

Commit

Permalink
First Object Test
Browse files Browse the repository at this point in the history
  • Loading branch information
tssweeney committed Jan 4, 2025
1 parent 08b2384 commit 0b6b723
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions tests/trace/test_call_apply_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@


def do_assertions_for_scorer_op(
apply_score_res: ApplyScorerResult, call: Call, score_fn: Op, client: WeaveClient
apply_score_res: ApplyScorerResult,
call: Call,
score_fn: Op | weave.Scorer,
client: WeaveClient,
):
assert apply_score_res.feedback_id is not None
assert apply_score_res.call_id is not None
Expand All @@ -17,7 +20,10 @@ def do_assertions_for_scorer_op(
assert len(feedbacks) == 1
target_feedback = feedbacks[0]
assert target_feedback.id == apply_score_res.feedback_id
assert target_feedback.feedback_type == "wandb.runnable.score_fn"
scorer_name = (
score_fn.name if isinstance(score_fn, Op) else score_fn.__class__.__name__
)
assert target_feedback.feedback_type == "wandb.runnable." + scorer_name
assert target_feedback.runnable_ref == score_fn.ref.uri()
assert (
target_feedback.call_ref
Expand Down Expand Up @@ -96,7 +102,32 @@ async def score_fn_with_incorrect_args(y, output):


def test_scorer_obj_no_context(client: WeaveClient):
raise NotImplementedError()
@weave.op
def predict(x):
return x + 1

class MyScorer(weave.Scorer):
offset: int

@weave.op
def score(self, x, output):
return output - x - self.offset

scorer = MyScorer(offset=1)

_, call = predict.call(1)
apply_score_res = call.apply_scorer(scorer)
do_assertions_for_scorer_op(apply_score_res, call, scorer, client)

class MyScorerWithIncorrectArgs(weave.Scorer):
offset: int

@weave.op
def score(self, y, output):
return output - y - self.offset

with pytest.raises(OpCallError):
apply_score_res = call.apply_scorer(MyScorerWithIncorrectArgs(offset=1))


def test_scorer_obj_with_context(client: WeaveClient):
Expand Down

0 comments on commit 0b6b723

Please sign in to comment.