Skip to content

Commit 66ed1de

Browse files
committed
move nested util
1 parent 302c2a4 commit 66ed1de

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@
3838
)
3939

4040

41+
# Use parameter signature from
42+
# https://github.com/googleapis/python-aiplatform/blob/v1.76.0/vertexai/generative_models/_generative_models.py#L595
43+
# to handle named vs positional args robustly
44+
def _extract_params(
45+
contents: ContentsType,
46+
*,
47+
generation_config: Optional[GenerationConfigType] = None,
48+
safety_settings: Optional[SafetySettingsType] = None,
49+
tools: Optional[list[Tool]] = None,
50+
tool_config: Optional[ToolConfig] = None,
51+
labels: Optional[dict[str, str]] = None,
52+
stream: bool = False,
53+
**_kwargs: Any,
54+
) -> GenerateContentParams:
55+
return GenerateContentParams(
56+
contents=contents,
57+
generation_config=generation_config,
58+
safety_settings=safety_settings,
59+
tools=tools,
60+
tool_config=tool_config,
61+
labels=labels,
62+
stream=stream,
63+
)
64+
65+
4166
def generate_content_create(
4267
tracer: Tracer, event_logger: EventLogger, capture_content: bool
4368
):
@@ -51,32 +76,7 @@ def traced_method(
5176
args: Any,
5277
kwargs: Any,
5378
):
54-
# Use parameter signature from
55-
# https://github.com/googleapis/python-aiplatform/blob/v1.76.0/vertexai/generative_models/_generative_models.py#L595
56-
# to handle named vs positional args robustly
57-
def extract_params(
58-
contents: ContentsType,
59-
*,
60-
generation_config: Optional[GenerationConfigType] = None,
61-
safety_settings: Optional[SafetySettingsType] = None,
62-
tools: Optional[list[Tool]] = None,
63-
tool_config: Optional[ToolConfig] = None,
64-
labels: Optional[dict[str, str]] = None,
65-
stream: bool = False,
66-
**_kwargs: Any,
67-
) -> GenerateContentParams:
68-
return GenerateContentParams(
69-
contents=contents,
70-
generation_config=generation_config,
71-
safety_settings=safety_settings,
72-
tools=tools,
73-
tool_config=tool_config,
74-
labels=labels,
75-
stream=stream,
76-
)
77-
78-
params = extract_params(*args, **kwargs)
79-
79+
params = _extract_params(*args, **kwargs)
8080
span_attributes = get_genai_request_attributes(instance, params)
8181

8282
span_name = get_span_name(span_attributes)

instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/cassettes/test_vertexai_generate_content_error.yaml

+1-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ interactions:
3939
"code": 400,
4040
"message": "Unable to submit request because it has a temperature value of 1000 but the supported range is from 0 (inclusive) to 2.0001 (exclusive). Update the value and try again.",
4141
"status": "INVALID_ARGUMENT",
42-
"details": [
43-
{
44-
"@type": "type.googleapis.com/google.rpc.DebugInfo",
45-
"detail": "[ORIGINAL ERROR] generic::invalid_argument: Unable to submit request because it has a temperature value of 1000 but the supported range is from 0 (inclusive) to 2.0001 (exclusive). Update the value and try again. [google.rpc.error_details_ext] { message: \"Unable to submit request because it has a temperature value of 1000 but the supported range is from 0 (inclusive) to 2.0001 (exclusive). Update the value and try again.\" }"
46-
}
47-
]
42+
"details": []
4843
}
4944
}
5045
headers:

0 commit comments

Comments
 (0)