Skip to content

Commit 71f7c85

Browse files
Release 3.8.18 (#535)
* capture different types of google genai inputs (#534) Co-authored-by: Obinna Okafor <[email protected]> * add boto3 version * add boto3 version --------- Co-authored-by: Obinna Okafor <[email protected]>
1 parent 093c784 commit 71f7c85

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
"transformers>=4.11.3",
3333
"sentry-sdk>=2.14.0",
3434
"ujson>=5.10.0",
35-
"boto3",
35+
"boto3==1.38.0",
3636
"setuptools",
3737
]
3838

src/langtrace_python_sdk/instrumentation/google_genai/patch.py

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
from langtrace_python_sdk.utils.llm import (
23
get_langtrace_attributes,
34
get_llm_request_attributes,
@@ -14,20 +15,65 @@
1415

1516
from typing import Iterator
1617

18+
def capture_input_data(contents):
19+
input_data = []
20+
21+
if isinstance(contents, list):
22+
content_parts = []
23+
for content in contents:
24+
if hasattr(content, 'parts'):
25+
for part in content.parts:
26+
if hasattr(part, 'text') and part.text:
27+
content_parts.append({
28+
"type": "text",
29+
"text": part.text
30+
})
31+
if hasattr(part, 'inline_data') and part.inline_data:
32+
content_parts.append({
33+
"type": "image_url",
34+
"image_url": f"data:{part.inline_data.mime_type};base64,{base64.b64encode(part.inline_data.data).decode('utf-8')}"
35+
})
36+
else:
37+
if isinstance(content, str):
38+
content_parts.append({
39+
"type": "text",
40+
"text": content
41+
})
42+
elif hasattr(content, 'text') and content.text:
43+
content_parts.append({
44+
"type": "text",
45+
"text": content.text
46+
})
47+
elif hasattr(content, 'inline_data') and content.inline_data:
48+
content_parts.append({
49+
"type": "image_url",
50+
"image_url": f"data:{content.inline_data.mime_type};base64,{base64.b64encode(content.inline_data.data).decode('utf-8')}"
51+
})
52+
else:
53+
content_parts.append({
54+
"type": "text",
55+
"text": content
56+
})
57+
input_data.append({
58+
"role": "user",
59+
"content": content_parts
60+
})
61+
else:
62+
input_data.append({
63+
"role": "user",
64+
"content": contents
65+
})
66+
67+
return input_data
68+
1769

1870
def patch_google_genai(tracer: Tracer, version: str):
1971
def traced_method(wrapped, instance, args, kwargs):
20-
prompt = [
21-
{
22-
"role": "user",
23-
"content": kwargs["contents"],
24-
}
25-
]
2672
span_attributes = {
2773
**get_langtrace_attributes(
2874
service_provider="google_genai", version=version
2975
),
30-
**get_llm_request_attributes(kwargs=kwargs, prompts=prompt),
76+
**get_llm_request_attributes(kwargs=kwargs, prompts=capture_input_data(kwargs["contents"])),
3177
}
3278
with tracer.start_as_current_span(
3379
name="google.genai.generate_content",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.8.17"
1+
__version__ = "3.8.18"

0 commit comments

Comments
 (0)