openlit 1.25.0__py3-none-any.whl → 1.26.0__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
@@ -2,6 +2,7 @@
2
2
  """
3
3
  This module has functions to calculate model costs based on tokens and to fetch pricing information.
4
4
  """
5
+ import os
5
6
  import json
6
7
  import logging
7
8
  from urllib.parse import urlparse
@@ -12,6 +13,19 @@ from opentelemetry.trace import Status, StatusCode
12
13
  # Set up logging
13
14
  logger = logging.getLogger(__name__)
14
15
 
16
+ def get_env_variable(name, arg_value, error_message):
17
+ """
18
+ Retrieve an environment variable if the argument is not provided
19
+ and raise an error if both are not set.
20
+ """
21
+ if arg_value is not None:
22
+ return arg_value
23
+ value = os.getenv(name)
24
+ if not value:
25
+ logging.error(error_message)
26
+ raise RuntimeError(error_message)
27
+ return value
28
+
15
29
  def openai_tokens(text, model):
16
30
  """
17
31
  Calculate the number of tokens a given text would take up for a specified model.
openlit/__init__.py CHANGED
@@ -20,7 +20,7 @@ from opentelemetry.trace import SpanKind, Status, StatusCode, Span
20
20
  from openlit.semcov import SemanticConvetion
21
21
  from openlit.otel.tracing import setup_tracing
22
22
  from openlit.otel.metrics import setup_meter
23
- from openlit.__helpers import fetch_pricing_info
23
+ from openlit.__helpers import fetch_pricing_info, get_env_variable
24
24
 
25
25
 
26
26
  # Instrumentors for various large language models.
@@ -324,19 +324,6 @@ def get_prompt(url=None, name=None, api_key=None, prompt_id=None,
324
324
  Retrieve and returns the prompt from OpenLIT Prompt Hub
325
325
  """
326
326
 
327
- def get_env_variable(name, arg_value, error_message):
328
- """
329
- Retrieve an environment variable if the argument is not provided
330
- and raise an error if both are not set.
331
- """
332
- if arg_value is not None:
333
- return arg_value
334
- value = os.getenv(name)
335
- if not value:
336
- logging.error(error_message)
337
- raise RuntimeError(error_message)
338
- return value
339
-
340
327
  # Validate and set the base URL
