Skip to content

Commit c19209d

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: GenAI SDK client - fix of return type for _wait_for_completion and few mypy errors for PromptOptimizerVAPOConfigOrDict
PiperOrigin-RevId: 785528094
1 parent 079b1f9 commit c19209d

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

vertexai/_genai/_prompt_optimizer_utils.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,19 @@ def _get_service_account(
2121
config: types.PromptOptimizerVAPOConfigOrDict,
2222
) -> str:
2323
"""Get the service account from the config for the custom job."""
24-
if hasattr(config, "service_account") and config.service_account:
25-
if (
26-
hasattr(config, "service_account_project_number")
27-
and config.service_account_project_number
28-
):
29-
raise ValueError(
30-
"Only one of service_account or service_account_project_number "
31-
"can be provided."
32-
)
24+
if isinstance(config, dict):
25+
config = types.PromptOptimizerVAPOConfig.model_validate(config)
26+
27+
if config.service_account and config.service_account_project_number:
28+
raise ValueError(
29+
"Only one of service_account or "
30+
"service_account_project_number can be provided."
31+
)
32+
elif config.service_account:
3333
return config.service_account
34-
elif (
35-
hasattr(config, "service_account_project_number")
36-
and config.service_account_project_number
37-
):
34+
elif config.service_account_project_number:
3835
return f"{config.service_account_project_number}-compute@developer.gserviceaccount.com"
3936
else:
4037
raise ValueError(
41-
"Either service_account or service_account_project_number is required."
38+
"Either service_account or service_account_project_number " "is required."
4239
)

vertexai/_genai/prompt_optimizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def _get_custom_job(
540540

541541
"""Prompt Optimizer PO-Data."""
542542

543-
def _wait_for_completion(self, job_name: str) -> None:
543+
def _wait_for_completion(self, job_name: str) -> types.CustomJob:
544544

545545
JOB_COMPLETE_STATES = [
546546
types.JobState.JOB_STATE_SUCCEEDED,
@@ -914,6 +914,8 @@ async def optimize(
914914

915915
# Get the job id for the dashboard url and display to the user.
916916
job_resource_name = job.name
917+
if not job_resource_name:
918+
raise ValueError(f"Error creating job: {job}")
917919
job_id = job_resource_name.split("/")[-1]
918920
logger.info("Job created: %s", job.name)
919921

vertexai/_genai/types.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,10 @@ class HttpOptions(_common.BaseModel):
10811081
)
10821082
extra_body: Optional[dict[str, Any]] = Field(
10831083
default=None,
1084-
description="""Extra parameters to add to the request body.""",
1084+
description="""Extra parameters to add to the request body.
1085+
The structure must match the backend API's request structure.
1086+
- VertexAI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
1087+
- GeminiAPI backend API docs: https://ai.google.dev/api/rest""",
10851088
)
10861089
retry_options: Optional[HttpRetryOptions] = Field(
10871090
default=None, description="""HTTP retry options for the request."""
@@ -1110,7 +1113,10 @@ class HttpOptionsDict(TypedDict, total=False):
11101113
"""Args passed to the async HTTP client."""
11111114

11121115
extra_body: Optional[dict[str, Any]]
1113-
"""Extra parameters to add to the request body."""
1116+
"""Extra parameters to add to the request body.
1117+
The structure must match the backend API's request structure.
1118+
- VertexAI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
1119+
- GeminiAPI backend API docs: https://ai.google.dev/api/rest"""
11141120

11151121
retry_options: Optional[HttpRetryOptionsDict]
11161122
"""HTTP retry options for the request."""

0 commit comments

Comments
 (0)