Skip to content

Commit 97266eb

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
fix: resolve SessionInput state serialization to cloud evaluation service
PiperOrigin-RevId: 924891381
1 parent d024de2 commit 97266eb

1 file changed

Lines changed: 103 additions & 2 deletions

File tree

vertexai/_genai/evals.py

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,95 @@ def _EvaluationRunConfig_to_vertex(
449449
return to_object
450450

451451

452+
def _SessionInput_to_vertex(
453+
from_object: Union[dict[str, Any], object],
454+
parent_object: Optional[dict[str, Any]] = None,
455+
) -> dict[str, Any]:
456+
to_object: dict[str, Any] = {}
457+
if getv(from_object, ["user_id"]) is not None:
458+
setv(to_object, ["userId"], getv(from_object, ["user_id"]))
459+
460+
if getv(from_object, ["state"]) is not None:
461+
setv(to_object, ["sessionState"], getv(from_object, ["state"]))
462+
463+
parameters = {}
464+
if getv(from_object, ["app_name"]) is not None:
465+
parameters["app_name"] = getv(from_object, ["app_name"])
466+
467+
if parameters:
468+
setv(to_object, ["parameters"], parameters)
469+
470+
return to_object
471+
472+
473+
def _SessionInput_from_vertex(
474+
from_object: Union[dict[str, Any], object],
475+
parent_object: Optional[dict[str, Any]] = None,
476+
) -> dict[str, Any]:
477+
to_object: dict[str, Any] = {}
478+
if getv(from_object, ["userId"]) is not None:
479+
setv(to_object, ["user_id"], getv(from_object, ["userId"]))
480+
481+
if getv(from_object, ["sessionState"]) is not None:
482+
setv(to_object, ["state"], getv(from_object, ["sessionState"]))
483+
484+
parameters = getv(from_object, ["parameters"])
485+
if parameters and "app_name" in parameters:
486+
setv(to_object, ["app_name"], parameters["app_name"])
487+
488+
return to_object
489+
490+
491+
def _AgentRunConfig_to_vertex(
492+
from_object: Union[dict[str, Any], object],
493+
parent_object: Optional[dict[str, Any]] = None,
494+
) -> dict[str, Any]:
495+
to_object: dict[str, Any] = {}
496+
if getv(from_object, ["session_input"]) is not None:
497+
setv(
498+
to_object,
499+
["sessionInput"],
500+
_SessionInput_to_vertex(getv(from_object, ["session_input"]), to_object),
501+
)
502+
503+
if getv(from_object, ["agent_engine"]) is not None:
504+
setv(to_object, ["agentEngine"], getv(from_object, ["agent_engine"]))
505+
506+
if getv(from_object, ["user_simulator_config"]) is not None:
507+
setv(
508+
to_object,
509+
["userSimulatorConfig"],
510+
getv(from_object, ["user_simulator_config"]),
511+
)
512+
513+
return to_object
514+
515+
516+
def _AgentRunConfig_from_vertex(
517+
from_object: Union[dict[str, Any], object],
518+
parent_object: Optional[dict[str, Any]] = None,
519+
) -> dict[str, Any]:
520+
to_object: dict[str, Any] = {}
521+
if getv(from_object, ["sessionInput"]) is not None:
522+
setv(
523+
to_object,
524+
["session_input"],
525+
_SessionInput_from_vertex(getv(from_object, ["sessionInput"]), to_object),
526+
)
527+
528+
if getv(from_object, ["agentEngine"]) is not None:
529+
setv(to_object, ["agent_engine"], getv(from_object, ["agentEngine"]))
530+
531+
if getv(from_object, ["userSimulatorConfig"]) is not None:
532+
setv(
533+
to_object,
534+
["user_simulator_config"],
535+
getv(from_object, ["userSimulatorConfig"]),
536+
)
537+
538+
return to_object
539+
540+
452541
def _EvaluationRunInferenceConfig_from_vertex(
453542
from_object: Union[dict[str, Any], object],
454543
parent_object: Optional[dict[str, Any]] = None,
@@ -464,7 +553,13 @@ def _EvaluationRunInferenceConfig_from_vertex(
464553
setv(to_object, ["prompt_template"], getv(from_object, ["promptTemplate"]))
465554

466555
if getv(from_object, ["agentRunConfig"]) is not None:
467-
setv(to_object, ["agent_run_config"], getv(from_object, ["agentRunConfig"]))
556+
setv(
557+
to_object,
558+
["agent_run_config"],
559+
_AgentRunConfig_from_vertex(
560+
getv(from_object, ["agentRunConfig"]), to_object
561+
),
562+
)
468563

469564
if getv(from_object, ["agents"]) is not None:
470565
setv(to_object, ["agent_configs"], getv(from_object, ["agents"]))
@@ -487,7 +582,13 @@ def _EvaluationRunInferenceConfig_to_vertex(
487582
setv(to_object, ["promptTemplate"], getv(from_object, ["prompt_template"]))
488583

489584
if getv(from_object, ["agent_run_config"]) is not None:
490-
setv(to_object, ["agentRunConfig"], getv(from_object, ["agent_run_config"]))
585+
setv(
586+
to_object,
587+
["agentRunConfig"],
588+
_AgentRunConfig_to_vertex(
589+
getv(from_object, ["agent_run_config"]), to_object
590+
),
591+
)
491592

492593
if getv(from_object, ["agent_configs"]) is not None:
493594
setv(to_object, ["agents"], getv(from_object, ["agent_configs"]))

0 commit comments

Comments
 (0)