Skip to content

Commit 166c081

Browse files
committed
feature: add blobpart and filepart to message handling
1 parent 2eefc39 commit 166c081

File tree

2 files changed

+29
-0
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai
  • util/opentelemetry-util-genai/src/opentelemetry/util/genai

2 files changed

+29
-0
lines changed

instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/message.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
from google.genai import types as genai_types
2121
from opentelemetry.util.genai.types import (
22+
BlobPart,
23+
FileDataPart,
2224
FinishReason,
2325
InputMessage,
2426
MessagePart,
@@ -95,6 +97,16 @@ def tool_call_id(name: str | None) -> str:
9597
if (text := part.text) is not None:
9698
return Text(content=text)
9799

100+
if data := part.inline_data:
101+
return BlobPart(
102+
mime_type=data.mime_type or "", data=data.data or b""
103+
)
104+
105+
if data := part.file_data:
106+
return FileDataPart(
107+
mime_type=data.mime_type or "", uri=data.file_uri or ""
108+
)
109+
98110
if call := part.function_call:
99111
return ToolCall(
100112
id=call.id or tool_call_id(call.name),

util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ class Text:
5555
type: Literal["text"] = "text"
5656

5757

58+
@dataclass
59+
class BlobPart:
60+
data: bytes
61+
mime_type: str
62+
type: Literal["blob"] = "blob"
63+
64+
65+
@dataclass
66+
class FileDataPart:
67+
mime_type: str
68+
uri: str
69+
type: Literal["file_data"] = "file_data"
70+
71+
class Config:
72+
extra = "allow"
73+
74+
5875
MessagePart = Union[Text, ToolCall, ToolCallResponse, Any]
5976

6077

0 commit comments

Comments
 (0)