langtrace-python-sdk 2.1.29__py3-none-any.whl → 2.2.2__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.
Files changed (58) hide show
  1. examples/cohere_example/chat.py +1 -0
  2. examples/cohere_example/chat_stream.py +3 -0
  3. examples/dspy_example/math_problems_cot_parallel.py +59 -0
  4. examples/gemini_example/__init__.py +6 -0
  5. examples/gemini_example/function_tools.py +62 -0
  6. examples/gemini_example/main.py +91 -0
  7. examples/langchain_example/__init__.py +8 -0
  8. examples/langchain_example/groq_example.py +28 -15
  9. examples/ollama_example/basic.py +1 -0
  10. examples/openai_example/__init__.py +1 -0
  11. examples/openai_example/async_tool_calling_nonstreaming.py +1 -1
  12. examples/openai_example/chat_completion.py +1 -1
  13. examples/openai_example/embeddings_create.py +1 -0
  14. examples/openai_example/images_edit.py +2 -2
  15. examples/vertexai_example/__init__.py +6 -0
  16. examples/vertexai_example/main.py +214 -0
  17. langtrace_python_sdk/constants/instrumentation/common.py +2 -0
  18. langtrace_python_sdk/constants/instrumentation/gemini.py +12 -0
  19. langtrace_python_sdk/constants/instrumentation/vertexai.py +42 -0
  20. langtrace_python_sdk/instrumentation/__init__.py +4 -0
  21. langtrace_python_sdk/instrumentation/anthropic/patch.py +68 -96
  22. langtrace_python_sdk/instrumentation/chroma/patch.py +29 -29
  23. langtrace_python_sdk/instrumentation/cohere/patch.py +143 -242
  24. langtrace_python_sdk/instrumentation/dspy/instrumentation.py +2 -2
  25. langtrace_python_sdk/instrumentation/dspy/patch.py +36 -36
  26. langtrace_python_sdk/instrumentation/gemini/__init__.py +3 -0
  27. langtrace_python_sdk/instrumentation/gemini/instrumentation.py +36 -0
  28. langtrace_python_sdk/instrumentation/gemini/patch.py +186 -0
  29. langtrace_python_sdk/instrumentation/groq/patch.py +82 -125
  30. langtrace_python_sdk/instrumentation/ollama/patch.py +62 -65
  31. langtrace_python_sdk/instrumentation/openai/patch.py +190 -494
  32. langtrace_python_sdk/instrumentation/qdrant/patch.py +6 -6
  33. langtrace_python_sdk/instrumentation/vertexai/__init__.py +3 -0
  34. langtrace_python_sdk/instrumentation/vertexai/instrumentation.py +33 -0
  35. langtrace_python_sdk/instrumentation/vertexai/patch.py +131 -0
  36. langtrace_python_sdk/langtrace.py +5 -0
  37. langtrace_python_sdk/utils/__init__.py +14 -3
  38. langtrace_python_sdk/utils/llm.py +311 -6
  39. langtrace_python_sdk/version.py +1 -1
  40. {langtrace_python_sdk-2.1.29.dist-info → langtrace_python_sdk-2.2.2.dist-info}/METADATA +26 -19
  41. {langtrace_python_sdk-2.1.29.dist-info → langtrace_python_sdk-2.2.2.dist-info}/RECORD +58 -38
  42. tests/anthropic/test_anthropic.py +28 -27
  43. tests/cohere/test_cohere_chat.py +36 -36
  44. tests/cohere/test_cohere_embed.py +12 -9
  45. tests/cohere/test_cohere_rerank.py +18 -11
  46. tests/groq/cassettes/test_async_chat_completion.yaml +113 -0
  47. tests/groq/cassettes/test_async_chat_completion_streaming.yaml +2232 -0
  48. tests/groq/cassettes/test_chat_completion.yaml +114 -0
  49. tests/groq/cassettes/test_chat_completion_streaming.yaml +2512 -0
  50. tests/groq/conftest.py +33 -0
  51. tests/groq/test_groq.py +142 -0
  52. tests/openai/cassettes/test_async_chat_completion_streaming.yaml +28 -28
  53. tests/openai/test_chat_completion.py +53 -67
  54. tests/openai/test_image_generation.py +47 -24
  55. tests/utils.py +40 -5
  56. {langtrace_python_sdk-2.1.29.dist-info → langtrace_python_sdk-2.2.2.dist-info}/WHEEL +0 -0
  57. {langtrace_python_sdk-2.1.29.dist-info → langtrace_python_sdk-2.2.2.dist-info}/entry_points.txt +0 -0
  58. {langtrace_python_sdk-2.1.29.dist-info → langtrace_python_sdk-2.2.2.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
- tokens = json.loads(attributes.get("llm.token.counts"))
26
- output_tokens = tokens.get("output_tokens")
27
- prompt_tokens = tokens.get("input_tokens")
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
- langtrace_responses = json.loads(attributes.get("llm.responses"))
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