langtrace-python-sdk 2.2.21__tar.gz → 2.2.23__tar.gz

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 (211) hide show
  1. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/PKG-INFO +1 -1
  2. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/extensions/langtrace_exporter.py +12 -7
  3. langtrace_python_sdk-2.2.23/src/langtrace_python_sdk/instrumentation/ollama/patch.py +157 -0
  4. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/langtrace.py +6 -1
  5. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/llm.py +11 -2
  6. langtrace_python_sdk-2.2.23/src/langtrace_python_sdk/version.py +1 -0
  7. langtrace_python_sdk-2.2.21/src/langtrace_python_sdk/instrumentation/ollama/patch.py +0 -224
  8. langtrace_python_sdk-2.2.21/src/langtrace_python_sdk/version.py +0 -1
  9. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/.gitignore +0 -0
  10. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/LICENSE +0 -0
  11. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/README.md +0 -0
  12. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/pyproject.toml +0 -0
  13. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/__init__.py +0 -0
  14. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/__init__.py +0 -0
  15. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/anthropic_example/__init__.py +0 -0
  16. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/anthropic_example/completion.py +0 -0
  17. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/chroma_example/__init__.py +0 -0
  18. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/chroma_example/basic.py +0 -0
  19. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/cohere_example/__init__.py +0 -0
  20. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/cohere_example/chat.py +0 -0
  21. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/cohere_example/chat_stream.py +0 -0
  22. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/cohere_example/embed.py +0 -0
  23. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/cohere_example/rerank.py +0 -0
  24. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/cohere_example/tools.py +0 -0
  25. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/__init__.py +0 -0
  26. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/basic.py +0 -0
  27. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/simple_agent/__init__.py +0 -0
  28. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/simple_agent/agents.py +0 -0
  29. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/simple_agent/main.py +0 -0
  30. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/simple_agent/tasks.py +0 -0
  31. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/trip_planner/__init__.py +0 -0
  32. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/trip_planner/agents.py +0 -0
  33. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/trip_planner/main.py +0 -0
  34. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/trip_planner/tasks.py +0 -0
  35. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/trip_planner/tools/calculator.py +0 -0
  36. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/crewai_example/trip_planner/tools/search_tools.py +0 -0
  37. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/dspy_example/math_problems_cot.py +0 -0
  38. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/dspy_example/math_problems_cot_parallel.py +0 -0
  39. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/dspy_example/program_of_thought_basic.py +0 -0
  40. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/dspy_example/quiz_gen.py +0 -0
  41. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/dspy_example/react.py +0 -0
  42. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/fastapi_example/__init__.py +0 -0
  43. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/fastapi_example/basic_route.py +0 -0
  44. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/gemini_example/__init__.py +0 -0
  45. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/gemini_example/function_tools.py +0 -0
  46. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/gemini_example/main.py +0 -0
  47. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/hiveagent_example/basic.py +0 -0
  48. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/inspect_ai_example/basic_eval.py +0 -0
  49. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/langchain_example/__init__.py +0 -0
  50. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/langchain_example/basic.py +0 -0
  51. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/langchain_example/groq_example.py +0 -0
  52. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/langchain_example/langgraph_example.py +0 -0
  53. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/langchain_example/sagemaker.py +0 -0
  54. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/langchain_example/tool.py +0 -0
  55. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/llamaindex_example/__init__.py +0 -0
  56. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/llamaindex_example/agent.py +0 -0
  57. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/llamaindex_example/basic.py +0 -0
  58. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/llamaindex_example/data/abramov.txt +0 -0
  59. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/ollama_example/__init__.py +0 -0
  60. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/ollama_example/basic.py +0 -0
  61. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/__init__.py +0 -0
  62. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/async_tool_calling_nonstreaming.py +0 -0
  63. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/async_tool_calling_streaming.py +0 -0
  64. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/chat_completion.py +0 -0
  65. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/chat_completion_tool_choice.py +0 -0
  66. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/embeddings_create.py +0 -0
  67. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/function_calling.py +0 -0
  68. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/images_edit.py +0 -0
  69. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/images_generate.py +0 -0
  70. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/resources/lounge_flamingo.png +0 -0
  71. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/resources/mask.png +0 -0
  72. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/send_user_feedback.py +0 -0
  73. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/tool_calling.py +0 -0
  74. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/tool_calling_nonstreaming.py +0 -0
  75. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/openai_example/tool_calling_streaming.py +0 -0
  76. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/otlp_example/otlp_basic.py +0 -0
  77. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/otlp_example/otlp_with_langtrace.py +0 -0
  78. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/perplexity_example/basic.py +0 -0
  79. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/pinecone_example/__init__.py +0 -0
  80. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/pinecone_example/basic.py +0 -0
  81. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/qdrant_example/__init__.py +0 -0
  82. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/qdrant_example/basic.py +0 -0
  83. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/routellm_example/basic.py +0 -0
  84. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/vertexai_example/__init__.py +0 -0
  85. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/vertexai_example/main.py +0 -0
  86. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/weaviate_example/__init__.py +0 -0
  87. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/examples/weaviate_example/query_text.py +0 -0
  88. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/__init__.py +0 -0
  89. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/__init__.py +0 -0
  90. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/exporter/langtrace_exporter.py +0 -0
  91. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/__init__.py +0 -0
  92. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/anthropic.py +0 -0
  93. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/chroma.py +0 -0
  94. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/cohere.py +0 -0
  95. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/common.py +0 -0
  96. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/gemini.py +0 -0
  97. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/groq.py +0 -0
  98. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/ollama.py +0 -0
  99. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/openai.py +0 -0
  100. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/pinecone.py +0 -0
  101. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/qdrant.py +0 -0
  102. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/vertexai.py +0 -0
  103. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/constants/instrumentation/weaviate.py +0 -0
  104. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/extensions/__init__.py +0 -0
  105. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/extensions/langtrace_filesystem.py +0 -0
  106. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/__init__.py +0 -0
  107. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/anthropic/__init__.py +0 -0
  108. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/anthropic/instrumentation.py +0 -0
  109. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/anthropic/patch.py +0 -0
  110. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/chroma/__init__.py +0 -0
  111. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/chroma/instrumentation.py +0 -0
  112. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/chroma/patch.py +0 -0
  113. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/cohere/__init__.py +0 -0
  114. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/cohere/instrumentation.py +0 -0
  115. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/cohere/patch.py +0 -0
  116. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/crewai/__init__.py +0 -0
  117. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/crewai/instrumentation.py +0 -0
  118. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/crewai/patch.py +0 -0
  119. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/dspy/__init__.py +0 -0
  120. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/dspy/instrumentation.py +0 -0
  121. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/dspy/patch.py +0 -0
  122. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/gemini/__init__.py +0 -0
  123. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/gemini/instrumentation.py +0 -0
  124. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/gemini/patch.py +0 -0
  125. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/groq/__init__.py +0 -0
  126. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/groq/instrumentation.py +0 -0
  127. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/groq/patch.py +0 -0
  128. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain/__init__.py +0 -0
  129. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain/instrumentation.py +0 -0
  130. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain/patch.py +0 -0
  131. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain_community/__init__.py +0 -0
  132. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain_community/instrumentation.py +0 -0
  133. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain_community/patch.py +0 -0
  134. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain_core/__init__.py +0 -0
  135. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain_core/instrumentation.py +0 -0
  136. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langchain_core/patch.py +0 -0
  137. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langgraph/__init__.py +0 -0
  138. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langgraph/instrumentation.py +0 -0
  139. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/langgraph/patch.py +0 -0
  140. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/llamaindex/__init__.py +0 -0
  141. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/llamaindex/instrumentation.py +0 -0
  142. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/llamaindex/patch.py +0 -0
  143. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/ollama/__init__.py +0 -0
  144. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/ollama/instrumentation.py +0 -0
  145. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/openai/__init__.py +0 -0
  146. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/openai/instrumentation.py +0 -0
  147. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/openai/patch.py +0 -0
  148. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/pinecone/__init__.py +0 -0
  149. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/pinecone/instrumentation.py +0 -0
  150. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/pinecone/patch.py +0 -0
  151. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/qdrant/__init__.py +0 -0
  152. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/qdrant/instrumentation.py +0 -0
  153. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/qdrant/patch.py +0 -0
  154. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/vertexai/__init__.py +0 -0
  155. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/vertexai/instrumentation.py +0 -0
  156. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/vertexai/patch.py +0 -0
  157. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/weaviate/__init__.py +0 -0
  158. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/weaviate/instrumentation.py +0 -0
  159. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/instrumentation/weaviate/patch.py +0 -0
  160. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/types/__init__.py +0 -0
  161. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/__init__.py +0 -0
  162. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/langtrace_sampler.py +0 -0
  163. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/misc.py +0 -0
  164. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/prompt_registry.py +0 -0
  165. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/sdk_version_checker.py +0 -0
  166. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/silently_fail.py +0 -0
  167. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/types.py +0 -0
  168. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/langtrace_python_sdk/utils/with_root_span.py +0 -0
  169. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/run_example.py +0 -0
  170. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/__init__.py +0 -0
  171. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/anthropic/cassettes/test_anthropic.yaml +0 -0
  172. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/anthropic/cassettes/test_anthropic_streaming.yaml +0 -0
  173. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/anthropic/cassettes/test_async_anthropic_streaming.yaml +0 -0
  174. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/anthropic/conftest.py +0 -0
  175. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/anthropic/test_anthropic.py +0 -0
  176. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/chroma/conftest.py +0 -0
  177. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/chroma/test_chroma.py +0 -0
  178. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/cassettes/test_cohere_chat.yaml +0 -0
  179. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/cassettes/test_cohere_chat_streaming.yaml +0 -0
  180. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/cassettes/test_cohere_embed.yaml +0 -0
  181. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/cassettes/test_cohere_rerank.yaml +0 -0
  182. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/conftest.py +0 -0
  183. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/test_cohere_chat.py +0 -0
  184. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/test_cohere_embed.py +0 -0
  185. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/cohere/test_cohere_rerank.py +0 -0
  186. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/conftest.py +0 -0
  187. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/groq/cassettes/test_async_chat_completion.yaml +0 -0
  188. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/groq/cassettes/test_async_chat_completion_streaming.yaml +0 -0
  189. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/groq/cassettes/test_chat_completion.yaml +0 -0
  190. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/groq/cassettes/test_chat_completion_streaming.yaml +0 -0
  191. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/groq/conftest.py +0 -0
  192. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/groq/test_groq.py +0 -0
  193. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/langchain/cassettes/test_langchain.yaml +0 -0
  194. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/langchain/conftest.py +0 -0
  195. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/langchain/test_langchain.py +0 -0
  196. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/cassettes/test_async_chat_completion_streaming.yaml +0 -0
  197. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/cassettes/test_async_image_generation.yaml +0 -0
  198. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/cassettes/test_chat_completion.yaml +0 -0
  199. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/cassettes/test_chat_completion_streaming.yaml +0 -0
  200. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/cassettes/test_image_generation.yaml +0 -0
  201. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/conftest.py +0 -0
  202. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/test_chat_completion.py +0 -0
  203. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/test_embeddings.py +0 -0
  204. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/openai/test_image_generation.py +0 -0
  205. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/pinecone/cassettes/test_query.yaml +0 -0
  206. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/pinecone/cassettes/test_upsert.yaml +0 -0
  207. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/pinecone/conftest.py +0 -0
  208. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/pinecone/test_pinecone.py +0 -0
  209. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/qdrant/conftest.py +0 -0
  210. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/qdrant/test_qdrant.py +0 -0
  211. {langtrace_python_sdk-2.2.21 → langtrace_python_sdk-2.2.23}/src/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.2.21
