openlit 1.33.12__py3-none-any.whl → 1.33.14__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
@@ -7,8 +7,8 @@ import json
7
7
  import logging
8
8
  from urllib.parse import urlparse
9
9
  from typing import Any, Dict, List, Tuple
10
+ import math
10
11
  import requests
11
- import tiktoken
12
12
  from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
13
13
  from opentelemetry.trace import Status, StatusCode
14
14
  from opentelemetry._events import Event
@@ -45,28 +45,12 @@ def get_env_variable(name, arg_value, error_message):
45
45
  raise RuntimeError(error_message)
46
46
  return value
47
47
 
48
- def openai_tokens(text, model):
49
- """
50
- Calculate the number of tokens a given text would take up for a specified model.
51
- """
52
-
53
- try:
54
- encoding = tiktoken.encoding_for_model(model)
55
- except:
56
- encoding = tiktoken.get_encoding("cl100k_base")
57
-
58
- num_tokens = len(encoding.encode(text))
59
- return num_tokens
60
-
61
48
  def general_tokens(text):
62
49
  """
63
50
  Calculate the number of tokens a given text would take up.
64
51
  """
65
52
 
66
- encoding = tiktoken.get_encoding('gpt2')
67
-
68
- num_tokens = len(encoding.encode(text))
69
- return num_tokens
53
+ return math.ceil(len(text) / 2)
70
54
 
71
55
  def get_chat_model_cost(model, pricing_info, prompt_tokens, completion_tokens):
72
56
  """
@@ -1,4 +1,3 @@
1
- # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
1
  """Initializer of Auto Instrumentation of AssemblyAI Functions"""
3
2
 
4
3
  from typing import Collection
@@ -10,7 +9,7 @@ from openlit.instrumentation.assemblyai.assemblyai import (
10
9
  transcribe
11
10
  )
12
11
 
13
- _instruments = ("assemblyai >= 0.35.1",)
12
+ _instruments = ('assemblyai >= 0.35.1',)
14
13
 
15
14
  class AssemblyAIInstrumentor(BaseInstrumentor):
16
15
  """
@@ -21,21 +20,22 @@ class AssemblyAIInstrumentor(BaseInstrumentor):
21
20
  return _instruments
22
21
 
23
22
  def _instrument(self, **kwargs):
24
- application_name = kwargs.get("application_name", "default")
25
- environment = kwargs.get("environment", "default")
26
- tracer = kwargs.get("tracer")
27
- metrics = kwargs.get("metrics_dict")
28
- pricing_info = kwargs.get("pricing_info", {})
29
- capture_message_content = kwargs.get("capture_message_content", False)
30
- disable_metrics = kwargs.get("disable_metrics")
31
- version = importlib.metadata.version("assemblyai")
23
+ application_name = kwargs.get('application_name', 'default')
24
+ environment = kwargs.get('environment', 'default')
25
+ tracer = kwargs.get('tracer')
26
+ event_provider = kwargs.get('event_provider')
27
+ metrics = kwargs.get('metrics_dict')
28
+ pricing_info = kwargs.get('pricing_info', {})
29
+ capture_message_content = kwargs.get('capture_message_content', False)
30
+ disable_metrics = kwargs.get('disable_metrics')
31
+ version = importlib.metadata.version('assemblyai')
32
32
 
33
33
  # sync transcribe
34
34
  wrap_function_wrapper(
35
- "assemblyai.transcriber",
36
- "Transcriber.transcribe",
35
+ 'assemblyai.transcriber',
36
+ 'Transcriber.transcribe',
37
37
  transcribe(version, environment, application_name,
38
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
38
+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),
39
39
  )
40
40
 
41
41
  def _uninstrument(self, **kwargs):
@@ -10,7 +10,8 @@ from openlit.__helpers import (
10
10
  get_audio_model_cost,
11
11
  handle_exception,
12
12
  create_metrics_attributes,
13
- set_server_address_and_port
13
+ set_server_address_and_port,
14
+ otel_event
14
15
  )
15
16
  from openlit.semcov import SemanticConvetion
16
17
 
@@ -18,38 +19,15 @@ from openlit.semcov import SemanticConvetion
18
19
  logger = logging.getLogger(__name__)
