openlit 1.18.0__py3-none-any.whl → 1.18.1__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.
@@ -6,7 +6,11 @@ Module for monitoring Ollama API calls.
6
6
  import logging
7
7
  from opentelemetry.trace import SpanKind, Status, StatusCode
8
8
  from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
- from openlit.__helpers import handle_exception, general_tokens
9
+ from openlit.__helpers import (
10
+ handle_exception,
11
+ general_tokens,
12
+ get_chat_model_cost,
13
+ get_embed_model_cost)
10
14
  from openlit.semcov import SemanticConvetion
11
15
 
12
16
  # Initialize logger for logging potential issues and operations
@@ -90,10 +94,11 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
90
94
  formatted_messages.append(f"{role}: {content}")
91
95
  prompt = "\n".join(formatted_messages)
92
96
 
93
- # Calculate cost of the operation
94
- cost = 0
95
97
  prompt_tokens = general_tokens(prompt)
96
98
  total_tokens = prompt_tokens + completion_tokens
99
+ # Calculate cost of the operation
100
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
101
+ pricing_info, prompt_tokens, completion_tokens)
97
102
 
98
103
  # Set Span attributes
99
104
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
@@ -219,11 +224,12 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
219
224
  },
220
225
  )
221
226
 
222
- # Calculate cost of the operation
223
- cost = 0
224
227
  prompt_tokens = general_tokens(prompt)
225
228
  completion_tokens = response["eval_count"]
226
229
  total_tokens = prompt_tokens + completion_tokens
230
+ # Calculate cost of the operation
231
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
232
+ pricing_info, prompt_tokens, completion_tokens)
227
233
 
228
234
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
229
235
  prompt_tokens)
@@ -331,10 +337,11 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
331
337
 
332
338
  # Handling exception ensure observability without disrupting operation
333
339
  try:
334
- # Calculate cost of the operation
335
- cost = 0
336
340
  prompt_tokens = general_tokens(kwargs.get("prompt", ""))
337
341
  total_tokens = prompt_tokens + completion_tokens
342
+ # Calculate cost of the operation
343
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
344
+ pricing_info, prompt_tokens, completion_tokens)
338
345
 
339
346
  # Set Span attributes
340
347
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
@@ -442,11 +449,12 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
442
449
  },
443
450
  )
444
451
 
445
- # Calculate cost of the operation
446
- cost = 0
447
452
  prompt_tokens = response["prompt_eval_count"]
448
453
  completion_tokens = response["eval_count"]
449
454
  total_tokens = prompt_tokens + completion_tokens
455
+ # Calculate cost of the operation
456
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
457
+ pricing_info, prompt_tokens, completion_tokens)
450
458
 
451
459
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
452
460
  prompt_tokens)
@@ -534,9 +542,10 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
534
542
  response = await wrapped(*args, **kwargs)
535
543
 
536
544
  try:
537
- # Calculate cost of the operation
538
- cost = 0
539
545
  prompt_tokens = general_tokens(kwargs.get('prompt', ""))
546
+ # Calculate cost of the operation
547
+ cost = get_embed_model_cost(kwargs.get('model', "mistral-embed"),
548
+ pricing_info, prompt_tokens)
540
549
  # Set Span attributes
541
550
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
542
551
  span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
@@ -6,7 +6,12 @@ Module for monitoring Ollama API calls.
6
6
  import logging
7
7
  from opentelemetry.trace import SpanKind, Status, StatusCode
8
8
  from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
- from openlit.__helpers import handle_exception, general_tokens
9
+ from openlit.__helpers import (
10
+ handle_exception,
11
+ general_tokens,
12
+ get_chat_model_cost,
13
+ get_embed_model_cost
14
+ )
10
15
  from openlit.semcov import SemanticConvetion
11
16
 
12
17
  # Initialize logger for logging potential issues and operations
@@ -90,10 +95,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,
90
95
  formatted_messages.append(f"{role}: {content}")
91
96
  prompt = "\n".join(formatted_messages)
92
97
 
93
- # Calculate cost of the operation
94
- cost = 0
95
98
  prompt_tokens = general_tokens(prompt)
96
99
  total_tokens = prompt_tokens + completion_tokens
100
+ # Calculate cost of the operation
101
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
102
+ pricing_info, prompt_tokens, completion_tokens)
97
103
 
98
104
  # Set Span attributes
99
105
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
@@ -219,11 +225,12 @@ def chat(gen_ai_endpoint, version, environment, application_name,
219
225
  },
220
226
  )
221
227
 
222
- # Calculate cost of the operation
223
- cost = 0
224
228
  prompt_tokens = general_tokens(prompt)
225
229
  completion_tokens = response["eval_count"]
226
230
  total_tokens = prompt_tokens + completion_tokens
231
+ # Calculate cost of the operation
232
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
233
+ pricing_info, prompt_tokens, completion_tokens)
227
234
 
228
235
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
229
236
  prompt_tokens)
