openlit 1.7.0__py3-none-any.whl → 1.8.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,8 +2,9 @@
2
2
  """
3
3
  This module has functions to calculate model costs based on tokens and to fetch pricing information.
4
4
  """
5
-
5
+ import json
6
6
  import logging
7
+ from urllib.parse import urlparse
7
8
  import requests
8
9
  import tiktoken
9
10
  from opentelemetry.trace import Status, StatusCode
@@ -122,11 +123,35 @@ def get_audio_model_cost(model, pricing_info, prompt):
122
123
  cost = 0
123
124
  return cost
124
125
 
125
- def fetch_pricing_info():
126
- """Fetches pricing information from a specified URL."""
127
- pricing_url = "https://raw.githubusercontent.com/openlit/openlit/main/assets/pricing.json"
126
+ def fetch_pricing_info(pricing_json=None):
127
+ """
128
+ Fetches pricing information from a specified URL or File Path.
129
+
130
+ Args:
131
+ pricing_json(str): path or url to the pricing json file
132
+
133
+ Returns:
134
+ dict: The pricing json
135
+ """
136
+ if pricing_json:
137
+ is_url = urlparse(pricing_json).scheme != ""
138
+ if is_url:
139
+ pricing_url = pricing_json
140
+ else:
141
+ try:
142
+ with open(pricing_json, mode='r', encoding='utf-8') as f:
143
+ return json.load(f)
144
+ except FileNotFoundError:
145
+ logger.error("Pricing information file not found: %s", pricing_json)
146
+ except json.JSONDecodeError:
147
+ logger.error("Error decoding JSON from file: %s", pricing_json)
148
+ except Exception as file_err:
149
+ logger.error("Unexpected error occurred while reading file: %s", file_err)
150
+ return {}
151
+ else:
152
+ pricing_url = "https://raw.githubusercontent.com/openlit/openlit/main/assets/pricing.json"
128
153
  try:
129
- # Set a timeout of 10 seconds for both the connection and the read
154
+ # Set a timeout of 10 seconds for both the connection and the read
130
155
  response = requests.get(pricing_url, timeout=20)
131
156
  response.raise_for_status()
132
157
  return response.json()
openlit/__init__.py CHANGED
@@ -75,7 +75,8 @@ class OpenlitConfig:
75
75
 
76
76
  @classmethod
77
77
  def update_config(cls, environment, application_name, tracer, otlp_endpoint,
78
- otlp_headers, disable_batch, trace_content, metrics_dict, disable_metrics):
78
+ otlp_headers, disable_batch, trace_content, metrics_dict,
79
+ disable_metrics, pricing_json):
79
80
  """
80
81
  Updates the configuration based on provided parameters.
81
82
 
@@ -88,10 +89,11 @@ class OpenlitConfig:
88
89
  otlp_headers (Dict[str, str]): OTLP headers.
89
90
  disable_batch (bool): Disable batch span processing flag.
90
91
  trace_content (bool): Enable or disable content tracing.
92
+ pricing_json(str): path or url to the pricing json file
91
93
  """
92
94
  cls.environment = environment
93
95
  cls.application_name = application_name
94
- cls.pricing_info = fetch_pricing_info()
96
+ cls.pricing_info = fetch_pricing_info(pricing_json)
95
97
  cls.tracer = tracer
96
98
  cls.metrics_dict = metrics_dict
97
99
  cls.otlp_endpoint = otlp_endpoint
@@ -126,7 +128,7 @@ def instrument_if_available(instrumentor_name, instrumentor_instance, config,
126
128
 
127
129
  def init(environment="default", application_name="default", tracer=None, otlp_endpoint=None,
128
130
  otlp_headers=None, disable_batch=False, trace_content=True, disabled_instrumentors=None,
129
- meter=None, disable_metrics=False):
131
+ meter=None, disable_metrics=False, pricing_json=None):
130
132
  """
131
133
  Initializes the openLIT configuration and setups tracing.
132
134
 
@@ -144,6 +146,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
144
146
  trace_content (bool): Flag to trace content (Optional).
145
147
  disabled_instrumentors (List[str]): Optional. List of instrumentor names to disable.
146
148
  disable_metrics (bool): Flag to disable metrics (Optional)
149
+ pricing_json(str): File path or url to the pricing json (Optional)
147
150
  """
