langwatch 0.3.1__py3-none-any.whl → 0.4.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.
langwatch/__version__.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from functools import wraps
|
|
2
2
|
from opentelemetry import trace
|
|
3
|
-
from
|
|
3
|
+
from opentelemetry.trace import Span
|
|
4
|
+
from typing import TYPE_CHECKING, TypeVar, Callable, Any, Optional, Union, Dict
|
|
4
5
|
import json
|
|
5
6
|
|
|
6
7
|
from langwatch.attributes import AttributeKey
|
|
@@ -11,9 +12,37 @@ if TYPE_CHECKING:
|
|
|
11
12
|
T = TypeVar("T", bound="Prompt")
|
|
12
13
|
|
|
13
14
|
|
|
15
|
+
def _set_attribute_if_not_none(
|
|
16
|
+
span: Span, key: str, value: Optional[Union[str, int, float, bool]]
|
|
17
|
+
) -> None:
|
|
18
|
+
"""Set span attribute only if value is not None."""
|
|
19
|
+
if value is not None:
|
|
20
|
+
span.set_attribute(key, value)
|
|
21
|
+
|
|
22
|
+
|
|
14
23
|
class PromptTracing:
|
|
15
24
|
"""Namespace for Prompt method tracing decorators"""
|
|
16
25
|
|
|
26
|
+
@staticmethod
|
|
27
|
+
def _set_prompt_attributes(span: Span, prompt: "Prompt") -> None:
|
|
28
|
+
"""Set prompt-related attributes on the span."""
|
|
29
|
+
_set_attribute_if_not_none(
|
|
30
|
+
span, AttributeKey.LangWatchPromptId, getattr(prompt, "id", None)
|
|
31
|
+
)
|
|
32
|
+
_set_attribute_if_not_none(
|
|
33
|
+
span, AttributeKey.LangWatchPromptHandle, getattr(prompt, "handle", None)
|
|
34
|
+
)
|
|
35
|
+
_set_attribute_if_not_none(
|
|
36
|
+
span,
|
|
37
|
+
AttributeKey.LangWatchPromptVersionId,
|
|
38
|
+
getattr(prompt, "version_id", None),
|
|
39
|
+
)
|
|
40
|
+
_set_attribute_if_not_none(
|
|
41
|
+
span,
|
|
42
|
+
AttributeKey.LangWatchPromptVersionNumber,
|
|
43
|
+
getattr(prompt, "version", None),
|
|
44
|
+
)
|
|
45
|
+
|
|
17
46
|
@staticmethod
|
|
18
47
|
def _create_compile_decorator(
|
|
19
48
|
span_name: str,
|
|
@@ -28,26 +57,15 @@ class PromptTracing:
|
|
|
28
57
|
with trace.get_tracer(__name__).start_as_current_span(
|
|
29
58
|
PromptTracing._create_span_name(span_name)
|
|
30
59
|
) as span:
|
|
31
|
-
# Set
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
AttributeKey.LangWatchPromptId: getattr(self, "id", None),
|
|
35
|
-
AttributeKey.LangWatchPromptHandle: getattr(
|
|
36
|
-
self, "handle", None
|
|
37
|
-
),
|
|
38
|
-
AttributeKey.LangWatchPromptVersionId: getattr(
|
|
39
|
-
self, "version_id", None
|
|
40
|
-
),
|
|
41
|
-
AttributeKey.LangWatchPromptVersionNumber: getattr(
|
|
42
|
-
self, "version", None
|
|
43
|
-
),
|
|
44
|
-
}
|
|
45
|
-
)
|
|
60
|
+
# Set prompt attributes
|
|
61
|
+
PromptTracing._set_prompt_attributes(span, self)
|
|
46
62
|
|
|
47
63
|
# Create variables dict from args and kwargs
|
|
48
|
-
variables_dict:
|
|
49
|
-
if args
|
|
50
|
-
|
|
64
|
+
variables_dict: Dict[str, Any] = {}
|
|
65
|
+
if args:
|
|
66
|
+
first_arg = args[0]
|
|
67
|
+
if first_arg is not None and hasattr(first_arg, "update"):
|
|
68
|
+
variables_dict.update(first_arg)
|
|
51
69
|
variables_dict.update(kwargs)
|
|
52
70
|
|
|
53
71
|
span.set_attribute(
|
|
@@ -88,7 +106,7 @@ class PromptTracing:
|
|
|
88
106
|
@staticmethod
|
|
89
107
|
def _create_span_name(span_name: str) -> str:
|
|
90
108
|
"""Create a span name for the prompt"""
|
|
91
|
-
return "Prompt
|
|
109
|
+
return f"Prompt.{span_name}"
|
|
92
110
|
|
|
93
111
|
|
|
94
112
|
prompt_tracing = PromptTracing()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langwatch
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: LangWatch Python SDK, for monitoring your LLMs
|
|
5
5
|
Author-email: Langwatch Engineers <engineering@langwatch.ai>
|
|
6
6
|
License: MIT
|
|
@@ -31,6 +31,7 @@ Requires-Dist: opentelemetry-sdk>=1.32.1
|
|
|
31
31
|
Requires-Dist: pksuid>=1.1.2
|
|
32
32
|
Requires-Dist: pydantic>=2
|
|
33
33
|
Requires-Dist: python-liquid>=2.0.2
|
|
34
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
34
35
|
Requires-Dist: retry>=0.9.2
|
|
35
36
|
Requires-Dist: termcolor>=3.0.1
|
|
36
37
|
Provides-Extra: dev
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
langwatch/__init__.py,sha256=TzPHzqCFGZJByI3sAIKrNB33Qi4PqVmgYDZuBwPnhPc,4222
|
|
2
|
-
langwatch/__version__.py,sha256=
|
|
2
|
+
langwatch/__version__.py,sha256=9l3owj3_pNV7TsTQT4fmHpK6UvxlyyebOVlDH3-Xcgw,64
|
|
3
3
|
langwatch/attributes.py,sha256=nXdI_G85wQQCAdAcwjCiLYdEYj3wATmfgCmhlf6dVIk,3910
|
|
4
4
|
langwatch/batch_evaluation.py,sha256=piez7TYqUZPb9NlIShTuTPmSzrZqX-vm2Grz_NGXe04,16078
|
|
5
5
|
langwatch/client.py,sha256=WTNcYSik7kZ2kH-qGDnhbMTosc8e_Xhab_lZlfh5TC8,25559
|
|
@@ -390,7 +390,7 @@ langwatch/prompts/prompt_api_service.py,sha256=tHhwIRjUBSM43_jwDAoGCHJjvvqVeSCrU
|
|
|
390
390
|
langwatch/prompts/prompt_facade.py,sha256=47matSK4G2Ce3HWUnO13-k7jlDuZQePGCck4gkbTmXM,5052
|
|
391
391
|
langwatch/prompts/types.py,sha256=p1bRMvfCCpGGiVwzFtQijVtWl5GWugL_vBOFc4B2348,269
|
|
392
392
|
langwatch/prompts/decorators/prompt_service_tracing.py,sha256=uSYw0vExo7AuxbcCRnxbYl6UOfOQSC0IsisSqYy153Y,2395
|
|
393
|
-
langwatch/prompts/decorators/prompt_tracing.py,sha256=
|
|
393
|
+
langwatch/prompts/decorators/prompt_tracing.py,sha256=x_PQvJlGbGF1h2HtGNiqaZ8K1qNd1jRf5pTOBTQx-7M,3963
|
|
394
394
|
langwatch/prompts/types/__init__.py,sha256=uEnjOQC4LkLMWQ0fXfKe573xKOvoMdPgC6uY-yo9B_g,506
|
|
395
395
|
langwatch/prompts/types/prompt_data.py,sha256=g_EQ94-PGfa4Ptwd3e2rMqoIZiX052MEEZKyF77m9D0,3137
|
|
396
396
|
langwatch/prompts/types/structures.py,sha256=cB94bn-qhFgHHYXcrmJV6Bk9idk5ZmyfXhFNQAaXw-M,951
|
|
@@ -407,6 +407,6 @@ langwatch/utils/initialization.py,sha256=1KoZmkHOvGEVF0j-4t4xRQdA_2C_SPiF7qFXqEG
|
|
|
407
407
|
langwatch/utils/module.py,sha256=KLBNOK3mA9gCSifCcQX_lOtU48BJQDWvFKtF6NMvwVA,688
|
|
408
408
|
langwatch/utils/transformation.py,sha256=76MGXyrYTxM0Yri36NJqLK-XxL4BBYdmKWAXXlw3D4Q,7690
|
|
409
409
|
langwatch/utils/utils.py,sha256=ZCOSie4o9LdJ7odshNfCNjmgwgQ27ojc5ENqt1rXuSs,596
|
|
410
|
-
langwatch-0.
|
|
411
|
-
langwatch-0.
|
|
412
|
-
langwatch-0.
|
|
410
|
+
langwatch-0.4.1.dist-info/METADATA,sha256=OoFLwcDgnCsFrigOQCb3r6oPYa2db0pAjhjiOn3Aa8E,13152
|
|
411
|
+
langwatch-0.4.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
412
|
+
langwatch-0.4.1.dist-info/RECORD,,
|
|
File without changes
|