openlit 1.34.30__py3-none-any.whl → 1.34.32__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 (168) hide show
  1. openlit/__helpers.py +235 -86
  2. openlit/__init__.py +19 -14
  3. openlit/_instrumentors.py +2 -1
  4. openlit/evals/all.py +50 -21
  5. openlit/evals/bias_detection.py +47 -20
  6. openlit/evals/hallucination.py +53 -22
  7. openlit/evals/toxicity.py +50 -21
  8. openlit/evals/utils.py +54 -30
  9. openlit/guard/all.py +61 -19
  10. openlit/guard/prompt_injection.py +34 -14
  11. openlit/guard/restrict_topic.py +46 -15
  12. openlit/guard/sensitive_topic.py +34 -14
  13. openlit/guard/utils.py +58 -22
  14. openlit/instrumentation/ag2/__init__.py +113 -6
  15. openlit/instrumentation/ag2/ag2.py +459 -17
  16. openlit/instrumentation/ag2/async_ag2.py +459 -17
  17. openlit/instrumentation/ag2/utils.py +475 -31
  18. openlit/instrumentation/ai21/__init__.py +43 -14
  19. openlit/instrumentation/ai21/ai21.py +47 -21
  20. openlit/instrumentation/ai21/async_ai21.py +47 -21
  21. openlit/instrumentation/ai21/utils.py +299 -78
  22. openlit/instrumentation/anthropic/__init__.py +21 -4
  23. openlit/instrumentation/anthropic/anthropic.py +28 -17
  24. openlit/instrumentation/anthropic/async_anthropic.py +28 -17
  25. openlit/instrumentation/anthropic/utils.py +145 -35
  26. openlit/instrumentation/assemblyai/__init__.py +11 -2
  27. openlit/instrumentation/assemblyai/assemblyai.py +15 -4
  28. openlit/instrumentation/assemblyai/utils.py +120 -25
  29. openlit/instrumentation/astra/__init__.py +43 -10
  30. openlit/instrumentation/astra/astra.py +28 -5
  31. openlit/instrumentation/astra/async_astra.py +28 -5
  32. openlit/instrumentation/astra/utils.py +151 -55
  33. openlit/instrumentation/azure_ai_inference/__init__.py +43 -10
  34. openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +53 -21
  35. openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +53 -21
  36. openlit/instrumentation/azure_ai_inference/utils.py +307 -83
  37. openlit/instrumentation/bedrock/__init__.py +21 -4
  38. openlit/instrumentation/bedrock/bedrock.py +63 -25
  39. openlit/instrumentation/bedrock/utils.py +139 -30
  40. openlit/instrumentation/chroma/__init__.py +89 -16
  41. openlit/instrumentation/chroma/chroma.py +28 -6
  42. openlit/instrumentation/chroma/utils.py +167 -51
  43. openlit/instrumentation/cohere/__init__.py +63 -18
  44. openlit/instrumentation/cohere/async_cohere.py +63 -24
  45. openlit/instrumentation/cohere/cohere.py +63 -24
  46. openlit/instrumentation/cohere/utils.py +286 -73
  47. openlit/instrumentation/controlflow/__init__.py +35 -9
  48. openlit/instrumentation/controlflow/controlflow.py +66 -33
  49. openlit/instrumentation/crawl4ai/__init__.py +25 -10
  50. openlit/instrumentation/crawl4ai/async_crawl4ai.py +78 -31
  51. openlit/instrumentation/crawl4ai/crawl4ai.py +78 -31
  52. openlit/instrumentation/crewai/__init__.py +40 -15
  53. openlit/instrumentation/crewai/async_crewai.py +32 -7
  54. openlit/instrumentation/crewai/crewai.py +32 -7
  55. openlit/instrumentation/crewai/utils.py +159 -56
  56. openlit/instrumentation/dynamiq/__init__.py +46 -12
  57. openlit/instrumentation/dynamiq/dynamiq.py +74 -33
  58. openlit/instrumentation/elevenlabs/__init__.py +23 -4
  59. openlit/instrumentation/elevenlabs/async_elevenlabs.py +16 -4
  60. openlit/instrumentation/elevenlabs/elevenlabs.py +16 -4
  61. openlit/instrumentation/elevenlabs/utils.py +128 -25
  62. openlit/instrumentation/embedchain/__init__.py +11 -2
  63. openlit/instrumentation/embedchain/embedchain.py +68 -35
  64. openlit/instrumentation/firecrawl/__init__.py +24 -7
  65. openlit/instrumentation/firecrawl/firecrawl.py +46 -20
  66. openlit/instrumentation/google_ai_studio/__init__.py +45 -10
  67. openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +67 -44
  68. openlit/instrumentation/google_ai_studio/google_ai_studio.py +67 -44
  69. openlit/instrumentation/google_ai_studio/utils.py +180 -67
  70. openlit/instrumentation/gpt4all/__init__.py +22 -7
  71. openlit/instrumentation/gpt4all/gpt4all.py +67 -29
  72. openlit/instrumentation/gpt4all/utils.py +285 -61
  73. openlit/instrumentation/gpu/__init__.py +128 -47
  74. openlit/instrumentation/groq/__init__.py +21 -4
  75. openlit/instrumentation/groq/async_groq.py +33 -21
  76. openlit/instrumentation/groq/groq.py +33 -21
  77. openlit/instrumentation/groq/utils.py +192 -55
  78. openlit/instrumentation/haystack/__init__.py +70 -24
  79. openlit/instrumentation/haystack/async_haystack.py +28 -6
  80. openlit/instrumentation/haystack/haystack.py +28 -6
  81. openlit/instrumentation/haystack/utils.py +196 -74
  82. openlit/instrumentation/julep/__init__.py +69 -19
  83. openlit/instrumentation/julep/async_julep.py +53 -27
  84. openlit/instrumentation/julep/julep.py +53 -28
  85. openlit/instrumentation/langchain/__init__.py +74 -63
  86. openlit/instrumentation/langchain/callback_handler.py +1100 -0
  87. openlit/instrumentation/langchain_community/__init__.py +13 -2
  88. openlit/instrumentation/langchain_community/async_langchain_community.py +23 -5
  89. openlit/instrumentation/langchain_community/langchain_community.py +23 -5
  90. openlit/instrumentation/langchain_community/utils.py +35 -9
  91. openlit/instrumentation/letta/__init__.py +68 -15
  92. openlit/instrumentation/letta/letta.py +99 -54
  93. openlit/instrumentation/litellm/__init__.py +43 -14
  94. openlit/instrumentation/litellm/async_litellm.py +51 -26
  95. openlit/instrumentation/litellm/litellm.py +51 -26
  96. openlit/instrumentation/litellm/utils.py +304 -102
  97. openlit/instrumentation/llamaindex/__init__.py +267 -90
  98. openlit/instrumentation/llamaindex/async_llamaindex.py +28 -6
  99. openlit/instrumentation/llamaindex/llamaindex.py +28 -6
  100. openlit/instrumentation/llamaindex/utils.py +204 -91
  101. openlit/instrumentation/mem0/__init__.py +11 -2
  102. openlit/instrumentation/mem0/mem0.py +50 -29
  103. openlit/instrumentation/milvus/__init__.py +10 -2
  104. openlit/instrumentation/milvus/milvus.py +31 -6
  105. openlit/instrumentation/milvus/utils.py +166 -67
  106. openlit/instrumentation/mistral/__init__.py +63 -18
  107. openlit/instrumentation/mistral/async_mistral.py +63 -24
  108. openlit/instrumentation/mistral/mistral.py +63 -24
  109. openlit/instrumentation/mistral/utils.py +277 -69
  110. openlit/instrumentation/multion/__init__.py +69 -19
  111. openlit/instrumentation/multion/async_multion.py +57 -26
  112. openlit/instrumentation/multion/multion.py +57 -26
  113. openlit/instrumentation/ollama/__init__.py +39 -18
  114. openlit/instrumentation/ollama/async_ollama.py +57 -26
  115. openlit/instrumentation/ollama/ollama.py +57 -26
  116. openlit/instrumentation/ollama/utils.py +226 -50
  117. openlit/instrumentation/openai/__init__.py +156 -32
  118. openlit/instrumentation/openai/async_openai.py +147 -67
  119. openlit/instrumentation/openai/openai.py +150 -67
  120. openlit/instrumentation/openai/utils.py +657 -185
  121. openlit/instrumentation/openai_agents/__init__.py +5 -1
  122. openlit/instrumentation/openai_agents/processor.py +110 -90
  123. openlit/instrumentation/phidata/__init__.py +13 -5
  124. openlit/instrumentation/phidata/phidata.py +67 -32
  125. openlit/instrumentation/pinecone/__init__.py +48 -9
  126. openlit/instrumentation/pinecone/async_pinecone.py +27 -5
  127. openlit/instrumentation/pinecone/pinecone.py +27 -5
  128. openlit/instrumentation/pinecone/utils.py +153 -47
  129. openlit/instrumentation/premai/__init__.py +22 -7
  130. openlit/instrumentation/premai/premai.py +51 -26
  131. openlit/instrumentation/premai/utils.py +246 -59
  132. openlit/instrumentation/pydantic_ai/__init__.py +49 -22
  133. openlit/instrumentation/pydantic_ai/pydantic_ai.py +69 -16
  134. openlit/instrumentation/pydantic_ai/utils.py +89 -24
  135. openlit/instrumentation/qdrant/__init__.py +19 -4
  136. openlit/instrumentation/qdrant/async_qdrant.py +33 -7
  137. openlit/instrumentation/qdrant/qdrant.py +33 -7
  138. openlit/instrumentation/qdrant/utils.py +228 -93
  139. openlit/instrumentation/reka/__init__.py +23 -10
  140. openlit/instrumentation/reka/async_reka.py +17 -11
  141. openlit/instrumentation/reka/reka.py +17 -11
  142. openlit/instrumentation/reka/utils.py +138 -36
  143. openlit/instrumentation/together/__init__.py +44 -12
  144. openlit/instrumentation/together/async_together.py +50 -27
  145. openlit/instrumentation/together/together.py +50 -27
  146. openlit/instrumentation/together/utils.py +301 -71
  147. openlit/instrumentation/transformers/__init__.py +2 -1
  148. openlit/instrumentation/transformers/transformers.py +13 -3
  149. openlit/instrumentation/transformers/utils.py +139 -36
  150. openlit/instrumentation/vertexai/__init__.py +81 -16
  151. openlit/instrumentation/vertexai/async_vertexai.py +33 -15
  152. openlit/instrumentation/vertexai/utils.py +123 -27
  153. openlit/instrumentation/vertexai/vertexai.py +33 -15
  154. openlit/instrumentation/vllm/__init__.py +12 -5
  155. openlit/instrumentation/vllm/utils.py +121 -31
  156. openlit/instrumentation/vllm/vllm.py +16 -10
  157. openlit/otel/events.py +35 -10
  158. openlit/otel/metrics.py +32 -24
  159. openlit/otel/tracing.py +24 -9
  160. openlit/semcov/__init__.py +82 -6
  161. {openlit-1.34.30.dist-info → openlit-1.34.32.dist-info}/METADATA +2 -1
  162. openlit-1.34.32.dist-info/RECORD +166 -0
  163. openlit/instrumentation/langchain/async_langchain.py +0 -102
  164. openlit/instrumentation/langchain/langchain.py +0 -102
  165. openlit/instrumentation/langchain/utils.py +0 -252
  166. openlit-1.34.30.dist-info/RECORD +0 -168
  167. {openlit-1.34.30.dist-info → openlit-1.34.32.dist-info}/LICENSE +0 -0
  168. {openlit-1.34.30.dist-info → openlit-1.34.32.dist-info}/WHEEL +0 -0
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Reka OpenTelemetry instrumentation utility functions
3
3
  """
4
+
4
5
  import time
5
6
 
6
7
  from opentelemetry.trace import Status, StatusCode
@@ -14,6 +15,7 @@ from openlit.__helpers import (
14
15
  )
15
16
  from openlit.semcov import SemanticConvention
16
17
 
18
+
17
19
  def format_content(messages):
18
20
  """
