langtrace-python-sdk 2.1.15__py3-none-any.whl → 2.1.17__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/inspect_ai_example/basic_eval.py +28 -0
- 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 +7 -6
- langtrace_python_sdk/extensions/langtrace_filesystem.py +178 -0
- 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.17.dist-info}/METADATA +34 -11
- {langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.17.dist-info}/RECORD +14 -11
- langtrace_python_sdk-2.1.17.dist-info/entry_points.txt +2 -0
- {langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.17.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.17.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# langtrace.init(write_spans_to_console=True)
|
|
2
|
+
import fsspec
|
|
3
|
+
from inspect_ai import Task, task
|
|
4
|
+
from inspect_ai.dataset import csv_dataset
|
|
5
|
+
from inspect_ai.scorer import model_graded_qa
|
|
6
|
+
from inspect_ai.solver import chain_of_thought, generate, self_critique
|
|
7
|
+
|
|
8
|
+
from langtrace_python_sdk.extensions.langtrace_filesystem import \
|
|
9
|
+
LangTraceFileSystem
|
|
10
|
+
|
|
11
|
+
# from langtrace_python_sdk import langtrace
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Manually register the filesystem with fsspec
|
|
15
|
+
# Note: This is only necessary because the filesystem is not registered.
|
|
16
|
+
fsspec.register_implementation(LangTraceFileSystem.protocol, LangTraceFileSystem)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@task
|
|
20
|
+
def security_guide():
|
|
21
|
+
return Task(
|
|
22
|
+
dataset=csv_dataset("langtracefs://clxc2mxu6000lpc7ntsvcjvp9"),
|
|
23
|
+
plan=[
|
|
24
|
+
chain_of_thought(),
|
|
25
|
+
self_critique()
|
|
26
|
+
],
|
|
27
|
+
scorer=model_graded_qa()
|
|
28
|
+
)
|
|
@@ -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
|
@@ -15,18 +15,19 @@ limitations under the License.
|
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
17
|
from langtrace_python_sdk import langtrace
|
|
18
|
-
from langtrace_python_sdk.
|
|
19
|
-
|
|
20
|
-
with_additional_attributes,
|
|
21
|
-
)
|
|
22
|
-
|
|
18
|
+
from langtrace_python_sdk.extensions.langtrace_filesystem import \
|
|
19
|
+
LangTraceFileSystem
|
|
23
20
|
from langtrace_python_sdk.utils.prompt_registry import get_prompt_from_registry
|
|
24
|
-
from langtrace_python_sdk.utils.with_root_span import
|
|
21
|
+
from langtrace_python_sdk.utils.with_root_span import (
|
|
22
|
+
SendUserFeedback, inject_additional_attributes, with_additional_attributes,
|
|
23
|
+
with_langtrace_root_span)
|
|
25
24
|
|
|
26
25
|
__all__ = [
|
|
27
26
|
"langtrace",
|
|
28
27
|
"with_langtrace_root_span",
|
|
29
28
|
"with_additional_attributes",
|
|
29
|
+
"inject_additional_attributes",
|
|
30
30
|
"get_prompt_from_registry",
|
|
31
31
|
"SendUserFeedback",
|
|
32
|
+
"LangTraceFileSystem",
|
|
32
33
|
]
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import io
|
|
3
|
+
import os
|
|
4
|
+
import requests
|
|
5
|
+
from typing import Iterator, Literal, Union
|
|
6
|
+
from colorama import Fore
|
|
7
|
+
from langtrace_python_sdk.constants.exporter.langtrace_exporter import (
|
|
8
|
+
LANGTRACE_REMOTE_URL,
|
|
9
|
+
)
|
|
10
|
+
from fsspec.spec import AbstractFileSystem
|
|
11
|
+
|
|
12
|
+
OpenTextMode = Literal["r", "a", "w"]
|
|
13
|
+
OpenBinaryMode = Literal["rb", "ab", "wb"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class OpenMode(str):
|
|
17
|
+
def __init_subclass__(cls, **kwargs):
|
|
18
|
+
allowed_values = set(OpenTextMode.__args__) | set(OpenBinaryMode.__args__)
|
|
19
|
+
super().__init_subclass__(**kwargs)
|
|
20
|
+
|
|
21
|
+
def __new__(cls, value):
|
|
22
|
+
if value not in allowed_values:
|
|
23
|
+
raise ValueError(f"Invalid value for OpenMode: {value}")
|
|
24
|
+
return super().__new__(cls, value)
|
|
25
|
+
|
|
26
|
+
cls.__new__ = __new__
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class LangTraceFile(io.BytesIO):
|
|
30
|
+
def __init__(self, fs: "LangTraceFileSystem", path: str, mode: OpenMode):
|
|
31
|
+
super().__init__()
|
|
32
|
+
self.fs = fs
|
|
33
|
+
self.path = path
|
|
34
|
+
self.mode = mode
|
|
35
|
+
|
|
36
|
+
def close(self) -> None:
|
|
37
|
+
if not self.closed:
|
|
38
|
+
self.seek(0)
|
|
39
|
+
file_data = self.getvalue()
|
|
40
|
+
self.fs.files[self.path] = file_data
|
|
41
|
+
|
|
42
|
+
# Upload the file to the remote server
|
|
43
|
+
self.upload_to_server(file_data)
|
|
44
|
+
|
|
45
|
+
super().close()
|
|
46
|
+
|
|
47
|
+
def upload_to_server(self, file_data: bytes) -> None:
|
|
48
|
+
try:
|
|
49
|
+
# Parse the log file and upload it to the server
|
|
50
|
+
log = file_data.decode("utf-8")
|
|
51
|
+
eval_log = json.loads(log)
|
|
52
|
+
data = {
|
|
53
|
+
"runId": eval_log['eval']['run_id'],
|
|
54
|
+
"taskId": eval_log['eval']['task_id'],
|
|
55
|
+
"log": log,
|
|
56
|
+
}
|
|
57
|
+
if self.path is not None:
|
|
58
|
+
dataset_id = self.path.split("/")[0]
|
|
59
|
+
print(Fore.GREEN + f"Sending results to Langtrace for dataset: {dataset_id}" + Fore.RESET)
|
|
60
|
+
data["datasetId"] = dataset_id
|
|
61
|
+
else:
|
|
62
|
+
print(Fore.GREEN + "Sending results to Langtrace" + Fore.RESET)
|
|
63
|
+
response = requests.post(
|
|
64
|
+
url=f"{LANGTRACE_REMOTE_URL}/api/run",
|
|
65
|
+
data=json.dumps(data),
|
|
66
|
+
headers={
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"x-api-key": os.environ.get("LANGTRACE_API_KEY")
|
|
69
|
+
},
|
|
70
|
+
timeout=20,
|
|
71
|
+
)
|
|
72
|
+
response.raise_for_status()
|
|
73
|
+
print(
|
|
74
|
+
Fore.GREEN + "Results sent to Langtrace successfully." + Fore.RESET
|
|
75
|
+
)
|
|
76
|
+
except requests.exceptions.RequestException as error:
|
|
77
|
+
print(Fore.RED + f"Error reporting results: {error}" + Fore.RESET)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class LangTraceFileSystem(AbstractFileSystem):
|
|
81
|
+
protocol = "langtracefs"
|
|
82
|
+
sep = "/"
|
|
83
|
+
|
|
84
|
+
def __init__(self, *args, **kwargs):
|
|
85
|
+
super().__init__(*args, **kwargs)
|
|
86
|
+
self.files = {}
|
|
87
|
+
self.dirs = set()
|
|
88
|
+
|
|
89
|
+
def open(
|
|
90
|
+
self,
|
|
91
|
+
path: str,
|
|
92
|
+
mode: OpenTextMode | OpenBinaryMode = "rb",
|
|
93
|
+
**kwargs,
|
|
94
|
+
) -> Iterator[LangTraceFile | io.BytesIO]:
|
|
95
|
+
if "r" in mode:
|
|
96
|
+
dataset_id = path
|
|
97
|
+
# Fetch file from API and return a BytesIO object
|
|
98
|
+
file_data = self.fetch_file_from_api(dataset_id)
|
|
99
|
+
return io.BytesIO(file_data)
|
|
100
|
+
elif "w" in mode or "a" in mode:
|
|
101
|
+
return LangTraceFile(self, path, mode)
|
|
102
|
+
else:
|
|
103
|
+
raise ValueError(f"Unsupported mode: {mode}")
|
|
104
|
+
|
|
105
|
+
def fetch_file_from_api(self, dataset_id: str) -> bytes:
|
|
106
|
+
try:
|
|
107
|
+
print(Fore.GREEN + f"Fetching dataset with id: {dataset_id} from Langtrace" + Fore.RESET)
|
|
108
|
+
response = requests.get(
|
|
109
|
+
url=f"{LANGTRACE_REMOTE_URL}/api/dataset/download?id={dataset_id}",
|
|
110
|
+
headers={
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
"x-api-key": os.environ.get("LANGTRACE_API_KEY")
|
|
113
|
+
},
|
|
114
|
+
timeout=20,
|
|
115
|
+
)
|
|
116
|
+
print(Fore.GREEN + f"Successfully fetched dataset with id: {dataset_id} from Langtrace" + Fore.RESET)
|
|
117
|
+
response.raise_for_status()
|
|
118
|
+
file_data = response.content
|
|
119
|
+
return file_data
|
|
120
|
+
except requests.exceptions.RequestException as error:
|
|
121
|
+
print(Fore.RED + f"Error fetching dataset with id: {dataset_id} from Langtrace: {error}" + Fore.RESET)
|
|
122
|
+
return b""
|
|
123
|
+
|
|
124
|
+
def makedirs(self, path: str, exist_ok: bool = False) -> None:
|
|
125
|
+
if not exist_ok and path in self.dirs:
|
|
126
|
+
raise FileExistsError(f"Directory {path} already exists")
|
|
127
|
+
self.dirs.add(path)
|
|
128
|
+
|
|
129
|
+
def info(self, path: str, **kwargs):
|
|
130
|
+
if path in self.files:
|
|
131
|
+
return {"name": path, "size": len(self.files[path]), "type": "file"}
|
|
132
|
+
elif path in self.dirs:
|
|
133
|
+
return {"name": path, "type": "directory"}
|
|
134
|
+
else:
|
|
135
|
+
raise FileNotFoundError(f"No such file or directory: {path}")
|
|
136
|
+
|
|
137
|
+
def created(self, path: str) -> float:
|
|
138
|
+
# Return a dummy creation time
|
|
139
|
+
return 0.0
|
|
140
|
+
|
|
141
|
+
def exists(self, path: str) -> bool:
|
|
142
|
+
return path in self.files or path in self.dirs
|
|
143
|
+
|
|
144
|
+
def ls(self, path: str, detail: bool = False, **kwargs):
|
|
145
|
+
if path not in self.dirs:
|
|
146
|
+
raise FileNotFoundError(f"No such directory: {path}")
|
|
147
|
+
entries = []
|
|
148
|
+
for file_path in self.files:
|
|
149
|
+
if file_path.startswith(path + self.sep):
|
|
150
|
+
if detail:
|
|
151
|
+
entries.append(self.info(file_path))
|
|
152
|
+
else:
|
|
153
|
+
entries.append(file_path)
|
|
154
|
+
for dir_path in self.dirs:
|
|
155
|
+
if dir_path.startswith(path + self.sep):
|
|
156
|
+
if detail:
|
|
157
|
+
entries.append(self.info(dir_path))
|
|
158
|
+
else:
|
|
159
|
+
entries.append(dir_path)
|
|
160
|
+
return entries
|
|
161
|
+
|
|
162
|
+
def walk(self, path: str, maxdepth: int = None, **kwargs):
|
|
163
|
+
for root, dirs, files in self._walk(path):
|
|
164
|
+
yield root, dirs, [self.sep.join([root, f]) for f in files]
|
|
165
|
+
|
|
166
|
+
def _walk(self, path: str):
|
|
167
|
+
if path in self.dirs:
|
|
168
|
+
dirs = [d for d in self.dirs if d.startswith(path + self.sep)]
|
|
169
|
+
files = [f for f in self.files if f.startswith(path + self.sep)]
|
|
170
|
+
yield path, [d.split(self.sep)[-1] for d in dirs], [f.split(self.sep)[-1] for f in files]
|
|
171
|
+
for d in dirs:
|
|
172
|
+
yield from self._walk(d)
|
|
173
|
+
|
|
174
|
+
def unstrip_protocol(self, path: str) -> str:
|
|
175
|
+
return path
|
|
176
|
+
|
|
177
|
+
def invalidate_cache(self, path: str = None) -> None:
|
|
178
|
+
pass
|
|
@@ -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.17"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: langtrace-python-sdk
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.17
|
|
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>
|
|
@@ -11,6 +11,7 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Requires-Python: >=3.9
|
|
13
13
|
Requires-Dist: colorama>=0.4.6
|
|
14
|
+
Requires-Dist: fsspec>=2024.6.0
|
|
14
15
|
Requires-Dist: opentelemetry-api>=1.25.0
|
|
15
16
|
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.25.0
|
|
16
17
|
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.25.0
|
|
@@ -179,14 +180,14 @@ langtrace.init(custom_remote_exporter=<your_exporter>, batch=<True or False>)
|
|
|
179
180
|
|
|
180
181
|
### Configure Langtrace
|
|
181
182
|
|
|
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']}`
|
|
183
|
+
| Parameter | Type | Default Value | Description |
|
|
184
|
+
| -------------------------- | ----------------------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
185
|
+
| `api_key` | `str` | `LANGTRACE_API_KEY` or `None` | The API key for authentication. |
|
|
186
|
+
| `batch` | `bool` | `True` | Whether to batch spans before sending them. |
|
|
187
|
+
| `write_spans_to_console` | `bool` | `False` | Whether to write spans to the console. |
|
|
188
|
+
| `custom_remote_exporter` | `Optional[Exporter]` | `None` | Custom remote exporter. If `None`, a default `LangTraceExporter` will be used. |
|
|
189
|
+
| `api_host` | `Optional[str]` | `https://langtrace.ai/` | The API host for the remote exporter. |
|
|
190
|
+
| `disable_instrumentations` | `Optional[DisableInstrumentations]` | `None` | You can pass an object to disable instrumentation for specific vendors ex: `{'only': ['openai']}` or `{'all_except': ['openai']}` |
|
|
190
191
|
|
|
191
192
|
### Additional Customization
|
|
192
193
|
|
|
@@ -205,7 +206,30 @@ def example():
|
|
|
205
206
|
return response
|
|
206
207
|
```
|
|
207
208
|
|
|
208
|
-
- `
|
|
209
|
+
- `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.
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from langtrace_python_sdk import inject_additional_attributes
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def do_llm_stuff(name=""):
|
|
217
|
+
response = client.chat.completions.create(
|
|
218
|
+
model="gpt-4",
|
|
219
|
+
messages=[{"role": "user", "content": "Say this is a test three times"}],
|
|
220
|
+
stream=False,
|
|
221
|
+
)
|
|
222
|
+
return response
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def main():
|
|
226
|
+
response = inject_additional_attributes(lambda: do_llm_stuff(name="llm"), {'user.id': 'userId'})
|
|
227
|
+
|
|
228
|
+
# if the function do not take arguments then this syntax will work
|
|
229
|
+
response = inject_additional_attributes(do_llm_stuff, {'user.id': 'userId'})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- `with_additional_attributes` - is behaving the same as `inject_additional_attributes` but as a decorator, this will be deprecated soon.
|
|
209
233
|
|
|
210
234
|
```python
|
|
211
235
|
from langtrace_python_sdk import with_langtrace_root_span, with_additional_attributes
|
|
@@ -277,7 +301,6 @@ We welcome contributions to this project. To get started, fork this repository a
|
|
|
277
301
|
|
|
278
302
|
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
303
|
|
|
280
|
-
|
|
281
304
|
---
|
|
282
305
|
|
|
283
306
|
## Security
|
|
@@ -12,8 +12,9 @@ examples/cohere_example/tools.py,sha256=a5uvS058tcwU6PJbF9EDO6LPVmPj2LoW4Vn8Web3
|
|
|
12
12
|
examples/fastapi_example/__init__.py,sha256=INIfvJP7zC_KkJCtulS1qbh61-MJTPAHnzAgzeKi0yU,87
|
|
13
13
|
examples/fastapi_example/basic_route.py,sha256=_IRXjkOtJQ-bTIGa1WbvUF_2LF4bjghjyXt4YrHaRvw,1170
|
|
14
14
|
examples/hiveagent_example/basic.py,sha256=Sd7I5w8w5Xx7ODaydTY30yiq9HwJDMKHQywrZjgehP0,441
|
|
15
|
+
examples/inspect_ai_example/basic_eval.py,sha256=IpuZGXsCLgHvQN7BlNDaCr_BEqZ56H9BgrPAHCQRE3c,841
|
|
15
16
|
examples/langchain_example/__init__.py,sha256=t28923ZDDejZabsvINnYwpLyb63WFwPde-Nmzdg-kH4,254
|
|
16
|
-
examples/langchain_example/basic.py,sha256=
|
|
17
|
+
examples/langchain_example/basic.py,sha256=8ppNBptB0x3vjD5wUF5qP7ghp1vk-OJBBKk-PJPVD5I,2504
|
|
17
18
|
examples/langchain_example/groq_example.py,sha256=9dBbOWZCVJ29PpB1NbJhc9MThmtwrlOpdNIxPl7d8f8,787
|
|
18
19
|
examples/langchain_example/langgraph_example.py,sha256=7C2a4Sg0PKbbab03CVkStO3MzT7C-O1UtdmObvBXurM,2005
|
|
19
20
|
examples/langchain_example/tool.py,sha256=8T8_IDbgA58XbsfyH5_xhA8ZKQfyfyFxF8wor-PsRjA,2556
|
|
@@ -24,7 +25,7 @@ examples/llamaindex_example/data/abramov.txt,sha256=Ou-GyWZm5AjHLgxviBoRE9ikNv5M
|
|
|
24
25
|
examples/openai_example/__init__.py,sha256=6l2FePb3vYBJVwIT4qfdtOLobKLZ6iO16Fe31TUwNz8,827
|
|
25
26
|
examples/openai_example/async_tool_calling_nonstreaming.py,sha256=FhbDX91RLhTrNd5IGPI0CxRdCjTRcNLlWkYdLqHGbVs,3838
|
|
26
27
|
examples/openai_example/async_tool_calling_streaming.py,sha256=LaSKmn_Unv55eTHXYdEmKjo39eNuB3ASOBV-m8U1HfU,7136
|
|
27
|
-
examples/openai_example/chat_completion.py,sha256=
|
|
28
|
+
examples/openai_example/chat_completion.py,sha256=AzA1IykhNHYu9fp-e41EEh4GudksdtJfLPpXP7odvLg,1191
|
|
28
29
|
examples/openai_example/embeddings_create.py,sha256=sqz-zh3pEaB17gVYeY0QE76QxRwsmo6wV8yjAfg1ljg,522
|
|
29
30
|
examples/openai_example/function_calling.py,sha256=zz-JdCcpP7uCXG21EYXF1Y39IKj6gYt2fOP5N_ywpnc,2338
|
|
30
31
|
examples/openai_example/images_edit.py,sha256=0hG5OYTSUBrcwSxbqN67brPYjf1pRJs8vqGzu-UjK6c,887
|
|
@@ -35,15 +36,15 @@ examples/openai_example/tool_calling_streaming.py,sha256=mV1RbyAoVhumGRPpqPWQ6PM
|
|
|
35
36
|
examples/openai_example/resources/lounge_flamingo.png,sha256=aspniTtmWqwLp3YUhYqAe2ze8nJaq-bTSW7uUJudtd0,2416234
|
|
36
37
|
examples/openai_example/resources/mask.png,sha256=mUE9Dfp-x8jI0Nh4WGr0P9pueUqEZfpjwxR-6Rxzxz4,2483660
|
|
37
38
|
examples/perplexity_example/basic.py,sha256=bp7n27gaugJkaFVyt8pjaEfi66lYcqP6eFFjPewUShY,668
|
|
38
|
-
examples/pinecone_example/__init__.py,sha256=
|
|
39
|
-
examples/pinecone_example/basic.py,sha256=
|
|
39
|
+
examples/pinecone_example/__init__.py,sha256=_rvn7Ygt_QWMQoa5wB2GB0S9gZVrlJrPrEhXqU3hPKw,427
|
|
40
|
+
examples/pinecone_example/basic.py,sha256=258a5EGyLXLCu_xnLl4iROhNjUrYULwnKS3wxTlZhFs,1486
|
|
40
41
|
examples/qdrant_example/__init__.py,sha256=Ze9xEzW8FiHUO58YBa8JeHNOwcmo3dpYH77AkdyglKU,197
|
|
41
42
|
examples/qdrant_example/basic.py,sha256=DCMjHSuBZKkhEjCkwy5d5La9WMyW0lCWqtcZWiFCEm4,1425
|
|
42
43
|
examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56snk-Bbg2Kw,618
|
|
43
44
|
examples/weaviate_example/query_text.py,sha256=qz9o-fTDzX5AW5m8BJF-TfmBdokxh492NfnmnPUMU3s,64814
|
|
44
|
-
langtrace_python_sdk/__init__.py,sha256=
|
|
45
|
+
langtrace_python_sdk/__init__.py,sha256=hUX84VxREzgdjXOc3ysDzQWkqnrPm0kevW6Mb9lc2vc,1162
|
|
45
46
|
langtrace_python_sdk/langtrace.py,sha256=pN-xJRXrtvJIenMOH0-xlNXcnqL9qMjg28SrW-PMRU0,6978
|
|
46
|
-
langtrace_python_sdk/version.py,sha256=
|
|
47
|
+
langtrace_python_sdk/version.py,sha256=ybQ-f3O4pW9SYci30ZzNDlbiqsMBjSInaZ-GHWegI1I,23
|
|
47
48
|
langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
|
|
48
49
|
langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
|
|
49
50
|
langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -58,6 +59,7 @@ langtrace_python_sdk/constants/instrumentation/qdrant.py,sha256=yL7BopNQTXW7L7Z-
|
|
|
58
59
|
langtrace_python_sdk/constants/instrumentation/weaviate.py,sha256=Iytf2OpB_irZYEmvOQ7Pf483EdG5Bh59GxaBlXck0yY,1501
|
|
59
60
|
langtrace_python_sdk/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
60
61
|
langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=gWVRU2DlB4xjZ4ww7M63DaLiAN5zQ2k1HPrythmjEdo,4202
|
|
62
|
+
langtrace_python_sdk/extensions/langtrace_filesystem.py,sha256=sqsiw0PhD1mlvwYTk4Bg9MlXt8CXUZ00vtRU3nYgktE,6492
|
|
61
63
|
langtrace_python_sdk/instrumentation/__init__.py,sha256=htP583cfv32IUvWeck6edRiPQxhk0uzUa1l1vgbtjtY,1042
|
|
62
64
|
langtrace_python_sdk/instrumentation/anthropic/__init__.py,sha256=donrurJAGYlxrSRA3BIf76jGeUcAx9Tq8CVpah68S0Y,101
|
|
63
65
|
langtrace_python_sdk/instrumentation/anthropic/instrumentation.py,sha256=-srgE8qumAn0ulQYZxMa8ch-9IBH0XgBW_rfEnGk6LI,1684
|
|
@@ -106,7 +108,7 @@ langtrace_python_sdk/utils/prompt_registry.py,sha256=-BNHX_UPAqBG1IdNUXZIA669M59
|
|
|
106
108
|
langtrace_python_sdk/utils/sdk_version_checker.py,sha256=FzjIWZjn53cX0LEVPdipQd1fO9lG8iGVUEVUs9Hyk6M,1713
|
|
107
109
|
langtrace_python_sdk/utils/silently_fail.py,sha256=F_9EteXCO9Cyq-8MA1OT2Zy_dx8n06nt31I7t7ui24E,478
|
|
108
110
|
langtrace_python_sdk/utils/types.py,sha256=l-N6o7cnWUyrD6dBvW7W3Pf5CkPo5QaoT__k1XLbrQg,383
|
|
109
|
-
langtrace_python_sdk/utils/with_root_span.py,sha256=
|
|
111
|
+
langtrace_python_sdk/utils/with_root_span.py,sha256=IPosE45Ef4jsfsHzW8cFiBPp5B64G4aBHUCU2_R4REc,7239
|
|
110
112
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
111
113
|
tests/conftest.py,sha256=0Jo6iCZTXbdvyJVhG9UpYGkLabL75378oauCzmt-Sa8,603
|
|
112
114
|
tests/utils.py,sha256=hP8sTH-M8WO6zlLkSFHPf6483ZcKEcnxul6JIIb1pLM,1396
|
|
@@ -143,7 +145,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
|
|
|
143
145
|
tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
|
|
144
146
|
tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
|
|
145
147
|
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.
|
|
148
|
+
langtrace_python_sdk-2.1.17.dist-info/METADATA,sha256=4Q1qZDw4DfVGKtM6ka2kZNEYJJkdC-b3OHZZdwMvTK4,13123
|
|
149
|
+
langtrace_python_sdk-2.1.17.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
|
150
|
+
langtrace_python_sdk-2.1.17.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
|
|
151
|
+
langtrace_python_sdk-2.1.17.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
152
|
+
langtrace_python_sdk-2.1.17.dist-info/RECORD,,
|
|
File without changes
|
{langtrace_python_sdk-2.1.15.dist-info → langtrace_python_sdk-2.1.17.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|