langtrace-python-sdk 2.2.28__py3-none-any.whl → 2.2.30__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.
@@ -123,4 +123,4 @@ class LangTraceExporter(SpanExporter):
123
123
  return SpanExportResult.FAILURE
124
124
 
125
125
  def shutdown(self) -> None:
126
- pass
126
+ print(Fore.WHITE + "⭐ Leave our github a star to stay on top of our updates - https://github.com/Scale3-Labs/langtrace" + Fore.RESET)
@@ -23,6 +23,7 @@ from opentelemetry.trace.propagation import set_span_in_context
23
23
 
24
24
  from opentelemetry.trace import SpanKind
25
25
  from opentelemetry.trace.status import Status, StatusCode
26
+ from langtrace.trace_attributes import SpanAttributes
26
27
 
27
28
  from langtrace_python_sdk.constants.instrumentation.common import (
28
29
  LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY,
@@ -71,6 +72,16 @@ def generic_patch(
71
72
  if trace_output:
72
73
  span.set_attribute("langchain.outputs", to_json_string(result))
73
74
 
75
+ prompt_tokens = instance.get_num_tokens(args[0])
76
+ completion_tokens = instance.get_num_tokens(result)
77
+ if hasattr(result, 'usage'):
78
+ prompt_tokens = result.usage.prompt_tokens
79
+ completion_tokens = result.usage.completion_tokens
80
+
81
+ span.set_attribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, prompt_tokens)
82
+ span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, completion_tokens)
83
+
84
+
74
85
  span.set_status(StatusCode.OK)
75
86
  return result
76
87
  except Exception as err:
@@ -30,6 +30,7 @@ from langtrace_python_sdk.constants.instrumentation.common import (
30
30
  from importlib_metadata import version as v
31
31
 
32
32
  from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME
33
+ from langtrace.trace_attributes import SpanAttributes
33
34
 
34
35
 
35
36
  def generic_patch(
@@ -78,8 +79,22 @@ def generic_patch(
78
79
  try:
79
80
  # Attempt to call the original method
80
81
  result = wrapped(*args, **kwargs)
82
+
81
83
  if trace_output:
82
84
  span.set_attribute("langchain.outputs", to_json_string(result))
85
+ if hasattr(result, 'usage'):
86
+ prompt_tokens = result.usage.prompt_tokens
87
+ completion_tokens = result.usage.completion_tokens
88
+ span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, prompt_tokens)
89
+ span.set_attribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, completion_tokens)
90
+
91
+ elif result.generations[0][0].text:
92
+ span.set_attribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, instance.get_num_tokens(result.generations[0][0].text))
93
+ elif isinstance(args[0][0], str):
94
+ span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, instance.get_num_tokens(args[0][0]))
95
+
96
+ else:
97
+ span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, instance.get_num_tokens(args[0][0].text))
83
98
 
84
99
  span.set_status(StatusCode.OK)
85
100
  return result
