langtrace-python-sdk 2.1.28__py3-none-any.whl → 2.2.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.
- examples/cohere_example/chat.py +1 -0
- examples/cohere_example/chat_stream.py +3 -0
- examples/gemini_example/__init__.py +6 -0
- examples/gemini_example/function_tools.py +62 -0
- examples/gemini_example/main.py +91 -0
- examples/langchain_example/__init__.py +8 -0
- examples/langchain_example/groq_example.py +28 -15
- examples/ollama_example/basic.py +1 -0
- examples/openai_example/__init__.py +1 -0
- examples/openai_example/async_tool_calling_nonstreaming.py +1 -1
- examples/openai_example/chat_completion.py +1 -1
- examples/openai_example/embeddings_create.py +1 -0
- examples/openai_example/images_edit.py +2 -2
- examples/vertexai_example/__init__.py +6 -0
- examples/vertexai_example/main.py +214 -0
- langtrace_python_sdk/constants/instrumentation/common.py +2 -0
- langtrace_python_sdk/constants/instrumentation/gemini.py +12 -0
- langtrace_python_sdk/constants/instrumentation/vertexai.py +42 -0
- langtrace_python_sdk/instrumentation/__init__.py +4 -0
- langtrace_python_sdk/instrumentation/anthropic/patch.py +68 -96
- langtrace_python_sdk/instrumentation/chroma/patch.py +29 -29
- langtrace_python_sdk/instrumentation/cohere/patch.py +143 -242
- langtrace_python_sdk/instrumentation/gemini/__init__.py +3 -0
- langtrace_python_sdk/instrumentation/gemini/instrumentation.py +36 -0
- langtrace_python_sdk/instrumentation/gemini/patch.py +186 -0
- langtrace_python_sdk/instrumentation/groq/patch.py +82 -125
- langtrace_python_sdk/instrumentation/ollama/patch.py +62 -65
- langtrace_python_sdk/instrumentation/openai/patch.py +190 -494
- langtrace_python_sdk/instrumentation/qdrant/patch.py +6 -6
- langtrace_python_sdk/instrumentation/vertexai/__init__.py +3 -0
- langtrace_python_sdk/instrumentation/vertexai/instrumentation.py +33 -0
- langtrace_python_sdk/instrumentation/vertexai/patch.py +131 -0
- langtrace_python_sdk/langtrace.py +7 -1
- langtrace_python_sdk/utils/__init__.py +14 -3
- langtrace_python_sdk/utils/llm.py +311 -6
- langtrace_python_sdk/version.py +1 -1
- {langtrace_python_sdk-2.1.28.dist-info → langtrace_python_sdk-2.2.1.dist-info}/METADATA +26 -19
- {langtrace_python_sdk-2.1.28.dist-info → langtrace_python_sdk-2.2.1.dist-info}/RECORD +55 -36
- tests/anthropic/test_anthropic.py +28 -27
- tests/cohere/test_cohere_chat.py +36 -36
- tests/cohere/test_cohere_embed.py +12 -9
- tests/cohere/test_cohere_rerank.py +18 -11
- tests/groq/cassettes/test_async_chat_completion.yaml +113 -0
- tests/groq/cassettes/test_async_chat_completion_streaming.yaml +2232 -0
- tests/groq/cassettes/test_chat_completion.yaml +114 -0
- tests/groq/cassettes/test_chat_completion_streaming.yaml +2512 -0
- tests/groq/conftest.py +33 -0
- tests/groq/test_groq.py +142 -0
- tests/openai/cassettes/test_async_chat_completion_streaming.yaml +28 -28
- tests/openai/test_chat_completion.py +53 -67
- tests/openai/test_image_generation.py +47 -24
- tests/utils.py +40 -5
- {langtrace_python_sdk-2.1.28.dist-info → langtrace_python_sdk-2.2.1.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-2.1.28.dist-info → langtrace_python_sdk-2.2.1.dist-info}/entry_points.txt +0 -0
- {langtrace_python_sdk-2.1.28.dist-info → langtrace_python_sdk-2.2.1.dist-info}/licenses/LICENSE +0 -0
tests/utils.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
from unittest.mock import MagicMock, patch
|
|
2
2
|
import json
|
|
3
|
+
from langtrace.trace_attributes import SpanAttributes
|
|
4
|
+
from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME
|
|
5
|
+
from importlib_metadata import version as v
|
|
3
6
|
|
|
4
7
|
|
|
5
8
|
def common_setup(data, method_to_mock=None):
|
|
@@ -22,10 +25,9 @@ def common_setup(data, method_to_mock=None):
|
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
def assert_token_count(attributes):
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
total_tokens = tokens.get("total_tokens")
|
|
28
|
+
output_tokens = attributes.get(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS)
|
|
29
|
+
prompt_tokens = attributes.get(SpanAttributes.LLM_USAGE_PROMPT_TOKENS)
|
|
30
|
+
total_tokens = attributes.get(SpanAttributes.LLM_USAGE_TOTAL_TOKENS)
|
|
29
31
|
|
|
30
32
|
assert (
|
|
31
33
|
output_tokens is not None
|
|
@@ -36,9 +38,42 @@ def assert_token_count(attributes):
|
|
|
36
38
|
|
|
37
39
|
|
|
38
40
|
def assert_response_format(attributes):
|
|
39
|
-
|
|
41
|
+
|
|
42
|
+
langtrace_responses = json.loads(attributes.get(SpanAttributes.LLM_COMPLETIONS))
|
|
43
|
+
|
|
40
44
|
assert isinstance(langtrace_responses, list)
|
|
41
45
|
for langtrace_response in langtrace_responses:
|
|
42
46
|
assert isinstance(langtrace_response, dict)
|
|
43
47
|
assert "role" in langtrace_response
|
|
44
48
|
assert "content" in langtrace_response
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def assert_langtrace_attributes(attributes, vendor, vendor_type="llm"):
|
|
52
|
+
|
|
53
|
+
assert attributes.get(SpanAttributes.LANGTRACE_SDK_NAME) == LANGTRACE_SDK_NAME
|
|
54
|
+
assert attributes.get(SpanAttributes.LANGTRACE_SERVICE_NAME) == vendor
|
|
55
|
+
assert attributes.get(SpanAttributes.LANGTRACE_SERVICE_TYPE) == vendor_type
|
|
56
|
+
assert attributes.get(SpanAttributes.LANGTRACE_SERVICE_VERSION) == v(vendor.lower())
|
|
57
|
+
assert attributes.get(SpanAttributes.LANGTRACE_VERSION) == v(LANGTRACE_SDK_NAME)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def assert_prompt_in_events(
|
|
61
|
+
events,
|
|
62
|
+
):
|
|
63
|
+
prompt_event = list(
|
|
64
|
+
filter(lambda event: event.name == SpanAttributes.LLM_CONTENT_PROMPT, events)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
assert prompt_event
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def assert_completion_in_events(
|
|
71
|
+
events,
|
|
72
|
+
):
|
|
73
|
+
completion_event = list(
|
|
74
|
+
filter(
|
|
75
|
+
lambda event: event.name == SpanAttributes.LLM_CONTENT_COMPLETION, events
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
assert completion_event
|
|
File without changes
|
{langtrace_python_sdk-2.1.28.dist-info → langtrace_python_sdk-2.2.1.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{langtrace_python_sdk-2.1.28.dist-info → langtrace_python_sdk-2.2.1.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|