19
21
  Process a list of messages to extract content.
@@ -26,8 +28,9 @@ def format_content(messages):
26
28
 
27
29
  if isinstance(content, list):
28
30
  content_str = ", ".join(
29
- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
30
- if "type" in item else f'text: {item["text"]}'
31
+ f"{item['type']}: {item['text'] if 'text' in item else item['image_url']}"
32
+ if "type" in item
33
+ else f"text: {item['text']}"
31
34
  for item in content
32
35
  )
33
36
  formatted_messages.append(f"{role}: {content_str}")
@@ -36,8 +39,18 @@ def format_content(messages):
36
39
 
37
40
  return "\n".join(formatted_messages)
38
41
 
39
- def common_chat_logic(scope, pricing_info, environment, application_name, metrics,
40
- capture_message_content, disable_metrics, version, is_stream):
42
+
43
+ def common_chat_logic(
44
+ scope,
45
+ pricing_info,
46
+ environment,
47
+ application_name,
48
+ metrics,
49
+ capture_message_content,
50
+ disable_metrics,
51
+ version,
52
+ is_stream,
53
+ ):
41
54
  """
42
55
  Process chat request and generate Telemetry
43
56
  """
@@ -48,42 +61,92 @@ def common_chat_logic(scope, pricing_info, environment, application_name, metric
48
61
  prompt = format_content(scope._kwargs.get("messages", ""))
49
62
  request_model = scope._kwargs.get("model", "reka-core-20240501")
50
63
 
51
- cost = get_chat_model_cost(request_model, pricing_info, scope._input_tokens, scope._output_tokens)
64
+ cost = get_chat_model_cost(
65
+ request_model, pricing_info, scope._input_tokens, scope._output_tokens
66
+ )
52
67
 
53
68
  # Common Span Attributes
54
- common_span_attributes(scope,
55
- SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,SemanticConvention.GEN_AI_SYSTEM_REKAAI,
56
- scope._server_address, scope._server_port, request_model, scope._response_model,
57
- environment, application_name, is_stream, scope._tbt, scope._ttft, version)
69
+ common_span_attributes(
70
+ scope,
71
+ SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
72
+ SemanticConvention.GEN_AI_SYSTEM_REKAAI,
73
+ scope._server_address,
74
+ scope._server_port,
75
+ request_model,
76
+ scope._response_model,
77
+ environment,
78
+ application_name,
79
+ is_stream,
80
+ scope._tbt,
81
+ scope._ttft,
82
+ version,
83
+ )
58
84
 
59
85
  # Span Attributes for Response parameters
60
- scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason])
61
- scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED, scope._kwargs.get("seed", ""))
62
- scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS, scope._kwargs.get("max_tokens", -1))
63
- scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY, scope._kwargs.get("presence_penalty", 0.0))
64
- scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES, scope._kwargs.get("stop", []))
65
- scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE, scope._kwargs.get("temperature", 0.4))
66
- scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_K, scope._kwargs.get("top_k", 1.0))
67
- scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P, scope._kwargs.get("top_p", 1.0))
86
+ scope._span.set_attribute(
87
+ SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason]
88
+ )
89
+ scope._span.set_attribute(
90
+ SemanticConvention.GEN_AI_REQUEST_SEED, scope._kwargs.get("seed", "")
91
+ )
92
+ scope._span.set_attribute(
93
+ SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
94
+ scope._kwargs.get("max_tokens", -1),
95
+ )
96
+ scope._span.set_attribute(
97
+ SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
98
+ scope._kwargs.get("presence_penalty", 0.0),
99
+ )
100
+ scope._span.set_attribute(
101
+ SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES, scope._kwargs.get("stop", [])
102
+ )
103
+ scope._span.set_attribute(
104
+ SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
105
+ scope._kwargs.get("temperature", 0.4),
106
+ )
107
+ scope._span.set_attribute(
108
+ SemanticConvention.GEN_AI_REQUEST_TOP_K, scope._kwargs.get("top_k", 1.0)
109
+ )
110
+ scope._span.set_attribute(
111
+ SemanticConvention.GEN_AI_REQUEST_TOP_P, scope._kwargs.get("top_p", 1.0)
112
+ )
68
113
  scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID, scope._response_id)
