-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add model settings id parameter #1053
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
Open
mathurk
wants to merge
3
commits into
main
Choose a base branch
from
feat/model_settings_id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−2
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import json | ||
| import logging | ||
| import os | ||
| import tempfile | ||
| import uuid | ||
| from collections import defaultdict | ||
| from contextlib import contextmanager | ||
|
|
@@ -44,12 +46,14 @@ | |
| from ...eval.evaluators import BaseEvaluator | ||
| from ...eval.models import EvaluationResult | ||
| from ...eval.models.models import AgentExecution, EvalItemResult | ||
| from .._utils._console import ConsoleLogger | ||
| from .._utils._eval_set import EvalHelpers | ||
| from .._utils._parallelization import execute_parallel | ||
| from ._evaluator_factory import EvaluatorFactory | ||
| from ._models._evaluation_set import ( | ||
| EvaluationItem, | ||
| EvaluationSet, | ||
| LegacyEvaluationSet, | ||
| ) | ||
| from ._models._exceptions import EvaluationRuntimeException | ||
| from ._models._output import ( | ||
|
|
@@ -67,6 +71,7 @@ | |
| set_execution_context, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| class ExecutionSpanExporter(SpanExporter): | ||
| """Custom exporter that stores spans grouped by execution ids.""" | ||
|
|
@@ -153,6 +158,7 @@ class UiPathEvalContext: | |
| verbose: bool = False | ||
| enable_mocker_cache: bool = False | ||
| report_coverage: bool = False | ||
| model_settings_id: str = "default" | ||
|
|
||
|
|
||
| class UiPathEvalRuntime: | ||
|
|
@@ -513,11 +519,97 @@ def _get_and_clear_execution_data( | |
|
|
||
| return spans, logs | ||
|
|
||
| async def _apply_model_settings_override(self) -> str | None: | ||
| """Apply model settings override if specified. | ||
|
|
||
| Returns: | ||
| Modified entrypoint path if settings were overridden, otherwise None | ||
| """ | ||
| console = ConsoleLogger() | ||
| console.info(f"Checking model settings override with ID: '{self.context.model_settings_id}'") | ||
|
|
||
| # Skip if no model settings ID specified | ||
| if not self.context.model_settings_id or self.context.model_settings_id == "default": | ||
| return None | ||
|
|
||
| # Load evaluation set to get model settings | ||
| evaluation_set, _ = EvalHelpers.load_eval_set(self.context.eval_set or "") | ||
| if not hasattr(evaluation_set, 'model_settings') or not evaluation_set.model_settings: | ||
| console.warning("No model settings available in evaluation set") | ||
| return None | ||
|
|
||
| # Find the specified model settings | ||
| target_model_settings = next( | ||
| (ms for ms in evaluation_set.model_settings if ms.id == self.context.model_settings_id), | ||
| None | ||
| ) | ||
|
|
||
| if not target_model_settings: | ||
| logger.warning(f"Model settings ID '{self.context.model_settings_id}' not found in evaluation set") | ||
| return None | ||
|
|
||
| console.info(f"Found model settings: model='{target_model_settings.model_name}', temperature='{target_model_settings.temperature}'") | ||
|
|
||
| # Early exit: if both values are "same-as-agent", no override needed | ||
| if (target_model_settings.model_name == "same-as-agent" and | ||
| target_model_settings.temperature == "same-as-agent"): | ||
| console.info("Both model and temperature are 'same-as-agent', no override needed") | ||
| return None | ||
|
|
||
| # Load the original entrypoint file | ||
| entrypoint_path = Path(self.context.entrypoint or "agent.json") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't leak |
||
| if not entrypoint_path.exists(): | ||
| console.warning(f"Entrypoint file '{entrypoint_path}' not found, model settings override not applicable") | ||
| return None | ||
|
|
||
| with open(entrypoint_path, 'r') as f: | ||
| agent_data = json.load(f) | ||
|
|
||
| # Apply model settings overrides | ||
| settings = agent_data.get("settings", {}) | ||
| original_model = settings.get("model", "") | ||
| original_temperature = settings.get("temperature", 0.0) | ||
|
|
||
| console.info(f"Original agent settings: model='{original_model}', temperature={original_temperature}") | ||
|
|
||
| # Override model if not "same-as-agent" | ||
| if target_model_settings.model_name != "same-as-agent": | ||
| settings["model"] = target_model_settings.model_name | ||
|
|
||
| # Override temperature if not "same-as-agent" | ||
| if target_model_settings.temperature != "same-as-agent": | ||
| try: | ||
| settings["temperature"] = float(target_model_settings.temperature) | ||
| except ValueError: | ||
| logger.warning(f"Invalid temperature value: '{target_model_settings.temperature}', keeping original") | ||
|
|
||
| agent_data["settings"] = settings | ||
|
|
||
| # Create a temporary file with the modified agent definition | ||
| temp_fd, temp_path = tempfile.mkstemp(suffix=".json", prefix="agent_override_") | ||
| try: | ||
| with os.fdopen(temp_fd, 'w') as temp_file: | ||
| json.dump(agent_data, temp_file, indent=2) | ||
|
|
||
| console.info(f"Applied model settings override: model='{settings.get('model', '')}', temperature={settings.get('temperature', 0.0)}") | ||
| return temp_path | ||
| except Exception as e: | ||
| logger.error(f"Failed to create temporary agent file: {e}") | ||
| try: | ||
| os.unlink(temp_path) | ||
| except: | ||
| pass | ||
| return None | ||
|
|
||
| async def execute_runtime( | ||
| self, eval_item: EvaluationItem, execution_id: str | ||
| ) -> UiPathEvalRunExecutionOutput: | ||
| # Apply model settings override if needed | ||
| overridden_entrypoint = await self._apply_model_settings_override() | ||
| entrypoint_to_use = overridden_entrypoint or self.context.entrypoint | ||
|
|
||
| runtime = await self.factory.new_runtime( | ||
| entrypoint=self.context.entrypoint or "", | ||
| entrypoint=entrypoint_to_use or "", | ||
| runtime_id=execution_id, | ||
| ) | ||
| log_handler = self._setup_execution_logging(execution_id) | ||
|
|
@@ -551,6 +643,12 @@ async def execute_runtime( | |
|
|
||
| finally: | ||
| await runtime.dispose() | ||
| # Clean up temporary file if it was created | ||
| if overridden_entrypoint and overridden_entrypoint != (self.context.entrypoint or ""): | ||
| try: | ||
| os.unlink(overridden_entrypoint) | ||
| except Exception as e: | ||
| logger.warning(f"Failed to clean up temporary agent file: {e}") | ||
|
|
||
| end_time = time() | ||
| spans, logs = self._get_and_clear_execution_data(execution_id) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use logger, console is a CLI concept (imagine we extract the evals engine to another library)