Evaluation.predict_and_score:v0
Version
0
Last updated
Last updated by
Calls:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import weave
from typing import Union
from weave.trace.op import Op
from weave.flow.model import Model
from weave.flow.model import apply_model_async
from weave.flow.model import ApplyModelError
from weave.scorers.base_scorer import get_scorer_attributes
@weave.op()
async def predict_and_score(self, model: Union[Op, Model], example: dict) -> dict:
apply_model_result = await apply_model_async(
model, example, self.preprocess_model_input
)
if isinstance(apply_model_result, ApplyModelError):
return {
self._output_key: None,
"scores": {},
"model_latency": apply_model_result.model_latency,
}
model_output = apply_model_result.model_output
model_call = apply_model_result.model_call
model_latency = apply_model_result.model_latency