langtrace-python-sdk 2.1.15__py3-none-any.whl → 2.1.16__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.
- examples/langchain_example/basic.py +0 -2
- examples/openai_example/chat_completion.py +0 -1
- examples/pinecone_example/__init__.py +10 -3
- examples/pinecone_example/basic.py +5 -10
- langtrace_python_sdk/__init__.py +5 -1
- langtrace_python_sdk/utils/with_root_span.py +18 -3
- langtrace_python_sdk/version.py +1 -1
- {langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.16.dist-info}/METADATA +33 -11
- {langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.16.dist-info}/RECORD +11 -11
- {langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.16.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.16.dist-info}/licenses/LICENSE +0 -0
|
@@ -18,7 +18,6 @@ _ = load_dotenv(find_dotenv())
|
|
|
18
18
|
langtrace.init()
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
# @with_additional_attributes({"user.id": "1234", "user.feedback.rating": 1})
|
|
22
21
|
def api_call_1():
|
|
23
22
|
llm = ChatOpenAI()
|
|
24
23
|
prompt = ChatPromptTemplate.from_messages(
|
|
@@ -33,7 +32,6 @@ def api_call_1():
|
|
|
33
32
|
print(res)
|
|
34
33
|
|
|
35
34
|
|
|
36
|
-
# @with_additional_attributes({"user.id": "37373", "user.feedback.rating": 1})
|
|
37
35
|
def api_call_2():
|
|
38
36
|
llm = ChatOpenAI()
|
|
39
37
|
prompt = ChatPromptTemplate.from_messages(
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
from langtrace_python_sdk import
|
|
1
|
+
from langtrace_python_sdk import (
|
|
2
|
+
get_prompt_from_registry,
|
|
3
|
+
with_langtrace_root_span,
|
|
4
|
+
with_additional_attributes,
|
|
5
|
+
inject_additional_attributes,
|
|
6
|
+
)
|
|
2
7
|
|
|
3
8
|
|
|
4
9
|
class PineconeRunner:
|
|
5
10
|
@with_langtrace_root_span("Pinecone")
|
|
6
11
|
def run(self):
|
|
7
|
-
from .basic import basic as
|
|
12
|
+
from .basic import basic as do_llm_stuff
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
response = inject_additional_attributes(do_llm_stuff, {"user.id": 1234})
|
|
15
|
+
print(response)
|
|
16
|
+
return response
|
|
@@ -7,6 +7,7 @@ from openai import OpenAI
|
|
|
7
7
|
from pinecone import Pinecone, ServerlessSpec
|
|
8
8
|
|
|
9
9
|
from langtrace_python_sdk import (
|
|
10
|
+
get_prompt_from_registry,
|
|
10
11
|
langtrace,
|
|
11
12
|
with_langtrace_root_span,
|
|
12
13
|
with_additional_attributes,
|
|
@@ -14,7 +15,6 @@ from langtrace_python_sdk import (
|
|
|
14
15
|
from langtrace_python_sdk.utils.with_root_span import SendUserFeedback
|
|
15
16
|
|
|
16
17
|
_ = load_dotenv(find_dotenv())
|
|
17
|
-
|
|
18
18
|
langtrace.init()
|
|
19
19
|
|
|
20
20
|
client = OpenAI()
|
|
@@ -32,10 +32,8 @@ def create_index():
|
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
@with_additional_attributes({"db.embedding_model": "text-embedding-ada-002"})
|
|
36
35
|
@with_langtrace_root_span("Pinecone Basic")
|
|
37
|
-
def basic(
|
|
38
|
-
|
|
36
|
+
def basic():
|
|
39
37
|
result = client.embeddings.create(
|
|
40
38
|
model="text-embedding-ada-002",
|
|
41
39
|
input="Some random text string goes here",
|
|
@@ -53,10 +51,7 @@ def basic(span_id=None, trace_id=None):
|
|
|
53
51
|
resp = index.query(
|
|
54
52
|
vector=embedding, top_k=1, include_values=False, namespace="test-namespace"
|
|
55
53
|
)
|
|
56
|
-
SendUserFeedback().evaluate(
|
|
57
|
-
|
|
58
|
-
)
|
|
54
|
+
# SendUserFeedback().evaluate(
|
|
55
|
+
# {"spanId": span_id, "traceId": trace_id, "userScore": 1, "userId": "123"}
|
|
56
|
+
# )
|
|
59
57
|
return [res, resp]
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# create_index()
|
langtrace_python_sdk/__init__.py
CHANGED
|
@@ -21,12 +21,16 @@ from langtrace_python_sdk.utils.with_root_span import (
|
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
from langtrace_python_sdk.utils.prompt_registry import get_prompt_from_registry
|
|
24
|
-
from langtrace_python_sdk.utils.with_root_span import
|
|
24
|
+
from langtrace_python_sdk.utils.with_root_span import (
|
|
25
|
+
SendUserFeedback,
|
|
26
|
+
inject_additional_attributes,
|
|
27
|
+
)
|
|
25
28
|
|
|
26
29
|
__all__ = [
|
|
27
30
|
"langtrace",
|
|
28
31
|
"with_langtrace_root_span",
|
|
29
32
|
"with_additional_attributes",
|
|
33
|
+
"inject_additional_attributes",
|
|
30
34
|
"get_prompt_from_registry",
|
|
31
35
|
"SendUserFeedback",
|
|
32
36
|
]
|
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|
|
16
16
|
|
|
17
17
|
import asyncio
|
|
18
18
|
import os
|
|
19
|
+
from deprecated import deprecated
|
|
19
20
|
from functools import wraps
|
|
20
21
|
from typing import Optional
|
|
21
22
|
|
|
@@ -23,9 +24,6 @@ import requests
|
|
|
23
24
|
from opentelemetry import baggage, context, trace
|
|
24
25
|
from opentelemetry.trace import SpanKind
|
|
25
26
|
|
|
26
|
-
from langtrace_python_sdk.constants.exporter.langtrace_exporter import (
|
|
27
|
-
LANGTRACE_REMOTE_URL,
|
|
28
|
-
)
|
|
29
27
|
from langtrace_python_sdk.constants.instrumentation.common import (
|
|
30
28
|
LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY,
|
|
31
29
|
)
|
|
@@ -87,7 +85,14 @@ def with_langtrace_root_span(
|
|
|
87
85
|
return decorator
|
|
88
86
|
|
|
89
87
|
|
|
88
|
+
@deprecated(reason="Use inject_additional_attributes instead")
|
|
90
89
|
def with_additional_attributes(attributes={}):
|
|
90
|
+
print(
|
|
91
|
+
Fore.YELLOW
|
|
92
|
+
+ "with_additional_attributes is deprecated, use inject_additional_attributes instead"
|
|
93
|
+
+ Fore.RESET
|
|
94
|
+
)
|
|
95
|
+
|
|
91
96
|
def decorator(func):
|
|
92
97
|
@wraps(func)
|
|
93
98
|
def sync_wrapper(*args, **kwargs):
|
|
@@ -113,6 +118,16 @@ def with_additional_attributes(attributes={}):
|
|
|
113
118
|
return decorator
|
|
114
119
|
|
|
115
120
|
|
|
121
|
+
def inject_additional_attributes(fn, attributes=None):
|
|
122
|
+
if attributes:
|
|
123
|
+
new_ctx = baggage.set_baggage(
|
|
124
|
+
LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY, attributes
|
|
125
|
+
)
|
|
126
|
+
context.attach(new_ctx)
|
|
127
|
+
|
|
128
|
+
return fn()
|
|
129
|
+
|
|
130
|
+
|
|
116
131
|
class SendUserFeedback:
|
|
117
132
|
_langtrace_host: str
|
|
118
133
|
_langtrace_api_key: str
|
langtrace_python_sdk/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.1.
|
|
1
|
+
__version__ = "2.1.16"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: langtrace-python-sdk
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.16
|
|
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>
|
|
@@ -179,14 +179,14 @@ langtrace.init(custom_remote_exporter=<your_exporter>, batch=<True or False>)
|
|
|
179
179
|
|
|
180
180
|
### Configure Langtrace
|
|
181
181
|
|
|
182
|
-
| Parameter | Type | Default Value | Description
|
|
183
|
-
| -------------------------- | ----------------------------------- | ----------------------------- |
|
|
184
|
-
| `api_key` | `str` | `LANGTRACE_API_KEY` or `None` | The API key for authentication.
|
|
185
|
-
| `batch` | `bool` | `True` | Whether to batch spans before sending them.
|
|
186
|
-
| `write_spans_to_console` | `bool` | `False` | Whether to write spans to the console.
|
|
187
|
-
| `custom_remote_exporter` | `Optional[Exporter]` | `None` | Custom remote exporter. If `None`, a default `LangTraceExporter` will be used.
|
|
188
|
-
| `api_host` | `Optional[str]` | `https://langtrace.ai/` | The API host for the remote exporter.
|
|
189
|
-
| `disable_instrumentations` | `Optional[DisableInstrumentations]` | `None` | You can pass an object to disable instrumentation for specific vendors ex: `{'only': ['openai']}` or `{'all_except': ['openai']}`
|
|
182
|
+
| Parameter | Type | Default Value | Description |
|
|
183
|
+
| -------------------------- | ----------------------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
184
|
+
| `api_key` | `str` | `LANGTRACE_API_KEY` or `None` | The API key for authentication. |
|
|
185
|
+
| `batch` | `bool` | `True` | Whether to batch spans before sending them. |
|
|
186
|
+
| `write_spans_to_console` | `bool` | `False` | Whether to write spans to the console. |
|
|
187
|
+
| `custom_remote_exporter` | `Optional[Exporter]` | `None` | Custom remote exporter. If `None`, a default `LangTraceExporter` will be used. |
|
|
188
|
+
| `api_host` | `Optional[str]` | `https://langtrace.ai/` | The API host for the remote exporter. |
|
|
189
|
+
| `disable_instrumentations` | `Optional[DisableInstrumentations]` | `None` | You can pass an object to disable instrumentation for specific vendors ex: `{'only': ['openai']}` or `{'all_except': ['openai']}` |
|
|
190
190
|
|
|
191
191
|
### Additional Customization
|
|
192
192
|
|
|
@@ -205,7 +205,30 @@ def example():
|
|
|
205
205
|
return response
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
- `
|
|
208
|
+
- `inject_additional_attributes` - this function is designed to enhance the traces by adding custom attributes to the current context. These custom attributes provide extra details about the operations being performed, making it easier to analyze and understand their behavior.
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from langtrace_python_sdk import inject_additional_attributes
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def do_llm_stuff(name=""):
|
|
216
|
+
response = client.chat.completions.create(
|
|
217
|
+
model="gpt-4",
|
|
218
|
+
messages=[{"role": "user", "content": "Say this is a test three times"}],
|
|
219
|
+
stream=False,
|
|
220
|
+
)
|
|
221
|
+
return response
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def main():
|
|
225
|
+
response = inject_additional_attributes(lambda: do_llm_stuff(name="llm"), {'user.id': 'userId'})
|
|
226
|
+
|
|
227
|
+
# if the function do not take arguments then this syntax will work
|
|
228
|
+
response = inject_additional_attributes(do_llm_stuff, {'user.id': 'userId'})
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- `with_additional_attributes` - is behaving the same as `inject_additional_attributes` but as a decorator, this will be deprecated soon.
|
|
209
232
|
|
|
210
233
|
```python
|
|
211
234
|
from langtrace_python_sdk import with_langtrace_root_span, with_additional_attributes
|
|
@@ -277,7 +300,6 @@ We welcome contributions to this project. To get started, fork this repository a
|
|
|
277
300
|
|
|
278
301
|
If you want to run any of the examples go to `run_example.py` file, you will find `ENABLED_EXAMPLES`. choose the example you want to run and just toggle the flag to `True` and run the file using `python src/run_example.py`
|
|
279
302
|
|
|
280
|
-
|
|
281
303
|
---
|
|
282
304
|
|
|
283
305
|
## Security
|
|
@@ -13,7 +13,7 @@ examples/fastapi_example/__init__.py,sha256=INIfvJP7zC_KkJCtulS1qbh61-MJTPAHnzAg
|
|
|
13
13
|
examples/fastapi_example/basic_route.py,sha256=_IRXjkOtJQ-bTIGa1WbvUF_2LF4bjghjyXt4YrHaRvw,1170
|
|
14
14
|
examples/hiveagent_example/basic.py,sha256=Sd7I5w8w5Xx7ODaydTY30yiq9HwJDMKHQywrZjgehP0,441
|
|
15
15
|
examples/langchain_example/__init__.py,sha256=t28923ZDDejZabsvINnYwpLyb63WFwPde-Nmzdg-kH4,254
|
|
16
|
-
examples/langchain_example/basic.py,sha256=
|
|
16
|
+
examples/langchain_example/basic.py,sha256=8ppNBptB0x3vjD5wUF5qP7ghp1vk-OJBBKk-PJPVD5I,2504
|
|
17
17
|
examples/langchain_example/groq_example.py,sha256=9dBbOWZCVJ29PpB1NbJhc9MThmtwrlOpdNIxPl7d8f8,787
|
|
18
18
|
examples/langchain_example/langgraph_example.py,sha256=7C2a4Sg0PKbbab03CVkStO3MzT7C-O1UtdmObvBXurM,2005
|
|
19
19
|
examples/langchain_example/tool.py,sha256=8T8_IDbgA58XbsfyH5_xhA8ZKQfyfyFxF8wor-PsRjA,2556
|
|
@@ -24,7 +24,7 @@ examples/llamaindex_example/data/abramov.txt,sha256=Ou-GyWZm5AjHLgxviBoRE9ikNv5M
|
|
|
24
24
|
examples/openai_example/__init__.py,sha256=6l2FePb3vYBJVwIT4qfdtOLobKLZ6iO16Fe31TUwNz8,827
|
|
25
25
|
examples/openai_example/async_tool_calling_nonstreaming.py,sha256=FhbDX91RLhTrNd5IGPI0CxRdCjTRcNLlWkYdLqHGbVs,3838
|
|
26
26
|
examples/openai_example/async_tool_calling_streaming.py,sha256=LaSKmn_Unv55eTHXYdEmKjo39eNuB3ASOBV-m8U1HfU,7136
|
|
27
|
-
examples/openai_example/chat_completion.py,sha256=
|
|
27
|
+
examples/openai_example/chat_completion.py,sha256=AzA1IykhNHYu9fp-e41EEh4GudksdtJfLPpXP7odvLg,1191
|
|
28
28
|
examples/openai_example/embeddings_create.py,sha256=sqz-zh3pEaB17gVYeY0QE76QxRwsmo6wV8yjAfg1ljg,522
|
|
29
29
|
examples/openai_example/function_calling.py,sha256=zz-JdCcpP7uCXG21EYXF1Y39IKj6gYt2fOP5N_ywpnc,2338
|
|
30
30
|
examples/openai_example/images_edit.py,sha256=0hG5OYTSUBrcwSxbqN67brPYjf1pRJs8vqGzu-UjK6c,887
|
|
@@ -35,15 +35,15 @@ examples/openai_example/tool_calling_streaming.py,sha256=mV1RbyAoVhumGRPpqPWQ6PM
|
|
|
35
35
|
examples/openai_example/resources/lounge_flamingo.png,sha256=aspniTtmWqwLp3YUhYqAe2ze8nJaq-bTSW7uUJudtd0,2416234
|
|
36
36
|
examples/openai_example/resources/mask.png,sha256=mUE9Dfp-x8jI0Nh4WGr0P9pueUqEZfpjwxR-6Rxzxz4,2483660
|
|
37
37
|
examples/perplexity_example/basic.py,sha256=bp7n27gaugJkaFVyt8pjaEfi66lYcqP6eFFjPewUShY,668
|
|
38
|
-
examples/pinecone_example/__init__.py,sha256=
|
|
39
|
-
examples/pinecone_example/basic.py,sha256=
|
|
38
|
+
examples/pinecone_example/__init__.py,sha256=_rvn7Ygt_QWMQoa5wB2GB0S9gZVrlJrPrEhXqU3hPKw,427
|
|
39
|
+
examples/pinecone_example/basic.py,sha256=258a5EGyLXLCu_xnLl4iROhNjUrYULwnKS3wxTlZhFs,1486
|
|
40
40
|
examples/qdrant_example/__init__.py,sha256=Ze9xEzW8FiHUO58YBa8JeHNOwcmo3dpYH77AkdyglKU,197
|
|
41
41
|
examples/qdrant_example/basic.py,sha256=DCMjHSuBZKkhEjCkwy5d5La9WMyW0lCWqtcZWiFCEm4,1425
|
|
42
42
|
examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56snk-Bbg2Kw,618
|
|
43
43
|
examples/weaviate_example/query_text.py,sha256=qz9o-fTDzX5AW5m8BJF-TfmBdokxh492NfnmnPUMU3s,64814
|
|
44
|
-
langtrace_python_sdk/__init__.py,sha256=
|
|
44
|
+
langtrace_python_sdk/__init__.py,sha256=j7EX7oY783Nmh6dQQO9VQVtirVnz4ajr7sBkw-y6rRk,1113
|
|
45
45
|
langtrace_python_sdk/langtrace.py,sha256=pN-xJRXrtvJIenMOH0-xlNXcnqL9qMjg28SrW-PMRU0,6978
|
|
46
|
-
langtrace_python_sdk/version.py,sha256=
|
|
46
|
+
langtrace_python_sdk/version.py,sha256=PUbyHN5ixal0BffZXLS2fU7ojPZOahFVrPT578Lb1Sg,23
|
|
47
47
|
langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
|
|
48
48
|
langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
|
|
49
49
|
langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -106,7 +106,7 @@ langtrace_python_sdk/utils/prompt_registry.py,sha256=-BNHX_UPAqBG1IdNUXZIA669M59
|
|
|
106
106
|
langtrace_python_sdk/utils/sdk_version_checker.py,sha256=FzjIWZjn53cX0LEVPdipQd1fO9lG8iGVUEVUs9Hyk6M,1713
|
|
107
107
|
langtrace_python_sdk/utils/silently_fail.py,sha256=F_9EteXCO9Cyq-8MA1OT2Zy_dx8n06nt31I7t7ui24E,478
|
|
108
108
|
langtrace_python_sdk/utils/types.py,sha256=l-N6o7cnWUyrD6dBvW7W3Pf5CkPo5QaoT__k1XLbrQg,383
|
|
109
|
-
langtrace_python_sdk/utils/with_root_span.py,sha256=
|
|
109
|
+
langtrace_python_sdk/utils/with_root_span.py,sha256=IPosE45Ef4jsfsHzW8cFiBPp5B64G4aBHUCU2_R4REc,7239
|
|
110
110
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
111
111
|
tests/conftest.py,sha256=0Jo6iCZTXbdvyJVhG9UpYGkLabL75378oauCzmt-Sa8,603
|
|
112
112
|
tests/utils.py,sha256=hP8sTH-M8WO6zlLkSFHPf6483ZcKEcnxul6JIIb1pLM,1396
|
|
@@ -143,7 +143,7 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
|
|
|
143
143
|
tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
|
|
144
144
|
tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
|
|
145
145
|
tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
|
|
146
|
-
langtrace_python_sdk-2.1.
|
|
147
|
-
langtrace_python_sdk-2.1.
|
|
148
|
-
langtrace_python_sdk-2.1.
|
|
149
|
-
langtrace_python_sdk-2.1.
|
|
146
|
+
langtrace_python_sdk-2.1.16.dist-info/METADATA,sha256=yXtCuRrFTuyr_ITt87NfKTmJS4y1yflOGcq3iozYNCM,13091
|
|
147
|
+
langtrace_python_sdk-2.1.16.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
|
148
|
+
langtrace_python_sdk-2.1.16.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
149
|
+
langtrace_python_sdk-2.1.16.dist-info/RECORD,,
|
|
File without changes
|
{langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.16.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|