openlit 1.32.3__py3-none-any.whl → 1.32.6__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/__init__.py CHANGED
@@ -57,6 +57,8 @@ from openlit.instrumentation.multion import MultiOnInstrumentor
57
57
  from openlit.instrumentation.dynamiq import DynamiqInstrumentor
58
58
  from openlit.instrumentation.phidata import PhidataInstrumentor
59
59
  from openlit.instrumentation.julep import JulepInstrumentor
60
+ from openlit.instrumentation.ai21 import AI21Instrumentor
61
+ from openlit.instrumentation.controlflow import ControlFlowInstrumentor
60
62
  from openlit.instrumentation.gpu import GPUInstrumentor
61
63
  import openlit.guard
62
64
  import openlit.evals
@@ -252,6 +254,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
252
254
  "premai": "premai",
253
255
  "julep": "julep",
254
256
  "astra": "astrapy",
257
+ "ai21": "ai21",
258
+ "controlflow": "controlflow",
255
259
  }
256
260
 
257
261
  invalid_instrumentors = [
@@ -342,6 +346,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
342
346
  "premai": PremAIInstrumentor(),
343
347
  "julep": JulepInstrumentor(),
344
348
  "astra": AstraInstrumentor(),
349
+ "ai21": AI21Instrumentor(),
350
+ "controlflow": ControlFlowInstrumentor(),
345
351
  }
346
352
 
347
353
  # Initialize and instrument only the enabled instrumentors
@@ -0,0 +1,66 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of AI21 Functions"""
3
+
4
+ from typing import Collection
5
+ import importlib.metadata
6
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7
+ from wrapt import wrap_function_wrapper
8
+
9
+ from openlit.instrumentation.ai21.ai21 import (
10
+ chat, chat_rag
11
+ )
12
+ from openlit.instrumentation.ai21.async_ai21 import (
13
+ async_chat, async_chat_rag
14
+ )
15
+
16
+ _instruments = ("ai21 >= 3.0.0",)
17
+
18
+ class AI21Instrumentor(BaseInstrumentor):
19
+ """
20
+ An instrumentor for AI21's client library.
21
+ """
22
+
23
+ def instrumentation_dependencies(self) -> Collection[str]:
24
+ return _instruments
25
+
26
+ def _instrument(self, **kwargs):
27
+ application_name = kwargs.get("application_name", "default_application")
28
+ environment = kwargs.get("environment", "default_environment")
29
+ tracer = kwargs.get("tracer")
30
+ metrics = kwargs.get("metrics_dict")
31
+ pricing_info = kwargs.get("pricing_info", {})
32
+ trace_content = kwargs.get("trace_content", False)
33
+ disable_metrics = kwargs.get("disable_metrics")
34
+ version = importlib.metadata.version("ai21")
35
+
36
+ #sync
37
+ wrap_function_wrapper(
38
+ "ai21.clients.studio.resources.chat.chat_completions",
39
+ "ChatCompletions.create",
40
+ chat("ai21.chat.completions", version, environment, application_name,
41
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
42
+ )
43
+ wrap_function_wrapper(
44
+ "ai21.clients.studio.resources.studio_conversational_rag",
45
+ "StudioConversationalRag.create",
46
+ chat_rag("ai21.conversational_rag", version, environment, application_name,
47
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
48
+ )
49
+
50
+ #Async
51
+ wrap_function_wrapper(
52
+ "ai21.clients.studio.resources.chat.async_chat_completions",
53
+ "AsyncChatCompletions.create",
54
+ async_chat("ai21.chat.completions", version, environment, application_name,
55
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
56
+ )
57
+ wrap_function_wrapper(
58
+ "ai21.clients.studio.resources.studio_conversational_rag",
59
+ "AsyncStudioConversationalRag.create",
60
+ async_chat_rag("ai21.conversational_rag", version, environment, application_name,
61
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
62
+ )
63
+
64
+ def _uninstrument(self, **kwargs):
65
+ # Proper uninstrumentation logic to revert patched methods
66
+ pass