148
151
  disabled_instrumentors = disabled_instrumentors if disabled_instrumentors else []
149
152
  # Check for invalid instrumentor names
@@ -199,7 +202,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
199
202
  # Update global configuration with the provided settings.
200
203
  config.update_config(environment, application_name, tracer, otlp_endpoint,
201
204
  otlp_headers, disable_batch, trace_content,
202
- metrics_dict, disable_metrics)
205
+ metrics_dict, disable_metrics, pricing_json)
203
206
 
204
207
  # Map instrumentor names to their instances
205
208
  instrumentor_instances = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.7.0
3
+ Version: 1.8.0
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
@@ -165,6 +165,7 @@ Below is a detailed overview of the configuration options available, allowing yo
165
165
  | `trace_content` | Enables tracing of content for deeper insights. | `True` | No |
166
166
  | `disabled_instrumentors`| List of instrumentors to disable. Choices: `["openai", "anthropic", "langchain", "cohere", "mistral", "transformers", "chroma", "pinecone"]`. | `None` | No |
167
167
  | `disable_metrics` | If set, disables the collection of metrics. | `False` | No |
168
+ | `pricing_json` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |
168
169
 
169
170
  ## 🌱 Contributing
170
171
 
@@ -183,5 +184,5 @@ Connect with the OpenLIT community and maintainers for support, discussions, and
183
184
  - 🌟 If you like it, Leave a star on our [GitHub](https://github.com/openlit/openlit/)
184
185
  - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) Community for live interactions and questions.
185
186
  - 🐞 Report bugs on our [GitHub Issues](https://github.com/openlit/openlit/issues) to help us improve OpenLIT.
186
- - 𝕏 Follow us on [X](https://twitter.com/openlit) for the latest updates and news.
187
+ - 𝕏 Follow us on [X](https://x.com/openlit_io) for the latest updates and news.
187
188
 
@@ -1,5 +1,5 @@
1
- openlit/__helpers.py,sha256=EEbLEUKuCiBp0WiieAvUnGcaU5D7grFgNVDCBgMKjQE,4651
2
- openlit/__init__.py,sha256=NzHt2F8iJh5ljM1wD-HH4pkH2yH0e0ivE49U5LNGlnk,9917
1
+ openlit/__helpers.py,sha256=lrn4PBs9owDudiCY2NBoVbAi7AU_HtUpyOj0oqPBsPY,5545
2
+ openlit/__init__.py,sha256=5AMhhPAlW60YtRxttzCyJzJIWMpX9l8TlBM8ofxPkaY,10141
3
3
  openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
4
4
  openlit/instrumentation/anthropic/anthropic.py,sha256=CYBui5eEfWdSfFF0xtCQjh1xO-gCVJc_V9Hli0szVZE,16026
5
5
  openlit/instrumentation/anthropic/async_anthropic.py,sha256=NW84kTQ3BkUx1zZuMRps_J7zTYkmq5BxOrqSjqWInBs,16068
@@ -43,7 +43,7 @@ openlit/instrumentation/vertexai/vertexai.py,sha256=UvpNKBHPoV9idVMfGigZnmWuEQiy
43
43
  openlit/otel/metrics.py,sha256=O7NoaDz0bY19mqpE4-0PcKwEe-B-iJFRgOCaanAuZAc,4291
44
44
  openlit/otel/tracing.py,sha256=vL1ifMbARPBpqK--yXYsCM6y5dSu5LFIKqkhZXtYmUc,3712
45
45
  openlit/semcov/__init__.py,sha256=wcy_1uP6_YxpaHxlo5he91m2GcuD5sfngZbZGgIwNlY,6328
46
- openlit-1.7.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
47
- openlit-1.7.0.dist-info/METADATA,sha256=gTob1Bi1ZPwj0i0AxWvnjxdg24xrAspP7_OmOIphCBo,12280
48
- openlit-1.7.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
49
- openlit-1.7.0.dist-info/RECORD,,
46
+ openlit-1.8.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
47
+ openlit-1.8.0.dist-info/METADATA,sha256=148uqS7Fbltn1PI2Ulk1T-9s1AnyJdtuE1tOQjxBYTU,12481
48
+ openlit-1.8.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
49
+ openlit-1.8.0.dist-info/RECORD,,