69
- scope._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE, "text" if isinstance(scope._llmresponse, str) else "json")
114
+ scope._span.set_attribute(
115
+ SemanticConvention.GEN_AI_OUTPUT_TYPE,
116
+ "text" if isinstance(scope._llmresponse, str) else "json",
117
+ )
70
118
 
71
119
  # Span Attributes for Cost and Tokens
72
- scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS, scope._input_tokens)
73
- scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS, scope._output_tokens)
74
- scope._span.set_attribute(SemanticConvention.GEN_AI_CLIENT_TOKEN_USAGE, scope._input_tokens + scope._output_tokens)
120
+ scope._span.set_attribute(
121
+ SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS, scope._input_tokens
122
+ )
123
+ scope._span.set_attribute(
124
+ SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS, scope._output_tokens
125
+ )
126
+ scope._span.set_attribute(
127
+ SemanticConvention.GEN_AI_CLIENT_TOKEN_USAGE,
128
+ scope._input_tokens + scope._output_tokens,
129
+ )
75
130
  scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST, cost)
76
131
 
77
132
  # Span Attributes for Tools
78
133
  if scope._tools:
79
- scope._span.set_attribute(SemanticConvention.GEN_AI_TOOL_NAME, scope._tools.get("name",""))
80
- scope._span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALL_ID, str(scope._tools.get("id","")))
81
- scope._span.set_attribute(SemanticConvention.GEN_AI_TOOL_ARGS, str(scope._tools.get("parameters","")))
134
+ scope._span.set_attribute(
135
+ SemanticConvention.GEN_AI_TOOL_NAME, scope._tools.get("name", "")
136
+ )
137
+ scope._span.set_attribute(
138
+ SemanticConvention.GEN_AI_TOOL_CALL_ID, str(scope._tools.get("id", ""))
139
+ )
140
+ scope._span.set_attribute(
141
+ SemanticConvention.GEN_AI_TOOL_ARGS, str(scope._tools.get("parameters", ""))
142
+ )
82
143
 