341
328
  url = get_env_variable(
342
329
  'OPENLIT_URL',
@@ -386,6 +373,63 @@ def get_prompt(url=None, name=None, api_key=None, prompt_id=None,
386
373
  print(f"Error fetching prompt: {error}")
387
374
  return None
388
375
 
376
+ def get_secrets(url=None, api_key=None, key=None, tags=None, should_set_env=None):
377
+ """
378
+ Retrieve & returns the secrets from OpenLIT Vault & sets all to env is should_set_env is True
379
+ """
380
+
381
+ # Validate and set the base URL
382
+ url = get_env_variable(
383
+ 'OPENLIT_URL',
384
+ url,
385
+ 'Missing OpenLIT URL: Provide as arg or set OPENLIT_URL env var.'
386
+ )
387
+
388
+ # Validate and set the API key
389
+ api_key = get_env_variable(
390
+ 'OPENLIT_API_KEY',
391
+ api_key,
392
+ 'Missing API key: Provide as arg or set OPENLIT_API_KEY env var.'
393
+ )
394
+
395
+ # Construct the API endpoint
396
+ endpoint = url + "/api/vault/get-secrets"
397
+
398
+ # Prepare the payload
399
+ payload = {
400
+ 'key': key,
401
+ 'tags': tags,
402
+ }
403
+
404
+ # Remove None values from payload
405
+ payload = {k: v for k, v in payload.items() if v is not None}
406
+
407
+ # Prepare headers
408
+ headers = {
409
+ 'Authorization': f'Bearer {api_key}',
410
+ 'Content-Type': 'application/json'
411
+ }
412
+
413
+ try:
414
+ # Make the POST request to the API with headers
415
+ response = requests.post(endpoint, json=payload, headers=headers, timeout=120)
416
+
417
+ # Check if the response is successful
418
+ response.raise_for_status()
419
+
420
+ # Return the JSON response
421
+ vault_response = response.json()
422
+
423
+ res = vault_response.get('res', [])
424
+
425
+ if should_set_env is True:
426
+ for token, value in res.items():
427
+ os.environ[token] = str(value)
428
+ return vault_response
429
+ except requests.RequestException as error:
430
+ print(f"Error fetching secrets: {error}")
431
+ return None
432
+
389
433
  def trace(wrapped):
390
434
  """
391
435
  Generates a telemetry wrapper for messages to collect metrics.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.25.0
3
+ Version: 1.26.0
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
  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,gpu
@@ -173,7 +173,7 @@ To send telemetry to OpenTelemetry backends requiring authentication, set the `o
173
173
  ### Step 3: Visualize and Optimize!
174
174
  With the LLM Observability data now being collected and sent to OpenLIT, the next step is to visualize and analyze this data to get insights into your LLM application’s performance, behavior, and identify areas of improvement.
175
175
 
176
- To begin exploring your LLM Application's performance data within the OpenLIT UI, please see the [Quickstart Guide](https://docs.openlit.io/latest/quickstart).
176
+ To begin exploring your LLM Application's performance data within the OpenLIT, please see the [Quickstart Guide](https://docs.openlit.io/latest/quickstart).
177
177
 
178
178
  If you want to integrate and send metrics and traces to your existing observability tools, refer to our [Connections Guide](https://docs.openlit.io/latest/connections/intro) for detailed instructions.
179
179
 
@@ -1,5 +1,5 @@
1
- openlit/__helpers.py,sha256=lrn4PBs9owDudiCY2NBoVbAi7AU_HtUpyOj0oqPBsPY,5545
2
- openlit/__init__.py,sha256=1odqNlSQmcvrkf9IMPGuM8w0wCj3NneF_0lqq2VxS0s,18083
1
+ openlit/__helpers.py,sha256=H-8uJKs_CP9Y2HL4lz5n0AgN60wwZ675hlWHMDO143A,5936
2
+ openlit/__init__.py,sha256=MMQriKcROfw0DBBC3FdHbOKI--9tq-ZM0pY6UsQvjGk,19287
3
3
  openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
4
4
  openlit/instrumentation/anthropic/anthropic.py,sha256=y7CEGhKOGHWt8G_5Phr4qPJTfPGRJIAr9Yk6nM3CcvM,16775
5
5
  openlit/instrumentation/anthropic/async_anthropic.py,sha256=Zz1KRKIG9wGn0quOoLvjORC-49IvHQpJ6GBdB-4PfCQ,16816
@@ -59,7 +59,7 @@ openlit/instrumentation/vllm/vllm.py,sha256=lDzM7F5pgxvh8nKL0dcKB4TD0Mc9wXOWeXOs
59
59
  openlit/otel/metrics.py,sha256=-PntPlH4xOBXgnDqgJp3iA7rh1TWxM7PudGnb0GxVDA,4298
60
60
  openlit/otel/tracing.py,sha256=2kSj7n7uXSkRegcGFDC8IbnDOxqWTA8dGODs__Yn_yA,3719
61
61
  openlit/semcov/__init__.py,sha256=wpAarrnkndbgvP8VSudi8IRInYtD02hkewqjyiC0dMk,7614
62
- openlit-1.25.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
63
- openlit-1.25.0.dist-info/METADATA,sha256=Ak-Pi2g2GMv7O0UV2O7BLnw3IdPlzOzVITQBN_vDOf0,15761
64
- openlit-1.25.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
65
- openlit-1.25.0.dist-info/RECORD,,
62
+ openlit-1.26.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
63
+ openlit-1.26.0.dist-info/METADATA,sha256=YRmexsUEdSEe5MBZu8IR6u6s4XMzi2TSJGw1Z7CMCgQ,15758
64
+ openlit-1.26.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
65
+ openlit-1.26.0.dist-info/RECORD,,