Skip to content
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

fix(weave): fixed a bug where Evaluation.predict_and_score tried accessing __name__ #3071

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions tests/trace/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ async def infer(self, input) -> str:
assert result == expected_eval_result


def test_evaluate_model_with__call__(client):
class EvalModel(Model):
@weave.op()
async def infer(self, input) -> str:
return eval(input)

def __call__(self, *args, **kwargs):
return self.infer(*args, **kwargs)

evaluation = Evaluation(
dataset=dataset_rows,
scorers=[score],
)
result = asyncio.run(evaluation.evaluate(EvalModel()))
assert result == expected_eval_result


def test_score_as_class(client):
class MyScorer(weave.Scorer):
@weave.op()
Expand Down
6 changes: 5 additions & 1 deletion weave/flow/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import traceback
from collections.abc import Coroutine
from inspect import isfunction
from typing import Any, Callable, Literal, Optional, Union, cast

from pydantic import PrivateAttr
Expand Down Expand Up @@ -165,9 +166,12 @@ async def predict_and_score(

model_self = None
model_predict: Union[Callable, Model]
if callable(model):
if callable(model) and isfunction(model):
model_predict = model
else:
if not isinstance(model, Model):
raise ValueError(INVALID_MODEL_ERROR)

model_self = model
model_predict = get_infer_method(model)

Expand Down
Loading