3
+ Version: 2.2.23
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>
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import os
3
3
  import typing
4
+ import sys
4
5
 
5
6
  import requests
6
7
  from opentelemetry.sdk.trace.export import ReadableSpan, SpanExporter, SpanExportResult
@@ -49,11 +50,13 @@ class LangTraceExporter(SpanExporter):
49
50
 
50
51
  api_key: str
51
52
  api_host: str
53
+ disable_logging: bool
52
54
 
53
55
  def __init__(
54
56
  self,
55
57
  api_host,
56
58
  api_key: str = None,
59
+ disable_logging: bool = False,
57
60
  ) -> None:
58
61
  self.api_key = api_key or os.environ.get("LANGTRACE_API_KEY")
59
62
  self.api_host = (
@@ -61,6 +64,7 @@ class LangTraceExporter(SpanExporter):
61
64
  if api_host == LANGTRACE_REMOTE_URL
62
65
  else api_host
63
66
  )
67
+ self.disable_logging = disable_logging
64
68
 
65
69
  def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
66
70
  """
@@ -72,7 +76,7 @@ class LangTraceExporter(SpanExporter):
72
76
  Returns:
73
77
  The result of the export SUCCESS or FAILURE
74
78
  """
75
- if not self.api_key:
79
+ if not self.api_key and not self.disable_logging:
76
80
  print(Fore.RED)
