openlit 1.33.17__py3-none-any.whl → 1.33.19__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.
openlit/__helpers.py CHANGED
@@ -237,27 +237,21 @@ def extract_and_format_input(messages):
237
237
  them into fixed roles like 'user', 'assistant', 'system', 'tool'.
238
238
  """
239
239
 
240
- fixed_roles = ['user', 'assistant', 'system', 'tool'] # Ensure these are your fixed keys
241
- # Initialize the dictionary with fixed keys and empty structures
240
+ fixed_roles = ['user', 'assistant', 'system', 'tool', 'developer']
242
241
  formatted_messages = {role_key: {'role': '', 'content': ''} for role_key in fixed_roles}
243
242
 
244
243
  for message in messages:
245
- # Normalize the message structure
246
244
  message = response_as_dict(message)
247
245
 
248
- # Extract role and content
249
246
  role = message.get('role')
250
247
  if role not in fixed_roles:
251
- continue # Skip any role not in our predefined roles
248
+ continue
252
249
 
253
250
  content = message.get('content', '')
254
251
 
255
- # Prepare content as a string
252
+ # Prepare content as a string, handling both list and str
256
253
  if isinstance(content, list):
257
- content_str = ", ".join(
258
- f'{item.get("type", "text")}: {extract_text_from_item(item)}'
259
- for item in content
260
- )
254
+ content_str = ", ".join(str(item) for item in content)
261
255
  else:
262
256
  content_str = content
263
257
 
@@ -272,30 +266,6 @@ def extract_and_format_input(messages):
272
266
 
273
267
  return formatted_messages
274
268
 
275
- def extract_text_from_item(item):
276
- """
277
- Extract text from inpit message
278
- """
279
-
280
- #pylint: disable=no-else-return
281
- if item.get('type') == 'text':
282
- return item.get('text', '')
283
- elif item.get('type') == 'image':
284
- # Handle image content specifically checking for 'url' or 'base64'
285
- source = item.get('source', {})
286
- if isinstance(source, dict):
287
- if source.get('type') == 'base64':
288
- # Return the actual base64 data if present
289
- return source.get('data', '[Missing base64 data]')
290
- elif source.get('type') == 'url':
291
- return source.get('url', '[Missing URL]')
292
- elif item.get('type') == 'image_url':
293
- # New format: Handle the 'image_url' type
294
- image_url = item.get('image_url', {})
295
- if isinstance(image_url, dict):
296
- return image_url.get('url', '[Missing image URL]')
297
- return ''
298
-
299
269
  # To be removed one the change to log events (from span events) is complete
300
270
  def concatenate_all_contents(formatted_messages):
301
271
  """
@@ -4,13 +4,11 @@ from typing import Collection
4
4
  import importlib.metadata
5
5
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6
6
  from wrapt import wrap_function_wrapper
7
-
8
7
  from openlit.instrumentation.azure_ai_inference.azure_ai_inference import (
9
- complete, embedding
8
+ complete
10
9
  )
11
-
12
10
  from openlit.instrumentation.azure_ai_inference.async_azure_ai_inference import (
13
- async_complete, async_embedding
11
+ async_complete
14
12
  )
15
13
 
16
14
  _instruments = ('azure-ai-inference >= 1.0.0b4',)
@@ -27,6 +25,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
27
25
  application_name = kwargs.get('application_name', 'default')
28
26
  environment = kwargs.get('environment', 'default')
29
27
  tracer = kwargs.get('tracer')
28
+ event_provider = kwargs.get('event_provider')
30
29
  metrics = kwargs.get('metrics_dict')
31
30
  pricing_info = kwargs.get('pricing_info', {})
32
31
  capture_message_content = kwargs.get('capture_message_content', False)
@@ -38,15 +37,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
38
37
  'azure.ai.inference',
39
38
  'ChatCompletionsClient.complete',
40
39
  complete(version, environment, application_name,
41
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
42
- )
43
-
44
- # sync embedding
45
- wrap_function_wrapper(
46
- 'azure.ai.inference',
47
- 'EmbeddingsClient.embed',
48
- embedding(version, environment, application_name,
49
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
40
+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),
50
41
  )
51
42
 
52
43
  # async generate
@@ -54,15 +45,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
54
45
  'azure.ai.inference.aio',
55
46
  'ChatCompletionsClient.complete',
56
47
  async_complete(version, environment, application_name,
57
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
58
- )
59
-
60
- # async embedding
61
- wrap_function_wrapper(
62
- 'azure.ai.inference.aio',
63
- 'EmbeddingsClient.embed',
64
- async_embedding(version, environment, application_name,
65
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
48
+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),
66
49
  )
67
50
 
68
51
  def _uninstrument(self, **kwargs):