@@ -156,6 +171,7 @@ def runnable_patch(
156
171
  try:
157
172
  # Attempt to call the original method
158
173
  result = wrapped(*args, **kwargs)
174
+
159
175
  if trace_output:
160
176
  outputs = {}
161
177
  if isinstance(result, dict):
@@ -44,7 +44,7 @@ from langtrace_python_sdk.utils.llm import (
44
44
  StreamWrapper,
45
45
  set_span_attributes,
46
46
  )
47
- from openai._types import NOT_GIVEN
47
+ from langtrace_python_sdk.types import NOT_GIVEN
48
48
 
49
49
 
50
50
  def images_generate(original_method, version, tracer):
@@ -83,6 +83,7 @@ def init(
83
83
  )
84
84
  check_if_sdk_is_outdated()
85
85
  print(Fore.GREEN + "Initializing Langtrace SDK.." + Fore.RESET)
86
+ print(Fore.WHITE + "⭐ Leave our github a star to stay on top of our updates - https://github.com/Scale3-Labs/langtrace" + Fore.RESET)
86
87
  sampler = LangtraceSampler(disabled_methods=disable_tracing_for_functions)
87
88
  resource = Resource.create(
88
89
  attributes={
@@ -1,4 +1,4 @@
1
- from typing import List, Literal, TypedDict
1
+ from typing import List, Literal, TypeVar, TypedDict, Union
2
2
  from enum import Enum
3
3
 
4
4
 
@@ -111,3 +111,32 @@ class InstrumentationMethods(TypedDict):
111
111
  anthropic: List[VendorMethods.AnthropicMethods]
112
112
  cohere: List[VendorMethods.CohereMethods]
113
113
  weaviate: List[str]
114
+
115
+ _T = TypeVar("_T")
116
+ class NotGiven:
117
+ """
118
+ A sentinel singleton class used to distinguish omitted keyword arguments
119
+ from those passed in with the value None (which may have different behavior).
120
+
121
+ For example:
122
+
123
+ ```py
124
+ def get(timeout: Union[int, NotGiven, None] = NotGiven()) -> Response:
125
+ ...
126
+
127
+
128
+ get(timeout=1) # 1s timeout
129
+ get(timeout=None) # No timeout
130
+ get() # Default timeout behavior, which may not be statically known at the method definition.
131
+ ```
132
+ """
133
+
134
+ def __bool__(self) -> Literal[False]:
135
+ return False
136
+
137
+ def __repr__(self) -> str:
138
+ return "NOT_GIVEN"
139
+
140
+
141
+ NotGivenOr = Union[_T, NotGiven]
142
+ NOT_GIVEN = NotGiven()
@@ -1,4 +1,4 @@
1
- from openai import NOT_GIVEN
1
+ from langtrace_python_sdk.types import NOT_GIVEN
2
2
  from .sdk_version_checker import SDKVersionChecker
3
3
  from opentelemetry.trace import Span
4
4
  from langtrace.trace_attributes import SpanAttributes
@@ -16,7 +16,7 @@ limitations under the License.
16
16
 
17
17
  from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME
18
18
  from langtrace_python_sdk.utils import set_span_attribute
19
- from openai import NOT_GIVEN
19
+ from langtrace_python_sdk.types import NOT_GIVEN
20
20
  from tiktoken import get_encoding
21
21
  from tiktoken import get_encoding, list_encoding_names
22
22
 
@@ -1 +1 @@
1
- __version__ = "2.2.28"
1
+ __version__ = "2.2.30"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.2.28
3
+ Version: 2.2.30
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>
@@ -21,6 +21,7 @@ Requires-Dist: opentelemetry-sdk>=1.25.0
21
21
  Requires-Dist: sqlalchemy
22
22
  Requires-Dist: tiktoken>=0.1.1
23
23
  Requires-Dist: trace-attributes==7.0.4
24
+ Requires-Dist: transformers>=4.11.3
24
25
  Provides-Extra: dev
25
26
  Requires-Dist: anthropic; extra == 'dev'
26
27
  Requires-Dist: chromadb; extra == 'dev'
@@ -78,8 +78,8 @@ examples/vertexai_example/main.py,sha256=gndId5X5ksD-ycxnAWMdEqIDbLc3kz5Vt8vm4YP
78
78
  examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56snk-Bbg2Kw,618
79
79
  examples/weaviate_example/query_text.py,sha256=wPHQTc_58kPoKTZMygVjTj-2ZcdrIuaausJfMxNQnQc,127162
80
80
  langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
81
- langtrace_python_sdk/langtrace.py,sha256=kcSZal0BVw2FWhndpQZ3o8xJSnRHdW7aqG5f1X78zHo,8068
82
- langtrace_python_sdk/version.py,sha256=YwImNSNzEWVl7jTeDskU9CMEa5v0unSCyONgNH-ERw8,23
81
+ langtrace_python_sdk/langtrace.py,sha256=NOS2ws7P1Voc-zYSdO_mVb-Kea9_nD5Jq1dXY2CS97k,8208
82
+ langtrace_python_sdk/version.py,sha256=3SFezL1kOpXZvo2YIaWEZ3PTHx1NRXGjgE666GlUfQE,23
83
83
  langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
84
84
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
85
85
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -97,7 +97,7 @@ langtrace_python_sdk/constants/instrumentation/qdrant.py,sha256=yL7BopNQTXW7L7Z-
97
97
  langtrace_python_sdk/constants/instrumentation/vertexai.py,sha256=0s2vX3Y0iwjOPkUg5lAKi-7o3LaNivDSBBbF-o695Ok,1266
98
98
  langtrace_python_sdk/constants/instrumentation/weaviate.py,sha256=gtv-JBxvNGClEMxClmRKzjJ1khgOonsli4D_k9IagSE,2601
99
99
  langtrace_python_sdk/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
100
- langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=_GIH4zP9lpk8UO81zBJ_9HklNszg1bsndqqXwcVe2rY,4569
100
+ langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=2ausFBC9JIitnpu1yECPCL0SXg_IvJTQL0MMsuidTo4,4700
101
101
  langtrace_python_sdk/extensions/langtrace_filesystem.py,sha256=34fZutG28EJ66l67OvTGsydAH3ZpXgikdE7hVLqBpG4,7863
102
102
  langtrace_python_sdk/instrumentation/__init__.py,sha256=BgY4bXGiVEHgpiRq5_OF4w-wqZCC46SBrEBbNO2EzWs,1465
103
103
  langtrace_python_sdk/instrumentation/anthropic/__init__.py,sha256=donrurJAGYlxrSRA3BIf76jGeUcAx9Tq8CVpah68S0Y,101
@@ -126,10 +126,10 @@ langtrace_python_sdk/instrumentation/langchain/instrumentation.py,sha256=_Z4AeNb
126
126
  langtrace_python_sdk/instrumentation/langchain/patch.py,sha256=BmVBKPpI4P9AX6Y8e67WYSz0a0rxZK7cJkI75ure2f4,4166
127
127
  langtrace_python_sdk/instrumentation/langchain_community/__init__.py,sha256=mj5RR_cfkjMql7W9OyyhmviT2GZ-4Pv9XJfGwJufp_E,119
128
128
  langtrace_python_sdk/instrumentation/langchain_community/instrumentation.py,sha256=TmMRXcaiMR99Qg7r7pT1XunCr_GOQl_Csr6leSKYyTQ,5350
129
- langtrace_python_sdk/instrumentation/langchain_community/patch.py,sha256=ssNM9NyRtWiGgqaOZ9zK3R-VDYx_VwNmPq1RAZ-4Wzg,5232
129
+ langtrace_python_sdk/instrumentation/langchain_community/patch.py,sha256=fn-FBbu56ko7XSer0dDdQtIaXcsdZ7L_il_YjnAdL8I,5817
130
130
  langtrace_python_sdk/instrumentation/langchain_core/__init__.py,sha256=kumE_reeqgM-ZvEZ6-XxyT-F-HAdKq_v_PKvsLb4EZQ,110
131
131
  langtrace_python_sdk/instrumentation/langchain_core/instrumentation.py,sha256=uiRGS3RLZGe442kzEyW2b9xJitb0EmZ8zs6Sj-cyol4,6295
132
- langtrace_python_sdk/instrumentation/langchain_core/patch.py,sha256=SvYTuYaVtKzoqmIz-_FIZbTCT00CItZOwjWvEOCwfDA,9552
132
+ langtrace_python_sdk/instrumentation/langchain_core/patch.py,sha256=fNoGSM9Ui1O--5hv6T6Tw1fuWw7IfFVC_7kQL0qERec,10529
133
133
  langtrace_python_sdk/instrumentation/langgraph/__init__.py,sha256=eitlHloY-aZ4ZuIEJx61AadEA3G7siyecP-V-lziAr8,101
134
134
  langtrace_python_sdk/instrumentation/langgraph/instrumentation.py,sha256=SUZZhWSIbcfsF1S5NtEqW8QzkRM_pKAuXB7pwk5tsOU,2526
135
135
  langtrace_python_sdk/instrumentation/langgraph/patch.py,sha256=PGe1ZywXctB_yYqnp8AtD8Xqj7EZ087-S5_2vLRYhEQ,4987
@@ -144,7 +144,7 @@ langtrace_python_sdk/instrumentation/ollama/instrumentation.py,sha256=jdsvkqUJAA
144
144
  langtrace_python_sdk/instrumentation/ollama/patch.py,sha256=7ETx0tQic5h_kH1f-IeptFwgNTBb4hSkTkWsB18Avm0,5375
145
145
  langtrace_python_sdk/instrumentation/openai/__init__.py,sha256=VPHRNCQEdkizIVP2d0Uw_a7t8XOTSTprEIB8oboJFbs,95
146
146
  langtrace_python_sdk/instrumentation/openai/instrumentation.py,sha256=A0BJHRLcZ74TNVg6I0I9M5YWvSpAtXwMmME6N5CEQ_M,2945
147
- langtrace_python_sdk/instrumentation/openai/patch.py,sha256=4GCYJzZdUBopEDinpTwRBFf-Enb0hdNO16LiiMKqqvY,24226
147
+ langtrace_python_sdk/instrumentation/openai/patch.py,sha256=Zf7Q5f7FgmmYloJqUSQDOAAZpq3ctxlWRDKFU8QnkFQ,24239
148
148
  langtrace_python_sdk/instrumentation/pinecone/__init__.py,sha256=DzXyGh9_MGWveJvXULkFwdkf7PbG2s3bAWtT1Dmz7Ok,99
149
149
  langtrace_python_sdk/instrumentation/pinecone/instrumentation.py,sha256=HDXkRITrVPwdQEoOYJOfMzZE_2-vDDvuqHTlD8W1lQw,1845
150
150
  langtrace_python_sdk/instrumentation/pinecone/patch.py,sha256=MIbUcEsVzl4W_pfq81LP9QFVhwPB8rHF0Aod9pq_j-o,5249
@@ -157,10 +157,10 @@ langtrace_python_sdk/instrumentation/vertexai/patch.py,sha256=mfd3LiKYGMW3jLf9OE
157
157
  langtrace_python_sdk/instrumentation/weaviate/__init__.py,sha256=Mc-Je6evPo-kKQzerTG7bd1XO5JOh4YGTE3wBxaUBwg,99
158
158
  langtrace_python_sdk/instrumentation/weaviate/instrumentation.py,sha256=bzPwtoQD0X6beLYXe6ZL7XRkyRkqdiqKiGc4gOlCQdU,2295
159
159
  langtrace_python_sdk/instrumentation/weaviate/patch.py,sha256=nr7USyY6overK3GQCo4Si0x3eoEl9ptoMRXuQUP4Ox8,6671
160
- langtrace_python_sdk/types/__init__.py,sha256=M-_6eLNR8GhjFZH3iMay4s3j7EcsT-hRAM5IWluS58A,3403
161
- langtrace_python_sdk/utils/__init__.py,sha256=SwYYPIh2AzEpI3zbwowQU2zJlwRwoVdWOCcrAKnkI9g,873
160
+ langtrace_python_sdk/types/__init__.py,sha256=MeGkmoy2OY3V21GErDIdlf_N8Aj7HDld5Tpbvq2PwTY,4104
161
+ langtrace_python_sdk/utils/__init__.py,sha256=giTHkvDOQdqFqXU4PoGP7DhA9tAteZN-KxX3mEUg6QQ,893
162
162
  langtrace_python_sdk/utils/langtrace_sampler.py,sha256=BupNndHbU9IL_wGleKetz8FdcveqHMBVz1bfKTTW80w,1753
163
- langtrace_python_sdk/utils/llm.py,sha256=k-xrIfwTZdWjKJHlCFsKUjQVNabN8X_VwH0g3ta5JwQ,14570
163
+ langtrace_python_sdk/utils/llm.py,sha256=7-b3r7NM2WeiVycIy0nmSer9aaVs9x3mIvTGyL7dWps,14590
164
164
  langtrace_python_sdk/utils/misc.py,sha256=CD9NWRLxLpFd0YwlHJqzlpFNedXVWtAKGOjQWnDCo8k,838
165
165
  langtrace_python_sdk/utils/prompt_registry.py,sha256=n5dQMVLBw8aJZY8Utvf67bncc25ELf6AH9BYw8_hSzo,2619
166
166
  langtrace_python_sdk/utils/sdk_version_checker.py,sha256=FzjIWZjn53cX0LEVPdipQd1fO9lG8iGVUEVUs9Hyk6M,1713
@@ -209,8 +209,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
209
209
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
210
210
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
211
211
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
212
- langtrace_python_sdk-2.2.28.dist-info/METADATA,sha256=5QFKRpvLLhzxYSp8zRIOA7bBQeQOH8nPhNc6kWvCU3I,14844
213
- langtrace_python_sdk-2.2.28.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
214
- langtrace_python_sdk-2.2.28.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
215
- langtrace_python_sdk-2.2.28.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
216
- langtrace_python_sdk-2.2.28.dist-info/RECORD,,
212
+ langtrace_python_sdk-2.2.30.dist-info/METADATA,sha256=wupH7hIM1_hYrQHGpFOvcBwUnty3iiLnGKGt2ziNaDQ,14880
213
+ langtrace_python_sdk-2.2.30.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
214
+ langtrace_python_sdk-2.2.30.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
215
+ langtrace_python_sdk-2.2.30.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
216
+ langtrace_python_sdk-2.2.30.dist-info/RECORD,,