77
81
  print(
78
82
  "Missing Langtrace API key, proceed to https://langtrace.ai to create one"
@@ -107,14 +111,15 @@ class LangTraceExporter(SpanExporter):
107
111
 
108
112
  if not response.ok:
109
113
  raise RequestException(response.text)
110
-
111
- print(
112
- Fore.GREEN + f"Exported {len(spans)} spans successfully." + Fore.RESET
113
- )
114
+ if not self.disable_logging:
115
+ print(
116
+ Fore.GREEN + f"Exported {len(spans)} spans successfully." + Fore.RESET
117
+ )
114
118
  return SpanExportResult.SUCCESS
115
119
  except RequestException as err:
116
- print(Fore.RED + "Failed to export spans.")
117
- print(Fore.RED + f"Error: {err}" + Fore.RESET)
120
+ if not self.disable_logging:
121
+ print(Fore.RED + "Failed to export spans.")
122
+ print(Fore.RED + f"Error: {err}" + Fore.RESET)
118
123
  return SpanExportResult.FAILURE
119
124
 
120
125
  def shutdown(self) -> None:
@@ -0,0 +1,157 @@
1
+ from langtrace_python_sdk.constants.instrumentation.ollama import APIS
2
+ from langtrace_python_sdk.utils import set_span_attribute
3
+ from langtrace_python_sdk.utils.llm import (
4
+ StreamWrapper,
5
+ get_extra_attributes,
6
+ get_langtrace_attributes,
7
+ get_llm_request_attributes,
8
+ get_llm_url,
9
+ get_span_name,
10
+ set_event_completion,
11
+ set_event_completion_chunk,
12
+ )
13
+ from langtrace_python_sdk.utils.silently_fail import silently_fail
14
+ from langtrace_python_sdk.constants.instrumentation.common import SERVICE_PROVIDERS
15
+ from langtrace.trace_attributes import LLMSpanAttributes, Event
16
+ from opentelemetry.trace import SpanKind
17
+ import json
18
+ from opentelemetry.trace.status import Status, StatusCode
19
+ from langtrace.trace_attributes import SpanAttributes
20
+ from opentelemetry.trace import Tracer
21
+
22
+
23
+ def generic_patch(operation_name, version, tracer: Tracer):
24
+ def traced_method(wrapped, instance, args, kwargs):
25
+ api = APIS[operation_name]
26
+ service_provider = SERVICE_PROVIDERS["OLLAMA"]
27
+ span_attributes = {
28
+ **get_langtrace_attributes(version, service_provider),
29
+ **get_llm_request_attributes(
30
+ kwargs,
31
+ prompts=kwargs.get("messages", None),
32
+ ),
33
+ **get_llm_url(instance),
34
+ SpanAttributes.LLM_PATH: api["ENDPOINT"],
35
+ SpanAttributes.LLM_RESPONSE_FORMAT: kwargs.get("format"),
36
+ **get_extra_attributes(),
37
+ }
38
+
39
+ attributes = LLMSpanAttributes(**span_attributes)
40
+
41
+ span = tracer.start_span(
42
+ name=get_span_name(f'ollama.{api["METHOD"]}'), kind=SpanKind.CLIENT
43
+ )
44
+ _set_input_attributes(span, kwargs, attributes)
45
+
46
+ try:
47
+ result = wrapped(*args, **kwargs)
48
+ if kwargs.get("stream"):
49
+ return StreamWrapper(result, span)
50
+ else:
51
+ _set_response_attributes(span, result)
52
+ return result
53
+
54
+ except Exception as err:
55
+ # Record the exception in the span
56
+ span.record_exception(err)
57
+
58
+ # Set the span status to indicate an error
59
+ span.set_status(Status(StatusCode.ERROR, str(err)))
60
+
61
+ # Reraise the exception to ensure it's not swallowed
62
+ raise
63
+
64
+ return traced_method
65
+
66
+
67
+ def ageneric_patch(operation_name, version, tracer):
68
+ async def traced_method(wrapped, instance, args, kwargs):
69
+ api = APIS[operation_name]
70
+ service_provider = SERVICE_PROVIDERS["OLLAMA"]
71
+ span_attributes = {
72
+ **get_langtrace_attributes(version, service_provider),
73
+ **get_llm_request_attributes(kwargs),
74
+ **get_llm_url(instance),
75
+ SpanAttributes.LLM_PATH: api["ENDPOINT"],
76
+ SpanAttributes.LLM_RESPONSE_FORMAT: kwargs.get("format"),
77
+ **get_extra_attributes(),
78
+ }
79
+ attributes = LLMSpanAttributes(**span_attributes)
80
+ span = tracer.start_span(
81
+ name=get_span_name(f'ollama.{api["METHOD"]}'), kind=SpanKind.CLIENT
82
+ )
83
+
84
+ _set_input_attributes(span, kwargs, attributes)
85
+ try:
86
+ result = await wrapped(*args, **kwargs)
87
+ if kwargs.get("stream"):
88
+ return StreamWrapper(span, result)
89
+ else:
90
+ _set_response_attributes(span, result)
91
+ span.end()
92
+ return result
93
+ except Exception as err:
94
+ # Record the exception in the span
95
+ span.record_exception(err)
96
+
97
+ # Set the span status to indicate an error
98
+ span.set_status(Status(StatusCode.ERROR, str(err)))
99
+
100
+ # Reraise the exception to ensure it's not swallowed
101
+ raise
102
+
103
+ return traced_method
104
+
105
+
106
+ @silently_fail
107
+ def _set_response_attributes(span, response):
108
+
109
+ input_tokens = response.get("prompt_eval_count") or 0
110
+ output_tokens = response.get("eval_count") or 0
111
+ total_tokens = input_tokens + output_tokens
112
+
113
+ if total_tokens > 0:
114
+ set_span_attribute(span, SpanAttributes.LLM_USAGE_PROMPT_TOKENS, input_tokens)
115
+ set_span_attribute(
116
+ span, SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, output_tokens
117
+ )
118
+ set_span_attribute(span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, total_tokens)
119
+
120
+ set_span_attribute(
121
+ span,
122
+ SpanAttributes.LLM_RESPONSE_FINISH_REASON,
123
+ response.get("done_reason"),
124
+ )
125
+ if "message" in response:
126
+ set_event_completion(span, [response.get("message")])
127
+
128
+ if "response" in response:
129
+ set_event_completion(
130
+ span, [{"role": "assistant", "content": response.get("response")}]
131
+ )
132
+
133
+
134
+ @silently_fail
135
+ def _set_input_attributes(span, kwargs, attributes):
136
+ options = kwargs.get("options")
137
+
138
+ for field, value in attributes.model_dump(by_alias=True).items():
139
+ set_span_attribute(span, field, value)
140
+
141
+ if "options" in kwargs:
142
+ set_span_attribute(
143
+ span,
144
+ SpanAttributes.LLM_REQUEST_TEMPERATURE,
145
+ options.get("temperature"),
146
+ )
147
+ set_span_attribute(span, SpanAttributes.LLM_REQUEST_TOP_P, options.get("top_p"))
148
+ set_span_attribute(
149
+ span,
150
+ SpanAttributes.LLM_FREQUENCY_PENALTY,
151
+ options.get("frequency_penalty"),
152
+ )
153
+ set_span_attribute(
154
+ span,
155
+ SpanAttributes.LLM_PRESENCE_PENALTY,
156
+ options.get("presence_penalty"),
157
+ )
@@ -72,7 +72,10 @@ def init(
72
72
  disable_instrumentations: Optional[DisableInstrumentations] = None,
73
73
  disable_tracing_for_functions: Optional[InstrumentationMethods] = None,
74
74
  service_name: Optional[str] = None,
75
+ disable_logging = False
75
76
  ):
77
+ if disable_logging:
78
+ sys.stdout = open(os.devnull, "w")
76
79
 
77
80
  host = (
78
81
  os.environ.get("LANGTRACE_API_HOST", None) or api_host or LANGTRACE_REMOTE_URL
@@ -90,7 +93,7 @@ def init(
90
93
  provider = TracerProvider(resource=resource, sampler=sampler)
91
94
 
92
95
  remote_write_exporter = (
93
- LangTraceExporter(api_key=api_key, api_host=host)
96
+ LangTraceExporter(api_key=api_key, api_host=host, disable_logging=disable_logging)
94
97
  if custom_remote_exporter is None
95
98
  else custom_remote_exporter
96
99
  )
@@ -146,6 +149,8 @@ def init(
146
149
  print(Fore.BLUE + "Exporting spans to Langtrace cloud.." + Fore.RESET)
147
150
  provider.add_span_processor(batch_processor_remote)
148
151
 
152
+ sys.stdout = sys.__stdout__
153
+
149
154
 
150
155
  def init_instrumentations(
151
156
  disable_instrumentations: DisableInstrumentations, all_instrumentations: dict
@@ -237,7 +237,6 @@ class StreamWrapper:
237
237
  def __init__(
238
238
  self, stream, span, prompt_tokens=0, function_call=False, tool_calls=False
239
239
  ):
240
-
241
240
  self.stream = stream
242
241
  self.span = span
243
242
  self.prompt_tokens = prompt_tokens
@@ -284,7 +283,6 @@ class StreamWrapper:
284
283
  }
285
284
  ],
286
285
  )
287
-
288
286
  self.span.set_status(StatusCode.OK)
289
287
  self.span.end()
290
288
  self._span_started = False
@@ -377,6 +375,10 @@ class StreamWrapper:
377
375
  if hasattr(chunk, "delta") and chunk.delta is not None:
378
376
  content = [chunk.delta.text] if hasattr(chunk.delta, "text") else []
379
377
 
378
+ if isinstance(chunk, dict):
379
+ if "message" in chunk:
380
+ if "content" in chunk["message"]:
381
+ content = [chunk["message"]["content"]]
380
382
  if content:
381
383
  self.result_content.append(content[0])
382
384
 
@@ -401,6 +403,13 @@ class StreamWrapper:
401
403
  self.completion_tokens = chunk.usage_metadata.candidates_token_count
402
404
  self.prompt_tokens = chunk.usage_metadata.prompt_token_count
403
405
 
406
+ # Ollama
407
+ if isinstance(chunk, dict):
408
+ if "prompt_eval_count" in chunk:
409
+ self.prompt_tokens = chunk["prompt_eval_count"]
410
+ if "eval_count" in chunk:
411
+ self.completion_tokens = chunk["eval_count"]
412
+
404
413
  def process_chunk(self, chunk):
405
414
  self.set_response_model(chunk=chunk)
406
415
  self.build_streaming_response(chunk=chunk)
@@ -0,0 +1 @@
1
+ __version__ = "2.2.23"
@@ -1,224 +0,0 @@
1
- from langtrace_python_sdk.constants.instrumentation.ollama import APIS
2
- from langtrace_python_sdk.utils import set_span_attribute
3
- from langtrace_python_sdk.utils.llm import (
4
- get_extra_attributes,
5
- get_langtrace_attributes,
6
- get_llm_request_attributes,
7
- get_llm_url,
8
- get_span_name,
9
- set_event_completion,
10
- set_event_completion_chunk,
11
- )
12
- from langtrace_python_sdk.utils.silently_fail import silently_fail
13
- from langtrace_python_sdk.constants.instrumentation.common import SERVICE_PROVIDERS
14
- from langtrace.trace_attributes import LLMSpanAttributes, Event
15
- from opentelemetry.trace import SpanKind
16
- import json
17
- from opentelemetry.trace.status import Status, StatusCode
18
- from langtrace.trace_attributes import SpanAttributes
19
-
20
-
21
- def generic_patch(operation_name, version, tracer):
22
- def traced_method(wrapped, instance, args, kwargs):
23
- api = APIS[operation_name]
24
- service_provider = SERVICE_PROVIDERS["OLLAMA"]
25
- span_attributes = {
26
- **get_langtrace_attributes(version, service_provider),
27
- **get_llm_request_attributes(
28
- kwargs,
29
- prompts=kwargs.get("messages", None),
30
- ),
31
- **get_llm_url(instance),
32
- SpanAttributes.LLM_PATH: api["ENDPOINT"],
33
- SpanAttributes.LLM_RESPONSE_FORMAT: kwargs.get("format"),
34
- **get_extra_attributes(),
35
- }
36
-
37
- attributes = LLMSpanAttributes(**span_attributes)
38
- with tracer.start_as_current_span(
39
- name=get_span_name(f'ollama.{api["METHOD"]}'), kind=SpanKind.CLIENT
40
- ) as span:
41
- _set_input_attributes(span, kwargs, attributes)
42
-
43
- try:
44
- result = wrapped(*args, **kwargs)
45
- if result:
46
- if span.is_recording():
47
-
48
- if kwargs.get("stream"):
49
- return _handle_streaming_response(
50
- span, result, api["METHOD"]
51
- )
52
-
53
- _set_response_attributes(span, result)
54
- span.set_status(Status(StatusCode.OK))
55
-
56
- span.end()
57
- return result
58
-
59
- except Exception as err:
60
- # Record the exception in the span
61
- span.record_exception(err)
62
-
63
- # Set the span status to indicate an error
64
- span.set_status(Status(StatusCode.ERROR, str(err)))
65
-
66
- # Reraise the exception to ensure it's not swallowed
67
- raise
68
-
69
- return traced_method
70
-
71
-
72
- def ageneric_patch(operation_name, version, tracer):
73
- async def traced_method(wrapped, instance, args, kwargs):
74
- api = APIS[operation_name]
75
- service_provider = SERVICE_PROVIDERS["OLLAMA"]
76
- span_attributes = {
77
- **get_langtrace_attributes(version, service_provider),
78
- **get_llm_request_attributes(kwargs),
79
- **get_llm_url(instance),
80
- SpanAttributes.LLM_PATH: api["ENDPOINT"],
81
- SpanAttributes.LLM_RESPONSE_FORMAT: kwargs.get("format"),
82
- **get_extra_attributes(),
83
- }
84
- attributes = LLMSpanAttributes(**span_attributes)
85
- with tracer.start_as_current_span(api["METHOD"], kind=SpanKind.CLIENT) as span:
86
- _set_input_attributes(span, kwargs, attributes)
87
- try:
88
- result = await wrapped(*args, **kwargs)
89
- if result:
90
- if span.is_recording():
91
- if kwargs.get("stream"):
92
- return _ahandle_streaming_response(
93
- span, result, api["METHOD"]
94
- )
95
-
96
- _set_response_attributes(span, result)
97
- span.set_status(Status(StatusCode.OK))
98
- span.end()
99
- return result
100
- except Exception as err:
101
- # Record the exception in the span
102
- span.record_exception(err)
103
-
104
- # Set the span status to indicate an error
105
- span.set_status(Status(StatusCode.ERROR, str(err)))
106
-
107
- # Reraise the exception to ensure it's not swallowed
108
- raise
109
-
110
- return traced_method
111
-
112
-
113
- @silently_fail
114
- def _set_response_attributes(span, response):
115
-
116
- input_tokens = response.get("prompt_eval_count") or 0
117
- output_tokens = response.get("eval_count") or 0
118
- total_tokens = input_tokens + output_tokens
119
-
120
- if total_tokens > 0:
121
- set_span_attribute(span, SpanAttributes.LLM_USAGE_PROMPT_TOKENS, input_tokens)
122
- set_span_attribute(
123
- span, SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, output_tokens
124
- )
125
- set_span_attribute(span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, total_tokens)
126
-
127
- set_span_attribute(
128
- span,
129
- SpanAttributes.LLM_RESPONSE_FINISH_REASON,
130
- response.get("done_reason"),
131
- )
132
- if "message" in response:
133
- set_event_completion(span, [response.get("message")])
134
-
135
- if "response" in response:
136
- set_event_completion(
137
- span, [{"role": "assistant", "content": response.get("response")}]
138
- )
139
-
140
-
141
- @silently_fail
142
- def _set_input_attributes(span, kwargs, attributes):
143
- options = kwargs.get("options")
144
-
145
- for field, value in attributes.model_dump(by_alias=True).items():
146
- set_span_attribute(span, field, value)
147
-
148
- if "options" in kwargs:
149
- set_span_attribute(
150
- span,
151
- SpanAttributes.LLM_REQUEST_TEMPERATURE,
152
- options.get("temperature"),
153
- )
154
- set_span_attribute(span, SpanAttributes.LLM_REQUEST_TOP_P, options.get("top_p"))
155
- set_span_attribute(
156
- span,
157
- SpanAttributes.LLM_FREQUENCY_PENALTY,
158
- options.get("frequency_penalty"),
159
- )
160
- set_span_attribute(
161
- span,
162
- SpanAttributes.LLM_PRESENCE_PENALTY,
163
- options.get("presence_penalty"),
164
- )
165
-
166
-
167
- def _handle_streaming_response(span, response, api):
168
- accumulated_tokens = None
169
- if api == "chat":
170
- accumulated_tokens = {"message": {"content": "", "role": ""}}
171
- if api == "completion" or api == "generate":
172
- accumulated_tokens = {"response": ""}
173
- span.add_event(Event.STREAM_START.value)
174
- try:
175
- for chunk in response:
176
- content = None
177
- if api == "chat":
178
- content = chunk["message"]["content"]
179
- accumulated_tokens["message"]["content"] += chunk["message"]["content"]
180
- accumulated_tokens["message"]["role"] = chunk["message"]["role"]
181
- if api == "generate":
182
- content = chunk["response"]
183
- accumulated_tokens["response"] += chunk["response"]
184
-
185
- set_event_completion_chunk(span, content)
186
-
187
- _set_response_attributes(span, chunk | accumulated_tokens)
188
- finally:
189
- # Finalize span after processing all chunks
190
- span.add_event(Event.STREAM_END.value)
191
- span.set_status(StatusCode.OK)
192
- span.end()
193
-
194
- return response
195
-
196
-
197
- async def _ahandle_streaming_response(span, response, api):
198
- accumulated_tokens = None
199
- if api == "chat":
200
- accumulated_tokens = {"message": {"content": "", "role": ""}}
201
- if api == "completion" or api == "generate":
202
- accumulated_tokens = {"response": ""}
203
-
204
- span.add_event(Event.STREAM_START.value)
205
- try:
206
- async for chunk in response:
207
- content = None
208
- if api == "chat":
209
- content = chunk["message"]["content"]
210
- accumulated_tokens["message"]["content"] += chunk["message"]["content"]
211
- accumulated_tokens["message"]["role"] = chunk["message"]["role"]
212
- if api == "generate":
213
- content = chunk["response"]
214
- accumulated_tokens["response"] += chunk["response"]
215
-
216
- set_event_completion_chunk(span, content)
217
- _set_response_attributes(span, chunk | accumulated_tokens)
218
- finally:
219
- # Finalize span after processing all chunks
220
- span.add_event(Event.STREAM_END.value)
221
- span.set_status(StatusCode.OK)
222
- span.end()
223
-
224
- return response
@@ -1 +0,0 @@
1
- __version__ = "2.2.21"