|
47 | 47 | from .._execution_context import ExecutionSpanCollector |
48 | 48 | from ..evaluators.base_evaluator import GenericBaseEvaluator |
49 | 49 | from ..evaluators.output_evaluator import OutputEvaluationCriteria |
| 50 | +from ..helpers import get_agent_model |
50 | 51 | from ..mocks._cache_manager import CacheManager |
51 | 52 | from ..mocks._input_mocker import ( |
52 | 53 | generate_llm_input, |
53 | 54 | ) |
54 | 55 | from ..mocks._mock_context import cache_manager_context |
55 | 56 | from ..mocks._mock_runtime import UiPathMockRuntime |
56 | | -from ..mocks._types import MockingContext |
| 57 | +from ..mocks._types import LLMMockingStrategy, MockingContext, ModelSettings |
57 | 58 | from ..models import EvaluationResult |
58 | 59 | from ..models.evaluation_set import ( |
59 | 60 | EvaluationItem, |
@@ -526,12 +527,25 @@ async def _execute_eval( |
526 | 527 | eval_item=eval_item, |
527 | 528 | ), |
528 | 529 | ) |
| 530 | + # Set agent model on the mocking strategy if not already set |
| 531 | + mocking_strategy = eval_item.mocking_strategy |
| 532 | + if ( |
| 533 | + mocking_strategy |
| 534 | + and isinstance(mocking_strategy, LLMMockingStrategy) |
| 535 | + and not mocking_strategy.model |
| 536 | + ): |
| 537 | + mocking_model = get_agent_model(self.context.runtime_schema) |
| 538 | + if mocking_model: |
| 539 | + mocking_strategy = mocking_strategy.model_copy( |
| 540 | + update={"model": ModelSettings(model=mocking_model)} |
| 541 | + ) |
| 542 | + |
529 | 543 | agent_execution_output = await self.execute_runtime( |
530 | 544 | eval_item, |
531 | 545 | execution_id, |
532 | 546 | input_overrides=self.context.input_overrides, |
533 | 547 | mocking_context=MockingContext( |
534 | | - strategy=eval_item.mocking_strategy, |
| 548 | + strategy=mocking_strategy, |
535 | 549 | name=eval_item.name, |
536 | 550 | inputs=eval_item.inputs, |
537 | 551 | ), |
@@ -811,8 +825,18 @@ async def _generate_input_for_eval( |
811 | 825 | or getattr(eval_item, "expected_output", None) |
812 | 826 | or {} |
813 | 827 | ) |
| 828 | + # Set agent model on the input mocking strategy if not already set |
| 829 | + input_strategy = eval_item.input_mocking_strategy |
| 830 | + # If input strategy does not specify a model, extract it |
| 831 | + if input_strategy and not input_strategy.model: |
| 832 | + input_generation_model = get_agent_model(self.context.runtime_schema) |
| 833 | + if input_generation_model: |
| 834 | + input_strategy = input_strategy.model_copy( |
| 835 | + update={"model": ModelSettings(model=input_generation_model)} |
| 836 | + ) |
| 837 | + |
814 | 838 | generated_input = await generate_llm_input( |
815 | | - eval_item.input_mocking_strategy, |
| 839 | + input_strategy, |
816 | 840 | (await self.get_schema()).input, |
817 | 841 | expected_behavior=eval_item.expected_agent_behavior or "", |
818 | 842 | expected_output=expected_output, |
|
0 commit comments