83
144
  # Span Attributes for Content
84
145
  if capture_message_content:
85
146
  scope._span.set_attribute(SemanticConvention.GEN_AI_CONTENT_PROMPT, prompt)
86
- scope._span.set_attribute(SemanticConvention.GEN_AI_CONTENT_COMPLETION, scope._llmresponse)
147
+ scope._span.set_attribute(
148
+ SemanticConvention.GEN_AI_CONTENT_COMPLETION, scope._llmresponse
149
+ )
87
150
 
88
151
  # To be removed one the change to span_attributes (from span events) is complete
89
152
  scope._span.add_event(
@@ -103,14 +166,42 @@ def common_chat_logic(scope, pricing_info, environment, application_name, metric
103
166
 
104
167
  # Metrics
105
168
  if not disable_metrics:
106
- record_completion_metrics(metrics, SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT, SemanticConvention.GEN_AI_SYSTEM_REKAAI,
107
- scope._server_address, scope._server_port, request_model, scope._response_model, environment,
108
- application_name, scope._start_time, scope._end_time, scope._input_tokens, scope._output_tokens,
109
- cost, scope._tbt, scope._ttft)
110
-
111
- def process_chat_response(response, request_model, pricing_info, server_port, server_address,
112
- environment, application_name, metrics, start_time, span, capture_message_content=False,
113
- disable_metrics=False, version="1.0.0", **kwargs):
169
+ record_completion_metrics(
170
+ metrics,
171
+ SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
172
+ SemanticConvention.GEN_AI_SYSTEM_REKAAI,
173
+ scope._server_address,
174
+ scope._server_port,
175
+ request_model,
176
+ scope._response_model,
177
+ environment,
178
+ application_name,
179
+ scope._start_time,
180
+ scope._end_time,
181
+ scope._input_tokens,
182
+ scope._output_tokens,
183
+ cost,
184
+ scope._tbt,
185
+ scope._ttft,
186
+ )
187
+
188
+
189
+ def process_chat_response(
190
+ response,
191
+ request_model,
192
+ pricing_info,
193
+ server_port,
194
+ server_address,
195
+ environment,
196
+ application_name,
197
+ metrics,
198
+ start_time,
199
+ span,
200
+ capture_message_content=False,
201
+ disable_metrics=False,
202
+ version="1.0.0",
203
+ **kwargs,
204
+ ):
114
205
  """
115
206
  Process chat request and generate Telemetry
116
207
  """
@@ -135,11 +226,22 @@ def process_chat_response(response, request_model, pricing_info, server_port, se
135
226
  scope._kwargs = kwargs
136
227
  scope._finish_reason = str(response_dict.get("responses")[0].get("finish_reason"))
137
228
  if scope._kwargs.get("tools"):
138
- scope._tools = response_dict.get("responses")[0].get("message").get("tool_calls")
229
+ scope._tools = (
230
+ response_dict.get("responses")[0].get("message").get("tool_calls")
231
+ )
139
232
  else:
140
233
  scope._tools = None
141
234
 
142
- common_chat_logic(scope, pricing_info, environment, application_name, metrics,
143
- capture_message_content, disable_metrics, version, is_stream=False)
235
+ common_chat_logic(
236
+ scope,
237
+ pricing_info,
238
+ environment,
239
+ application_name,
240
+ metrics,
241
+ capture_message_content,
242
+ disable_metrics,
243
+ version,
244
+ is_stream=False,
245
+ )
144
246
 
145
247
  return response
@@ -5,15 +5,15 @@ import importlib.metadata
5
5
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6
6
  from wrapt import wrap_function_wrapper
7
7
 
8
- from openlit.instrumentation.together.together import (
9
- completion, image_generate
10
- )
8
+ from openlit.instrumentation.together.together import completion, image_generate
11
9
  from openlit.instrumentation.together.async_together import (
12
- async_completion, async_image_generate
10
+ async_completion,
11
+ async_image_generate,
13
12
  )
14
13
 
15
14
  _instruments = ("together >= 1.3.5",)
16
15
 
16
+
17
17
  class TogetherInstrumentor(BaseInstrumentor):
18
18
  """
19
19
  An instrumentor for Together client library.
@@ -36,32 +36,64 @@ class TogetherInstrumentor(BaseInstrumentor):
36
36
  wrap_function_wrapper(
37
37
  "together.resources.chat.completions",
38
38
  "ChatCompletions.create",
39
- completion(version, environment, application_name,
40
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
39
+ completion(
40
+ version,
41
+ environment,
42
+ application_name,
43
+ tracer,
44
+ pricing_info,
45
+ capture_message_content,
46
+ metrics,
47
+ disable_metrics,
48
+ ),
41
49
  )
42
50
 
43
51
  # Image generate
44
52
  wrap_function_wrapper(
45
53
  "together.resources.images",
46
54
  "Images.generate",
47
- image_generate(version, environment, application_name,
48
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
55
+ image_generate(
56
+ version,
57
+ environment,
58
+ application_name,
59
+ tracer,
60
+ pricing_info,
61
+ capture_message_content,
62
+ metrics,
63
+ disable_metrics,
64
+ ),
49
65
  )
50
66
 
51
67
  # Chat completions
52
68
  wrap_function_wrapper(
53
69
  "together.resources.chat.completions",
54
70
  "AsyncChatCompletions.create",
55
- async_completion(version, environment, application_name,
56
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
71
+ async_completion(
72
+ version,
73
+ environment,
74
+ application_name,
75
+ tracer,
76
+ pricing_info,
77
+ capture_message_content,
78
+ metrics,
79
+ disable_metrics,
80
+ ),
57
81
  )
58
82
 
59
83
  # Image generate
60
84
  wrap_function_wrapper(
61
85
  "together.resources.images",
62
86
  "AsyncImages.generate",
63
- async_image_generate(version, environment, application_name,
64
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
87
+ async_image_generate(
88
+ version,
89
+ environment,
90
+ application_name,
91
+ tracer,
92
+ pricing_info,
93
+ capture_message_content,
94
+ metrics,
95
+ disable_metrics,
96
+ ),
65
97
  )
66
98
 
67
99
  def _uninstrument(self, **kwargs):
@@ -4,20 +4,26 @@ Module for monitoring Together API calls.
4
4
 
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
- from openlit.__helpers import (
8
- handle_exception,
9
- set_server_address_and_port
10
- )
7
+ from openlit.__helpers import handle_exception, set_server_address_and_port
11
8
  from openlit.instrumentation.together.utils import (
12
9
  process_chat_response,
13
10
  process_chunk,
14
11
  process_streaming_chat_response,
15
- process_image_response
12
+ process_image_response,
16
13
  )
17
14
  from openlit.semcov import SemanticConvention
18
15
 
19
- def async_completion(version, environment, application_name,
20
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
16
+
17
+ def async_completion(
18
+ version,
19
+ environment,
20
+ application_name,
21
+ tracer,
22
+ pricing_info,
23
+ capture_message_content,
24
+ metrics,
25
+ disable_metrics,
26
+ ):
21
27
  """
22
28
  Generates a telemetry wrapper for GenAI function call
23
29
  """
@@ -28,15 +34,15 @@ def async_completion(version, environment, application_name,
28
34
  """
29
35
 
30
36
  def __init__(
31
- self,
32
- wrapped,
33
- span,
34
- span_name,
35
- kwargs,
36
- server_address,
37
- server_port,
38
- **args,
39
- ):
37
+ self,
38
+ wrapped,
39
+ span,
40
+ span_name,
41
+ kwargs,
42
+ server_address,
43
+ server_port,
44
+ **args,
45
+ ):
40
46
  self.__wrapped__ = wrapped
41
47
  self._span = span
42
48
  self._span_name = span_name
@@ -78,7 +84,9 @@ def async_completion(version, environment, application_name,
78
84
  return chunk
79
85
  except StopIteration:
80
86
  try:
81
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
87
+ with tracer.start_as_current_span(
88
+ self._span_name, kind=SpanKind.CLIENT
89
+ ) as self._span:
82
90
  process_streaming_chat_response(
83
91
  self,
84
92
  pricing_info=pricing_info,
@@ -87,7 +95,7 @@ def async_completion(version, environment, application_name,
87
95
  metrics=metrics,
88
96
  capture_message_content=capture_message_content,
89
97
  disable_metrics=disable_metrics,
90
- version=version
98
+ version=version,
91
99
  )
92
100
 
93
101
  except Exception as e:
@@ -103,7 +111,9 @@ def async_completion(version, environment, application_name,
103
111
  # Check if streaming is enabled for the API call
104
112
  streaming = kwargs.get("stream", False)
105
113
 
106
- server_address, server_port = set_server_address_and_port(instance, "api.together.xyz", 443)
114
+ server_address, server_port = set_server_address_and_port(
115
+ instance, "api.together.xyz", 443
116
+ )
107
117
  request_model = kwargs.get("model", "gpt-4o")
108
118
 
109
119
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -112,11 +122,13 @@ def async_completion(version, environment, application_name,
112
122
  # Special handling for streaming response to accommodate the nature of data flow
113
123
  awaited_wrapped = await wrapped(*args, **kwargs)
114
124
  span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
115
- return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
125
+ return TracedAsyncStream(
126
+ awaited_wrapped, span, span_name, kwargs, server_address, server_port
127
+ )
116
128
 
117
129
  # Handling for non-streaming responses
118
130
  else:
119
- with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
131
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
120
132
  start_time = time.time()
121
133
  response = await wrapped(*args, **kwargs)
122
134
 
@@ -135,7 +147,7 @@ def async_completion(version, environment, application_name,
135
147
  capture_message_content=capture_message_content,
136
148
  disable_metrics=disable_metrics,
137
149
  version=version,
138
- **kwargs
150
+ **kwargs,
139
151
  )
140
152
 
141
153
  except Exception as e:
@@ -145,8 +157,17 @@ def async_completion(version, environment, application_name,
145
157
 
146
158
  return wrapper
147
159
 
148
- def async_image_generate(version, environment, application_name,
149
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
160
+
161
+ def async_image_generate(
162
+ version,
163
+ environment,
164
+ application_name,
165
+ tracer,
166
+ pricing_info,
167
+ capture_message_content,
168
+ metrics,
169
+ disable_metrics,
170
+ ):
150
171
  """
151
172
  Generates a telemetry wrapper for GenAI function call
152
173
  """
@@ -156,12 +177,14 @@ def async_image_generate(version, environment, application_name,
156
177
  Wraps the GenAI function call.
157
178
  """
158
179
 
159
- server_address, server_port = set_server_address_and_port(instance, "api.together.xyz", 443)
180
+ server_address, server_port = set_server_address_and_port(
181
+ instance, "api.together.xyz", 443
182
+ )
160
183
  request_model = kwargs.get("model", "dall-e-2")
161
184
 
162
185
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE} {request_model}"
163
186
 
164
- with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
187
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
165
188
  start_time = time.time()
166
189
  response = await wrapped(*args, **kwargs)
167
190
  end_time = time.time()
@@ -182,7 +205,7 @@ def async_image_generate(version, environment, application_name,
182
205
  capture_message_content=capture_message_content,
183
206
  disable_metrics=disable_metrics,
184
207
  version=version,
185
- **kwargs
208
+ **kwargs,
186
209
  )
187
210
 
188
211
  return response
@@ -4,20 +4,26 @@ Module for monitoring Together API calls.
4
4
 
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
- from openlit.__helpers import (
8
- handle_exception,
9
- set_server_address_and_port
10
- )
7
+ from openlit.__helpers import handle_exception, set_server_address_and_port
11
8
  from openlit.instrumentation.together.utils import (
12
9
  process_chat_response,
13
10
  process_chunk,
14
11
  process_streaming_chat_response,
15
- process_image_response
12
+ process_image_response,
16
13
  )
17
14
  from openlit.semcov import SemanticConvention
18
15
 
19
- def completion(version, environment, application_name,
20
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
16
+
17
+ def completion(
18
+ version,
19
+ environment,
20
+ application_name,
21
+ tracer,
22
+ pricing_info,
23
+ capture_message_content,
24
+ metrics,
25
+ disable_metrics,
26
+ ):
21
27
  """
22
28
  Generates a telemetry wrapper for GenAI function call
23
29
  """
@@ -28,15 +34,15 @@ def completion(version, environment, application_name,
28
34
  """
29
35
 
30
36
  def __init__(
31
- self,
32
- wrapped,
33
- span,
34
- span_name,
35
- kwargs,
36
- server_address,
37
- server_port,
38
- **args,
39
- ):
37
+ self,
38
+ wrapped,
39
+ span,
40
+ span_name,
41
+ kwargs,
42
+ server_address,
43
+ server_port,
44
+ **args,
45
+ ):
40
46
  self.__wrapped__ = wrapped
41
47
  self._span = span
42
48
  self._span_name = span_name
@@ -78,7 +84,9 @@ def completion(version, environment, application_name,
78
84
  return chunk
79
85
  except StopIteration:
80
86
  try:
81
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
87
+ with tracer.start_as_current_span(
88
+ self._span_name, kind=SpanKind.CLIENT
89
+ ) as self._span:
82
90
  process_streaming_chat_response(
83
91
  self,
84
92
  pricing_info=pricing_info,
@@ -87,7 +95,7 @@ def completion(version, environment, application_name,
87
95
  metrics=metrics,
88
96
  capture_message_content=capture_message_content,
89
97
  disable_metrics=disable_metrics,
90
- version=version
98
+ version=version,
91
99
  )
92
100
 
93
101
  except Exception as e:
@@ -103,7 +111,9 @@ def completion(version, environment, application_name,
103
111
  # Check if streaming is enabled for the API call
104
112
  streaming = kwargs.get("stream", False)
105
113
 
106
- server_address, server_port = set_server_address_and_port(instance, "api.together.xyz", 443)
114
+ server_address, server_port = set_server_address_and_port(
115
+ instance, "api.together.xyz", 443
116
+ )
107
117
  request_model = kwargs.get("model", "gpt-4o")
108
118
 
109
119
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -112,11 +122,13 @@ def completion(version, environment, application_name,
112
122
  # Special handling for streaming response to accommodate the nature of data flow
113
123
  awaited_wrapped = wrapped(*args, **kwargs)
114
124
  span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
115
- return TracedSyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
125
+ return TracedSyncStream(
126
+ awaited_wrapped, span, span_name, kwargs, server_address, server_port
127
+ )
116
128
 
117
129
  # Handling for non-streaming responses
118
130
  else:
119
- with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
131
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
120
132
  start_time = time.time()
121
133
  response = wrapped(*args, **kwargs)
122
134
 
@@ -135,7 +147,7 @@ def completion(version, environment, application_name,
135
147
  capture_message_content=capture_message_content,
136
148
  disable_metrics=disable_metrics,
137
149
  version=version,
138
- **kwargs
150
+ **kwargs,
139
151
  )
140
152
 
141
153
  except Exception as e:
@@ -145,8 +157,17 @@ def completion(version, environment, application_name,
145
157
 
146
158
  return wrapper
147
159
 
148
- def image_generate(version, environment, application_name,
149
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
160
+
161
+ def image_generate(
162
+ version,
163
+ environment,
164
+ application_name,
165
+ tracer,
166
+ pricing_info,
167
+ capture_message_content,
168
+ metrics,
169
+ disable_metrics,
170
+ ):
150
171
  """
151
172
  Generates a telemetry wrapper for GenAI function call
152
173
  """
@@ -156,12 +177,14 @@ def image_generate(version, environment, application_name,
156
177
  Wraps the GenAI function call.
157
178
  """
158
179
 
159
- server_address, server_port = set_server_address_and_port(instance, "api.together.xyz", 443)
180
+ server_address, server_port = set_server_address_and_port(
181
+ instance, "api.together.xyz", 443
182
+ )
160
183
  request_model = kwargs.get("model", "dall-e-2")
161
184
 
162
185
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE} {request_model}"
163
186
 
164
- with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
187
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
165
188
  start_time = time.time()
166
189
  response = wrapped(*args, **kwargs)
167
190
  end_time = time.time()
@@ -182,7 +205,7 @@ def image_generate(version, environment, application_name,
182
205
  capture_message_content=capture_message_content,
183
206
  disable_metrics=disable_metrics,
184
207
  version=version,
185
- **kwargs
208
+ **kwargs,
186
209
  )
187
210
 
188
211
  return response