Skip to content

Commit d9754da

Browse files
committed
WIP vertex tool calls
1 parent 06b2e79 commit d9754da

File tree

2 files changed

+20
-3
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai

2 files changed

+20
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from __future__ import annotations
2424

2525
from dataclasses import asdict, dataclass
26-
from typing import Literal
26+
from typing import Literal, Sequence
2727

2828
from opentelemetry._events import Event
2929
from opentelemetry.semconv._incubating.attributes import gen_ai_attributes
@@ -104,18 +104,31 @@ class ChoiceMessage:
104104
role: str = "assistant"
105105

106106

107+
@dataclass
108+
class ChoiceToolCall:
109+
"""The tool_calls field for a gen_ai.choice event"""
110+
111+
@dataclass
112+
class Function:
113+
name: str
114+
arguments: AnyValue = None
115+
116+
function: Function
117+
id: str
118+
type: Literal["function"]
119+
120+
107121
FinishReason = Literal[
108122
"content_filter", "error", "length", "stop", "tool_calls"
109123
]
110124

111125

112-
# TODO add tool calls
113-
# https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3216
114126
def choice_event(
115127
*,
116128
finish_reason: FinishReason | str,
117129
index: int,
118130
message: ChoiceMessage,
131+
tool_calls: Sequence[ChoiceToolCall] | None = None,
119132
) -> Event:
120133
"""Creates a choice event, which describes the Gen AI response message.
121134
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#event-gen_aichoice
@@ -125,6 +138,8 @@ def choice_event(
125138
"index": index,
126139
"message": asdict(message),
127140
}
141+
if tool_calls:
142+
body["tool_calls"] = [asdict(tool_call) for tool_call in tool_calls]
128143

129144
return Event(
130145
name="gen_ai.choice",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ def response_to_events(
242242
parts=candidate.content.parts,
243243
),
244244
),
245+
# TODO: tool calls
246+
tool_calls=None,
245247
)
246248

247249

0 commit comments

Comments
 (0)