19
20
 
20
21
  def transcribe(version, environment, application_name,
21
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
22
+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):
22
23
  """
23
- Generates a telemetry wrapper for creating speech audio to collect metrics.
24
-
25
- Args:
26
- gen_ai_endpoint: Endpoint identifier for logging and tracing.
27
- version: Version of the monitoring package.
28
- environment: Deployment environment (e.g., production, staging).
29
- application_name: Name of the application using the Assembly AI API.
30
- tracer: OpenTelemetry tracer for creating spans.
31
- pricing_info: Information used for calculating the cost of generating speech audio.
32
- capture_message_content: Flag indicating whether to trace the input text and generated audio.
33
-
34
- Returns:
35
- A function that wraps the speech audio creation method to add telemetry.
24
+ Generates a telemetry wrapper for GenAI function call
36
25
  """
37
26
 
27
+
38
28
  def wrapper(wrapped, instance, args, kwargs):
39
29
  """
40
- Wraps the 'generate' API call to add telemetry.
41
-
42
- This collects metrics such as execution time, cost, and handles errors
43
- gracefully, adding details to the trace for observability.
44
-
45
- Args:
46
- wrapped: The original 'generate' method to be wrapped.
47
- instance: The instance of the class where the original method is defined.
48
- args: Positional arguments for the 'generate' method.
49
- kwargs: Keyword arguments for the 'generate' method.
50
-
51
- Returns:
52
- The response from the original 'transcribe' method.
30
+ Wraps the GenAI function call.
53
31
  """
54
32
 
55
33
  server_address, server_port = set_server_address_and_port(instance, 'api.assemblyai.com', 443)
@@ -96,6 +74,7 @@ def transcribe(version, environment, application_name,
96
74
  span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,
97
75
  version)
98
76
 
77
+ # To be removed one the change to log events (from span events) is complete
99
78
  if capture_message_content:
100
79
  span.add_event(
101
80
  name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
@@ -110,6 +89,34 @@ def transcribe(version, environment, application_name,
110
89
  },
111
90
  )
112
91
 
92
+ input_event = otel_event(
93
+ name=SemanticConvetion.GEN_AI_USER_MESSAGE,
94
+ attributes={
95
+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_ASSEMBLYAI
96
+ },
97
+ body={
98
+ **({'content': response.audio_url} if capture_message_content else {}),
99
+ 'role': 'user'
100
+ }
101
+ )
102
+ event_provider.emit(input_event)
103
+
104
+ output_event = otel_event(
105
+ name=SemanticConvetion.GEN_AI_CHOICE,
106
+ attributes={
107
+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_ASSEMBLYAI
108
+ },
109
+ body={
110
+ 'finish_reason': 'stop',
111
+ 'index': 0,
112
+ 'message': {
113
+ **({'content': response.text} if capture_message_content else {}),
114
+ 'role': 'assistant'
115
+ }
116
+ }
117
+ )
118
+ event_provider.emit(output_event)
119
+
113
120
  span.set_status(Status(StatusCode.OK))
114
121
 
115
122
  if disable_metrics is False:
@@ -1,4 +1,3 @@
1
- # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
1
  """Initializer of Auto Instrumentation of Azure AI Inference Functions"""
3
2
 
4
3
  from typing import Collection
@@ -14,7 +13,7 @@ from openlit.instrumentation.azure_ai_inference.async_azure_ai_inference import
14
13
  async_complete, async_embedding
15
14
  )
16
15
 
17
- _instruments = ("azure-ai-inference >= 1.0.0b4",)
16
+ _instruments = ('azure-ai-inference >= 1.0.0b4',)
18
17
 
19
18
  class AzureAIInferenceInstrumentor(BaseInstrumentor):
