langtrace-python-sdk 3.4.0__py3-none-any.whl → 3.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langtrace_python_sdk/constants/instrumentation/common.py +1 -1
- langtrace_python_sdk/constants/instrumentation/vertexai.py +20 -0
- langtrace_python_sdk/instrumentation/vertexai/patch.py +36 -6
- langtrace_python_sdk/utils/llm.py +30 -13
- langtrace_python_sdk/version.py +1 -1
- {langtrace_python_sdk-3.4.0.dist-info → langtrace_python_sdk-3.5.1.dist-info}/METADATA +2 -2
- {langtrace_python_sdk-3.4.0.dist-info → langtrace_python_sdk-3.5.1.dist-info}/RECORD +10 -10
- {langtrace_python_sdk-3.4.0.dist-info → langtrace_python_sdk-3.5.1.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-3.4.0.dist-info → langtrace_python_sdk-3.5.1.dist-info}/entry_points.txt +0 -0
- {langtrace_python_sdk-3.4.0.dist-info → langtrace_python_sdk-3.5.1.dist-info}/licenses/LICENSE +0 -0
@@ -39,4 +39,24 @@ APIS = {
|
|
39
39
|
"method": "ChatSession",
|
40
40
|
"operation": "send_message_streaming",
|
41
41
|
},
|
42
|
+
"PREDICTION_SERVICE_BETA_GENERATE_CONTENT": {
|
43
|
+
"module": "google.cloud.aiplatform_v1beta1.services.prediction_service.client",
|
44
|
+
"method": "PredictionServiceClient",
|
45
|
+
"operation": "generate_content",
|
46
|
+
},
|
47
|
+
"PREDICTION_SERVICE_GENERATE_CONTENT": {
|
48
|
+
"module": "google.cloud.aiplatform_v1.services.prediction_service.client",
|
49
|
+
"method": "PredictionServiceClient",
|
50
|
+
"operation": "generate_content",
|
51
|
+
},
|
52
|
+
"PREDICTION_SERVICE_BETA_STREAM_GENERATE_CONTENT": {
|
53
|
+
"module": "google.cloud.aiplatform_v1beta1.services.prediction_service.client",
|
54
|
+
"method": "PredictionServiceClient",
|
55
|
+
"operation": "stream_generate_content",
|
56
|
+
},
|
57
|
+
"PREDICTION_SERVICE_STREAM_GENERATE_CONTENT": {
|
58
|
+
"module": "google.cloud.aiplatform_v1.services.prediction_service.client",
|
59
|
+
"method": "PredictionServiceClient",
|
60
|
+
"operation": "stream_generate_content",
|
61
|
+
},
|
42
62
|
}
|
@@ -27,12 +27,13 @@ def patch_vertexai(name, version, tracer: Tracer):
|
|
27
27
|
def traced_method(wrapped, instance, args, kwargs):
|
28
28
|
service_provider = SERVICE_PROVIDERS["VERTEXAI"]
|
29
29
|
prompts = serialize_prompts(args, kwargs)
|
30
|
+
|
30
31
|
span_attributes = {
|
31
32
|
**get_langtrace_attributes(version, service_provider),
|
32
33
|
**get_llm_request_attributes(
|
33
34
|
kwargs,
|
34
35
|
prompts=prompts,
|
35
|
-
model=get_llm_model(instance),
|
36
|
+
model=get_llm_model(instance, kwargs),
|
36
37
|
),
|
37
38
|
**get_llm_url(instance),
|
38
39
|
SpanAttributes.LLM_PATH: "",
|
@@ -77,6 +78,10 @@ def set_response_attributes(span: Span, result):
|
|
77
78
|
if hasattr(result, "text"):
|
78
79
|
set_event_completion(span, [{"role": "assistant", "content": result.text}])
|
79
80
|
|
81
|
+
if hasattr(result, "candidates"):
|
82
|
+
parts = result.candidates[0].content.parts
|
83
|
+
set_event_completion(span, [{"role": "assistant", "content": parts[0].text}])
|
84
|
+
|
80
85
|
if hasattr(result, "usage_metadata") and result.usage_metadata is not None:
|
81
86
|
usage = result.usage_metadata
|
82
87
|
input_tokens = usage.prompt_token_count
|
@@ -96,17 +101,23 @@ def set_response_attributes(span: Span, result):
|
|
96
101
|
|
97
102
|
|
98
103
|
def is_streaming_response(response):
|
99
|
-
return
|
100
|
-
response, types.
|
104
|
+
return (
|
105
|
+
isinstance(response, types.GeneratorType)
|
106
|
+
or isinstance(response, types.AsyncGeneratorType)
|
107
|
+
or str(type(response).__name__) == "_StreamingResponseIterator"
|
101
108
|
)
|
102
109
|
|
103
110
|
|
104
|
-
def get_llm_model(instance):
|
111
|
+
def get_llm_model(instance, kwargs):
|
112
|
+
if "request" in kwargs:
|
113
|
+
return kwargs.get("request").model.split("/")[-1]
|
114
|
+
|
105
115
|
if hasattr(instance, "_model_name"):
|
106
116
|
return instance._model_name.replace("publishers/google/models/", "")
|
107
117
|
return getattr(instance, "_model_id", "unknown")
|
108
118
|
|
109
119
|
|
120
|
+
@silently_fail
|
110
121
|
def serialize_prompts(args, kwargs):
|
111
122
|
if args and len(args) > 0:
|
112
123
|
prompt_parts = []
|
@@ -122,5 +133,24 @@ def serialize_prompts(args, kwargs):
|
|
122
133
|
|
123
134
|
return [{"role": "user", "content": "\n".join(prompt_parts)}]
|
124
135
|
else:
|
125
|
-
|
126
|
-
|
136
|
+
# Handle PredictionServiceClient for google-cloud-aiplatform.
|
137
|
+
if "request" in kwargs:
|
138
|
+
prompt = []
|
139
|
+
prompt_body = kwargs.get("request")
|
140
|
+
if prompt_body.system_instruction:
|
141
|
+
for part in prompt_body.system_instruction.parts:
|
142
|
+
prompt.append({"role": "system", "content": part.text})
|
143
|
+
|
144
|
+
contents = prompt_body.contents
|
145
|
+
|
146
|
+
if not contents:
|
147
|
+
return []
|
148
|
+
|
149
|
+
for c in contents:
|
150
|
+
role = c.role if c.role else "user"
|
151
|
+
content = c.parts[0].text if c.parts else ""
|
152
|
+
prompt.append({"role": role, "content": content})
|
153
|
+
return prompt
|
154
|
+
else:
|
155
|
+
content = kwargs.get("prompt") or kwargs.get("message")
|
156
|
+
return [{"role": "user", "content": content}] if content else []
|
@@ -395,18 +395,30 @@ class StreamWrapper:
|
|
395
395
|
content = [chunk.text]
|
396
396
|
|
397
397
|
# CohereV2
|
398
|
-
if (
|
399
|
-
chunk
|
400
|
-
|
401
|
-
chunk.delta
|
402
|
-
|
403
|
-
chunk.delta.message
|
404
|
-
|
405
|
-
chunk.delta.message.content
|
398
|
+
if (
|
399
|
+
hasattr(chunk, "delta")
|
400
|
+
and chunk.delta is not None
|
401
|
+
and hasattr(chunk.delta, "message")
|
402
|
+
and chunk.delta.message is not None
|
403
|
+
and hasattr(chunk.delta.message, "content")
|
404
|
+
and chunk.delta.message.content is not None
|
405
|
+
and hasattr(chunk.delta.message.content, "text")
|
406
|
+
and chunk.delta.message.content.text is not None
|
407
|
+
):
|
406
408
|
content = [chunk.delta.message.content.text]
|
407
|
-
|
409
|
+
# google-cloud-aiplatform
|
410
|
+
if hasattr(chunk, "candidates") and chunk.candidates is not None:
|
411
|
+
for candidate in chunk.candidates:
|
412
|
+
if hasattr(candidate, "content") and candidate.content is not None:
|
413
|
+
for part in candidate.content.parts:
|
414
|
+
if hasattr(part, "text") and part.text is not None:
|
415
|
+
content.append(part.text)
|
408
416
|
# Anthropic
|
409
|
-
if
|
417
|
+
if (
|
418
|
+
hasattr(chunk, "delta")
|
419
|
+
and chunk.delta is not None
|
420
|
+
and not hasattr(chunk.delta, "message")
|
421
|
+
):
|
410
422
|
content = [chunk.delta.text] if hasattr(chunk.delta, "text") else []
|
411
423
|
|
412
424
|
if isinstance(chunk, dict):
|
@@ -425,9 +437,14 @@ class StreamWrapper:
|
|
425
437
|
|
426
438
|
# CohereV2
|
427
439
|
if hasattr(chunk, "type") and chunk.type == "message-end":
|
428
|
-
if (
|
429
|
-
hasattr(chunk
|
430
|
-
|
440
|
+
if (
|
441
|
+
hasattr(chunk, "delta")
|
442
|
+
and chunk.delta is not None
|
443
|
+
and hasattr(chunk.delta, "usage")
|
444
|
+
and chunk.delta.usage is not None
|
445
|
+
and hasattr(chunk.delta.usage, "billed_units")
|
446
|
+
and chunk.delta.usage.billed_units is not None
|
447
|
+
):
|
431
448
|
usage = chunk.delta.usage.billed_units
|
432
449
|
self.completion_tokens = int(usage.output_tokens)
|
433
450
|
self.prompt_tokens = int(usage.input_tokens)
|
langtrace_python_sdk/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "3.
|
1
|
+
__version__ = "3.5.1"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: langtrace-python-sdk
|
3
|
-
Version: 3.
|
3
|
+
Version: 3.5.1
|
4
4
|
Summary: Python SDK for LangTrace
|
5
5
|
Project-URL: Homepage, https://github.com/Scale3-Labs/langtrace-python-sdk
|
6
6
|
Author-email: Scale3 Labs <engineering@scale3labs.com>
|
@@ -23,7 +23,7 @@ Requires-Dist: sentry-sdk>=2.14.0
|
|
23
23
|
Requires-Dist: setuptools
|
24
24
|
Requires-Dist: sqlalchemy
|
25
25
|
Requires-Dist: tiktoken>=0.1.1
|
26
|
-
Requires-Dist: trace-attributes==7.1.
|
26
|
+
Requires-Dist: trace-attributes==7.1.2
|
27
27
|
Requires-Dist: transformers>=4.11.3
|
28
28
|
Requires-Dist: ujson>=5.10.0
|
29
29
|
Provides-Extra: dev
|
@@ -111,7 +111,7 @@ examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56sn
|
|
111
111
|
examples/weaviate_example/query_text.py,sha256=wPHQTc_58kPoKTZMygVjTj-2ZcdrIuaausJfMxNQnQc,127162
|
112
112
|
langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
|
113
113
|
langtrace_python_sdk/langtrace.py,sha256=ekJbkRnmJ2VHv0nrfqK8NiRvYI2ZA7YHK7r12_TiQCU,13425
|
114
|
-
langtrace_python_sdk/version.py,sha256=
|
114
|
+
langtrace_python_sdk/version.py,sha256=q84OxOhhZQRg9QLCpRzm8ZW7aGHtGUAnNgVlGvZ9vBg,22
|
115
115
|
langtrace_python_sdk/constants/__init__.py,sha256=3CNYkWMdd1DrkGqzLUgNZXjdAlM6UFMlf_F-odAToyc,146
|
116
116
|
langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=EVCrouYCpY98f0KSaKr4PzNxPULTZZO6dSA_crEOyJU,106
|
117
117
|
langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -119,7 +119,7 @@ langtrace_python_sdk/constants/instrumentation/anthropic.py,sha256=YX3llt3zwDY6X
|
|
119
119
|
langtrace_python_sdk/constants/instrumentation/aws_bedrock.py,sha256=QwKtO4NBarOZoGkt5cFCcpxAw3zvZxcMMWBbzPPGv-g,422
|
120
120
|
langtrace_python_sdk/constants/instrumentation/chroma.py,sha256=hiPGYdHS0Yj4Kh3eaYBbuCAl_swqIygu80yFqkOgdak,955
|
121
121
|
langtrace_python_sdk/constants/instrumentation/cohere.py,sha256=9yD133VdrYZ5BoJR4nJHlj67gHEImB9-KsD-NkzHW1I,1159
|
122
|
-
langtrace_python_sdk/constants/instrumentation/common.py,sha256=
|
122
|
+
langtrace_python_sdk/constants/instrumentation/common.py,sha256=CLL1YNXvmCSuYDCZUMUcs_plomCPcBqjITBt2uiN0RE,1224
|
123
123
|
langtrace_python_sdk/constants/instrumentation/embedchain.py,sha256=HodCJvaFjILoOG50OwFObxfVxt_8VUaIAIqvgoN3tzo,278
|
124
124
|
langtrace_python_sdk/constants/instrumentation/gemini.py,sha256=UAmfgg9FM7uNeOCdPfWlir6OIH-8BoxFGPRpdBd9ZZs,358
|
125
125
|
langtrace_python_sdk/constants/instrumentation/groq.py,sha256=VFXmIl4aqGY_fS0PAmjPj_Qm7Tibxbx7Ur_e7rQpqXc,134
|
@@ -131,7 +131,7 @@ langtrace_python_sdk/constants/instrumentation/openai.py,sha256=uEOH5UXapU2DSf2A
|
|
131
131
|
langtrace_python_sdk/constants/instrumentation/pinecone.py,sha256=0TityERbGWaHGSN8-vyYZtYCjVj8fQOKae8lng0O0Bk,478
|
132
132
|
langtrace_python_sdk/constants/instrumentation/pymongo.py,sha256=bZR3anvH2OjQCj6ZCLMmdJcWcmlHhEGezS_3sx9RyJ8,195
|
133
133
|
langtrace_python_sdk/constants/instrumentation/qdrant.py,sha256=yL7BopNQTXW7L7Z-gVM2PdusKD7r9qqcATvczFd7NtQ,1999
|
134
|
-
langtrace_python_sdk/constants/instrumentation/vertexai.py,sha256=
|
134
|
+
langtrace_python_sdk/constants/instrumentation/vertexai.py,sha256=S1Ewx4KAn5lb9pdeI8tbjKH6p0wFIBF_xhq_YRWjiF4,2198
|
135
135
|
langtrace_python_sdk/constants/instrumentation/weaviate.py,sha256=gtv-JBxvNGClEMxClmRKzjJ1khgOonsli4D_k9IagSE,2601
|
136
136
|
langtrace_python_sdk/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
137
137
|
langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=ckd8dMmY6h2oxE04p1JFLwUB5PSJX_Cy4eDFEM6aj4Y,6605
|
@@ -222,14 +222,14 @@ langtrace_python_sdk/instrumentation/qdrant/instrumentation.py,sha256=vl2eKSP55a
|
|
222
222
|
langtrace_python_sdk/instrumentation/qdrant/patch.py,sha256=IgdozFyKqB8n72BjKvBDiMhYM4o75DReD0I8_uIQ7KY,5015
|
223
223
|
langtrace_python_sdk/instrumentation/vertexai/__init__.py,sha256=ZzKxB7bl0FaRlgJhhgAk5V8Bf20FmThWM_Z9u9Eyy1s,92
|
224
224
|
langtrace_python_sdk/instrumentation/vertexai/instrumentation.py,sha256=yz4trw0BqGbNUvlagsejk_j8pDvRHxxQFtYJVarNKqY,1393
|
225
|
-
langtrace_python_sdk/instrumentation/vertexai/patch.py,sha256=
|
225
|
+
langtrace_python_sdk/instrumentation/vertexai/patch.py,sha256=PzBio8x6zdVpX286TKtaTR-sf1HCHQ7RrdvpyNaGk4Q,5571
|
226
226
|
langtrace_python_sdk/instrumentation/weaviate/__init__.py,sha256=Mc-Je6evPo-kKQzerTG7bd1XO5JOh4YGTE3wBxaUBwg,99
|
227
227
|
langtrace_python_sdk/instrumentation/weaviate/instrumentation.py,sha256=Kwq5QQTUQNRHrWrMnNe9X0TcqtXGiNpBidsuToRTqG0,2417
|
228
228
|
langtrace_python_sdk/instrumentation/weaviate/patch.py,sha256=Lqixz32uAvDA2VLU3zXLiJ9ohpKeD_LveahX7uro3ZY,6934
|
229
229
|
langtrace_python_sdk/types/__init__.py,sha256=2VykM6fNHRlkOaIEUCdK3VyaaVgk2rTIr9jMmCVj2Ag,4676
|
230
230
|
langtrace_python_sdk/utils/__init__.py,sha256=VVDOG-QLd59ZvSHp0avjof0sbxlZ1QQOf0KoOF7ofhQ,3310
|
231
231
|
langtrace_python_sdk/utils/langtrace_sampler.py,sha256=BupNndHbU9IL_wGleKetz8FdcveqHMBVz1bfKTTW80w,1753
|
232
|
-
langtrace_python_sdk/utils/llm.py,sha256=
|
232
|
+
langtrace_python_sdk/utils/llm.py,sha256=693egq-ztVLmlwdZ9KkTTzMpg_k397ErA28XFL00_ws,16733
|
233
233
|
langtrace_python_sdk/utils/misc.py,sha256=LaQr5LOmZMiuwVdjYh7aIu6o2C_Xb1wgpQGNOVmRzfE,1918
|
234
234
|
langtrace_python_sdk/utils/prompt_registry.py,sha256=n5dQMVLBw8aJZY8Utvf67bncc25ELf6AH9BYw8_hSzo,2619
|
235
235
|
langtrace_python_sdk/utils/sdk_version_checker.py,sha256=F-VVVH7Fmhr5LcY0IIe-34zIi5RQcx26uuxFpPzZesM,1782
|
@@ -280,8 +280,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
|
|
280
280
|
tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
|
281
281
|
tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
|
282
282
|
tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
|
283
|
-
langtrace_python_sdk-3.
|
284
|
-
langtrace_python_sdk-3.
|
285
|
-
langtrace_python_sdk-3.
|
286
|
-
langtrace_python_sdk-3.
|
287
|
-
langtrace_python_sdk-3.
|
283
|
+
langtrace_python_sdk-3.5.1.dist-info/METADATA,sha256=lFJxH9nTj_ZqszPLjEM-W8thp65GoqiYJd_FKpzAJ_4,15643
|
284
|
+
langtrace_python_sdk-3.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
285
|
+
langtrace_python_sdk-3.5.1.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
|
286
|
+
langtrace_python_sdk-3.5.1.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
287
|
+
langtrace_python_sdk-3.5.1.dist-info/RECORD,,
|
File without changes
|
{langtrace_python_sdk-3.4.0.dist-info → langtrace_python_sdk-3.5.1.dist-info}/entry_points.txt
RENAMED
File without changes
|
{langtrace_python_sdk-3.4.0.dist-info → langtrace_python_sdk-3.5.1.dist-info}/licenses/LICENSE
RENAMED
File without changes
|