diff --git a/vertexai/_genai/evals.py b/vertexai/_genai/evals.py index 33fff12b49..64bdea61a0 100644 --- a/vertexai/_genai/evals.py +++ b/vertexai/_genai/evals.py @@ -449,6 +449,95 @@ def _EvaluationRunConfig_to_vertex( return to_object +def _SessionInput_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["user_id"]) is not None: + setv(to_object, ["userId"], getv(from_object, ["user_id"])) + + if getv(from_object, ["state"]) is not None: + setv(to_object, ["sessionState"], getv(from_object, ["state"])) + + parameters = {} + if getv(from_object, ["app_name"]) is not None: + parameters["app_name"] = getv(from_object, ["app_name"]) + + if parameters: + setv(to_object, ["parameters"], parameters) + + return to_object + + +def _SessionInput_from_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["userId"]) is not None: + setv(to_object, ["user_id"], getv(from_object, ["userId"])) + + if getv(from_object, ["sessionState"]) is not None: + setv(to_object, ["state"], getv(from_object, ["sessionState"])) + + parameters = getv(from_object, ["parameters"]) + if parameters and "app_name" in parameters: + setv(to_object, ["app_name"], parameters["app_name"]) + + return to_object + + +def _AgentRunConfig_to_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["session_input"]) is not None: + setv( + to_object, + ["sessionInput"], + _SessionInput_to_vertex(getv(from_object, ["session_input"]), to_object), + ) + + if getv(from_object, ["agent_engine"]) is not None: + setv(to_object, ["agentEngine"], getv(from_object, ["agent_engine"])) + + if getv(from_object, ["user_simulator_config"]) is not None: + setv( + to_object, + ["userSimulatorConfig"], + getv(from_object, ["user_simulator_config"]), + ) + + return to_object + + +def _AgentRunConfig_from_vertex( + from_object: Union[dict[str, Any], object], + parent_object: Optional[dict[str, Any]] = None, +) -> dict[str, Any]: + to_object: dict[str, Any] = {} + if getv(from_object, ["sessionInput"]) is not None: + setv( + to_object, + ["session_input"], + _SessionInput_from_vertex(getv(from_object, ["sessionInput"]), to_object), + ) + + if getv(from_object, ["agentEngine"]) is not None: + setv(to_object, ["agent_engine"], getv(from_object, ["agentEngine"])) + + if getv(from_object, ["userSimulatorConfig"]) is not None: + setv( + to_object, + ["user_simulator_config"], + getv(from_object, ["userSimulatorConfig"]), + ) + + return to_object + + def _EvaluationRunInferenceConfig_from_vertex( from_object: Union[dict[str, Any], object], parent_object: Optional[dict[str, Any]] = None, @@ -464,7 +553,13 @@ def _EvaluationRunInferenceConfig_from_vertex( setv(to_object, ["prompt_template"], getv(from_object, ["promptTemplate"])) if getv(from_object, ["agentRunConfig"]) is not None: - setv(to_object, ["agent_run_config"], getv(from_object, ["agentRunConfig"])) + setv( + to_object, + ["agent_run_config"], + _AgentRunConfig_from_vertex( + getv(from_object, ["agentRunConfig"]), to_object + ), + ) if getv(from_object, ["agents"]) is not None: setv(to_object, ["agent_configs"], getv(from_object, ["agents"])) @@ -487,7 +582,13 @@ def _EvaluationRunInferenceConfig_to_vertex( setv(to_object, ["promptTemplate"], getv(from_object, ["prompt_template"])) if getv(from_object, ["agent_run_config"]) is not None: - setv(to_object, ["agentRunConfig"], getv(from_object, ["agent_run_config"])) + setv( + to_object, + ["agentRunConfig"], + _AgentRunConfig_to_vertex( + getv(from_object, ["agent_run_config"]), to_object + ), + ) if getv(from_object, ["agent_configs"]) is not None: setv(to_object, ["agents"], getv(from_object, ["agent_configs"]))