@@ -331,10 +338,11 @@ def generate(gen_ai_endpoint, version, environment, application_name,
331
338
 
332
339
  # Handling exception ensure observability without disrupting operation
333
340
  try:
334
- # Calculate cost of the operation
335
- cost = 0
336
341
  prompt_tokens = general_tokens(kwargs.get("prompt", ""))
337
342
  total_tokens = prompt_tokens + completion_tokens
343
+ # Calculate cost of the operation
344
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
345
+ pricing_info, prompt_tokens, completion_tokens)
338
346
 
339
347
  # Set Span attributes
340
348
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
@@ -442,11 +450,12 @@ def generate(gen_ai_endpoint, version, environment, application_name,
442
450
  },
443
451
  )
444
452
 
445
- # Calculate cost of the operation
446
- cost = 0
447
453
  prompt_tokens = response["prompt_eval_count"]
448
454
  completion_tokens = response["eval_count"]
449
455
  total_tokens = prompt_tokens + completion_tokens
456
+ # Calculate cost of the operation
457
+ cost = get_chat_model_cost(kwargs.get("model", "llama3"),
458
+ pricing_info, prompt_tokens, completion_tokens)
450
459
 
451
460
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
452
461
  prompt_tokens)
@@ -534,9 +543,10 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
534
543
  response = wrapped(*args, **kwargs)
535
544
 
536
545
  try:
537
- # Calculate cost of the operation
538
- cost = 0
539
546
  prompt_tokens = general_tokens(kwargs.get('prompt', ""))
547
+ # Calculate cost of the operation
548
+ cost = get_embed_model_cost(kwargs.get('model', "mistral-embed"),
549
+ pricing_info, prompt_tokens)
540
550
  # Set Span attributes
541
551
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
542
552
  span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.18.0
3
+ Version: 1.18.1
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
5
5
  Home-page: https://github.com/openlit/openlit/tree/main/openlit/python
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT
@@ -32,8 +32,8 @@ openlit/instrumentation/mistral/__init__.py,sha256=zJCIpFWRbsYrvooOJYuqwyuKeSOQL
32
32
  openlit/instrumentation/mistral/async_mistral.py,sha256=WXU46nbe61IglfGehrwdprMVB6hNiuqqmJHE3XvvP0E,22192
33
33
  openlit/instrumentation/mistral/mistral.py,sha256=DC-wLIypokPEEAbVSKX5sytv94DY2QDnk12401e5vq8,22039
34
34
  openlit/instrumentation/ollama/__init__.py,sha256=cOax8PiypDuo_FC4WvDCYBRo7lH5nV9xU92h7k-eZbg,3812
35
- openlit/instrumentation/ollama/async_ollama.py,sha256=UBwl-Jv4VPyPuhKIesL0VYIQ2u1AZ0U8c9MZQzEPn6c,30594
36
- openlit/instrumentation/ollama/ollama.py,sha256=bZPgkJJUD3RgJTUUt98cklfZ8Y1lsSgQGOUXXHk53BI,30504
35
+ openlit/instrumentation/ollama/async_ollama.py,sha256=7lbikD-I9k8VL63idqj3VMEfiEKJmFNUPR8Xb6g2phQ,31366
36
+ openlit/instrumentation/ollama/ollama.py,sha256=lBt1d3rFnF1tFbfdOccwjEafHnmTAUGsiOKSHku6Fkw,31277
37
37
  openlit/instrumentation/openai/__init__.py,sha256=AZ2cPr3TMKkgGdMl_yXMeSi7bWhtmMqOW1iHdzHHGHA,16265
38
38
  openlit/instrumentation/openai/async_azure_openai.py,sha256=XbST1UE_zXzNL6RX2XwCsK_a6IhG9PHVTMKBjGrUcB0,48961
39
39
  openlit/instrumentation/openai/async_openai.py,sha256=RGNpKLsHYfJXjj1ImuWRJToVSs0wdvMNp2kyTBrBaDw,47578
@@ -53,7 +53,7 @@ openlit/instrumentation/vllm/vllm.py,sha256=lDzM7F5pgxvh8nKL0dcKB4TD0Mc9wXOWeXOs
53
53
  openlit/otel/metrics.py,sha256=O7NoaDz0bY19mqpE4-0PcKwEe-B-iJFRgOCaanAuZAc,4291
54
54
  openlit/otel/tracing.py,sha256=vL1ifMbARPBpqK--yXYsCM6y5dSu5LFIKqkhZXtYmUc,3712
55
55
  openlit/semcov/__init__.py,sha256=EvoNOKtc7UKwLZ3Gp0-B1zwmeTcAIbx8O7wvAw8wXP4,7498
56
- openlit-1.18.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
57
- openlit-1.18.0.dist-info/METADATA,sha256=LzRSgLCKr0x6Vr8YwhFkPCEuTbF_NfQtpQTpMdiXCqo,14334
58
- openlit-1.18.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
59
- openlit-1.18.0.dist-info/RECORD,,
56
+ openlit-1.18.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
57
+ openlit-1.18.1.dist-info/METADATA,sha256=l-nXpcuMqzXPGB-IiwqWhvkjq-pW4lsK_8Q5_rH3uoo,14334
58
+ openlit-1.18.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
59
+ openlit-1.18.1.dist-info/RECORD,,