20
19
  """
@@ -25,43 +24,43 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
25
24
  return _instruments
26
25
 
27
26
  def _instrument(self, **kwargs):
28
- application_name = kwargs.get("application_name", "default_application")
29
- environment = kwargs.get("environment", "default_environment")
30
- tracer = kwargs.get("tracer")
31
- metrics = kwargs.get("metrics_dict")
32
- pricing_info = kwargs.get("pricing_info", {})
33
- capture_message_content = kwargs.get("capture_message_content", False)
34
- disable_metrics = kwargs.get("disable_metrics")
35
- version = importlib.metadata.version("azure-ai-inference")
27
+ application_name = kwargs.get('application_name', 'default')
28
+ environment = kwargs.get('environment', 'default')
29
+ tracer = kwargs.get('tracer')
30
+ metrics = kwargs.get('metrics_dict')
31
+ pricing_info = kwargs.get('pricing_info', {})
32
+ capture_message_content = kwargs.get('capture_message_content', False)
33
+ disable_metrics = kwargs.get('disable_metrics')
34
+ version = importlib.metadata.version('azure-ai-inference')
36
35
 
37
36
  # sync generate
38
37
  wrap_function_wrapper(
39
- "azure.ai.inference",
40
- "ChatCompletionsClient.complete",
38
+ 'azure.ai.inference',
39
+ 'ChatCompletionsClient.complete',
41
40
  complete(version, environment, application_name,
42
41
  tracer, pricing_info, capture_message_content, metrics, disable_metrics),
43
42
  )
44
43
 
45
44
  # sync embedding
46
45
  wrap_function_wrapper(
47
- "azure.ai.inference",
48
- "EmbeddingsClient.embed",
46
+ 'azure.ai.inference',
47
+ 'EmbeddingsClient.embed',
49
48
  embedding(version, environment, application_name,
50
49
  tracer, pricing_info, capture_message_content, metrics, disable_metrics),
51
50
  )
52
51
 
53
52
  # async generate
54
53
  wrap_function_wrapper(
55
- "azure.ai.inference.aio",
56
- "ChatCompletionsClient.complete",
54
+ 'azure.ai.inference.aio',
55
+ 'ChatCompletionsClient.complete',
57
56
  async_complete(version, environment, application_name,
58
57
  tracer, pricing_info, capture_message_content, metrics, disable_metrics),
59
58
  )
60
59
 
61
60
  # async embedding
62
61
  wrap_function_wrapper(
63
- "azure.ai.inference.aio",
64
- "EmbeddingsClient.embed",
62
+ 'azure.ai.inference.aio',
63
+ 'EmbeddingsClient.embed',
65
64
  async_embedding(version, environment, application_name,
66
65
  tracer, pricing_info, capture_message_content, metrics, disable_metrics),
67
66
  )
@@ -11,7 +11,7 @@ from openlit.__helpers import (
11
11
  get_embed_model_cost,
12
12
  get_audio_model_cost,
13
13
  get_image_model_cost,
14
- openai_tokens,
14
+ general_tokens,
15
15
  handle_exception,
16
16
  response_as_dict,
17
17
  calculate_ttft,
@@ -151,10 +151,8 @@ def async_chat_completions(version, environment, application_name,
151
151
  request_model = self._kwargs.get("model", "gpt-4o")
152
152
 
153
153
  # Calculate tokens using input prompt and aggregated response
154
- input_tokens = openai_tokens(prompt,
155
- request_model)
156
- output_tokens = openai_tokens(self._llmresponse,
157
- request_model)
154
+ input_tokens = general_tokens(prompt)
155
+ output_tokens = general_tokens(self._llmresponse)
158
156
 
159
157
  # Calculate cost of the operation
160
158
  cost = get_chat_model_cost(request_model,
@@ -11,7 +11,7 @@ from openlit.__helpers import (
11
11
  get_embed_model_cost,
12
12
  get_audio_model_cost,
13
13
  get_image_model_cost,
14
- openai_tokens,
14
+ general_tokens,
15
15
  handle_exception,
16
16
  response_as_dict,
17
17
  calculate_ttft,
@@ -151,10 +151,8 @@ def chat_completions(version, environment, application_name,
151
151
  request_model = self._kwargs.get("model", "gpt-4o")
152
152
 
153
153
  # Calculate tokens using input prompt and aggregated response
154
- input_tokens = openai_tokens(prompt,
155
- request_model)
156
- output_tokens = openai_tokens(self._llmresponse,
157
- request_model)
154
+ input_tokens = general_tokens(prompt)
155
+ output_tokens = general_tokens(self._llmresponse)
158
156
 
159
157
  # Calculate cost of the operation
160
158
  cost = get_chat_model_cost(request_model,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: openlit
3
- Version: 1.33.12
3
+ Version: 1.33.14
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects
5
5
  License: Apache-2.0
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT,gpu
@@ -25,7 +25,6 @@ Requires-Dist: opentelemetry-sdk (>=1.27.0,<2.0.0)
25
25
  Requires-Dist: pydantic (>=2.0.0,<3.0.0)
26
26
  Requires-Dist: requests (>=2.26.0,<3.0.0)
27
27
  Requires-Dist: schedule (>=1.2.2,<2.0.0)
28
- Requires-Dist: tiktoken (>=0.7.0,<0.8.0)
29
28
  Requires-Dist: xmltodict (>=0.13.0,<0.14.0)
30
29
  Project-URL: Homepage, https://github.com/openlit/openlit/tree/main/openlit/python
31
30
  Project-URL: Repository, https://github.com/openlit/openlit/tree/main/openlit/python
@@ -1,4 +1,4 @@
1
- openlit/__helpers.py,sha256=TBFkzFFAOWLy2YjMOU--VMtQGb9kspSiJRwk4Twts3g,10675
1
+ openlit/__helpers.py,sha256=9K9nz_RunwtnFeAk591uOJZiY3J88HsYv7T2H8elHWA,10262
2
2
  openlit/__init__.py,sha256=87uE_wi6YF2FKkmVy0VLmRKeNMuJ9e6XrycIbad9T6A,23755
3
3
  openlit/evals/__init__.py,sha256=nJe99nuLo1b5rf7pt9U9BCdSDedzbVi2Fj96cgl7msM,380
4
4
  openlit/evals/all.py,sha256=oWrue3PotE-rB5WePG3MRYSA-ro6WivkclSHjYlAqGs,7154
@@ -22,12 +22,12 @@ openlit/instrumentation/anthropic/__init__.py,sha256=QEsiwdxcQDzzlVYR4_x7KTdf0-U
22
22
  openlit/instrumentation/anthropic/anthropic.py,sha256=mZbNepBzOtQBCGJCDWaVTpXukii6jjt_fgSOY1RfMoU,5147
23
23
  openlit/instrumentation/anthropic/async_anthropic.py,sha256=DBHFdGKBhnI21Tuh_430kc-Zjaq54yUvfqmCmb1EQqg,5233
24
24
  openlit/instrumentation/anthropic/utils.py,sha256=nfIOV7eTtAReNN5QN0oG6NaqftulGjbgMrALOaDHQ8A,11897
25
- openlit/instrumentation/assemblyai/__init__.py,sha256=AS6tEzcyEG7RP6bNDW_Kf4_rN-u-O1BNjJ3khX3AEUs,1565
26
- openlit/instrumentation/assemblyai/assemblyai.py,sha256=18AQ7wrigCZd9RXwNZ36mn9fc3M3p2WkAHlT_sD5M3c,6292
25
+ openlit/instrumentation/assemblyai/__init__.py,sha256=vW5ifDgwprOSsr2Xa94T8Us0Gm6ynimAPeB3a8VQKZw,1551
26
+ openlit/instrumentation/assemblyai/assemblyai.py,sha256=TJvzWXtedpRvDybbfpvHURUxndtpVBlpy1AsQHdoiwY,6393
27
27
  openlit/instrumentation/astra/__init__.py,sha256=mEHT_p4q3bl9IiXAFqutGEvw37k6CCuWbmlI9Gx3xKY,8314
28
28
  openlit/instrumentation/astra/astra.py,sha256=BHU2iaM8ihDfdyXZQZ3Hdv0sfciSOS1QEsqrLPNGnAk,12081
29
29
  openlit/instrumentation/astra/async_astra.py,sha256=rlZeU5eIM_onR7rSxMRO0VSZL_p1eLpsU7nabTgBVlo,12093
30
- openlit/instrumentation/azure_ai_inference/__init__.py,sha256=H4x-9lyEwen2Bk_Dltpd7z8RGOk1hltjjbuJBXq35HQ,2681
30
+ openlit/instrumentation/azure_ai_inference/__init__.py,sha256=T45ideMzIPWFzVhWIjalVGEBP562ESWfCA9diZAoTtw,2573
31
31
  openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py,sha256=xI0GDqKmsbSp58IHalpNvEapM_h65oGYDbe24UVyXqg,29974
32
32
  openlit/instrumentation/azure_ai_inference/azure_ai_inference.py,sha256=dgQ8GuSO-j0J6K77tcwK0mZSK3JnIdmT60kjwAV1dt8,29870
33
33
  openlit/instrumentation/bedrock/__init__.py,sha256=ZdCBjgwK92cclnbFfF90NC6AsRreom3nT3CklbM7EmM,1555
@@ -92,8 +92,8 @@ openlit/instrumentation/ollama/async_ollama.py,sha256=LhDQPy3wLyNO9JWksUEeCx-DK9
92
92
  openlit/instrumentation/ollama/ollama.py,sha256=wVyaX0quoiiCj1J3tyTiQx5Du5CmaWmt9e_lpCr7s6A,6434
93
93
  openlit/instrumentation/ollama/utils.py,sha256=zXsWNqfnZLssrcb-GNbWeZeqTKVzQb1bes8vzgl-gbQ,14549
94
94
  openlit/instrumentation/openai/__init__.py,sha256=dfgMBHd2wAT24uckVBBqTy7pzN34ESzeymKzkUy6t58,4893
95
- openlit/instrumentation/openai/async_openai.py,sha256=8-I6SMT1bFxNGLf2GW1Yfpny-lCvIcR5coKvytKL_yE,50635
96
- openlit/instrumentation/openai/openai.py,sha256=t1-9KY1CCqeRno2_gXd3PxFkWm1ySwFweno4st2T3bE,50469
95
+ openlit/instrumentation/openai/async_openai.py,sha256=DtY26K-mNXqVAIGb_md3V3nVnGzNDn82anw9qzA3RKo,50500
96
+ openlit/instrumentation/openai/openai.py,sha256=79ydZrzRDd_44_3WtZ7U68I3HMvTkKysKglyMhjPcNQ,50334
97
97
  openlit/instrumentation/phidata/__init__.py,sha256=tqls5-UI6FzbjxYgq_qqAfALhWJm8dHn2NtgqiQA4f8,1557
98
98
  openlit/instrumentation/phidata/phidata.py,sha256=-BU_g3FpGcttOt-W-QIER5qquCRORob2UFLdaOW3F_s,4819
99
99
  openlit/instrumentation/pinecone/__init__.py,sha256=0guSEPmObaZiOF8yHExpOGY-qW_egHXfZGog3rKGi8M,2596
@@ -120,7 +120,7 @@ openlit/otel/events.py,sha256=VrMjTpvnLtYRBHCiFwJojTQqqNpRCxoD4yJYeQrtPsk,3560
120
120
  openlit/otel/metrics.py,sha256=URL7gzQbnxaNQJSX7oHRa15v6xi1GFmANn-5uFNL-aY,6378
121
121
  openlit/otel/tracing.py,sha256=tjV2bEbEDPUB1Z46gE-UsJsb04sRdFrfbhIDkxViZc0,3103
122
122
  openlit/semcov/__init__.py,sha256=kUd-ZSmXkXBo-osVve4ce_XEgr0fgEN7nXxoNm7kfEQ,12798
123
- openlit-1.33.12.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
124
- openlit-1.33.12.dist-info/METADATA,sha256=t2L1uO5RcNpbAuY5qKha7WQWoB6TCT6L0sc0jG1K5cY,23512
125
- openlit-1.33.12.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
126
- openlit-1.33.12.dist-info/RECORD,,
123
+ openlit-1.33.14.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
124
+ openlit-1.33.14.dist-info/METADATA,sha256=AFPf0UID4LGiybK2NlcoSwKF2AFWx1ksMmDmbSH5uiM,23471
125
+ openlit-1.33.14.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
126
+ openlit-1.33.14.dist-info/RECORD,,