openlit 1.32.2__py3-none-any.whl → 1.32.4__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
@@ -48,6 +48,7 @@ from openlit.instrumentation.chroma import ChromaInstrumentor
48
48
  from openlit.instrumentation.pinecone import PineconeInstrumentor
49
49
  from openlit.instrumentation.qdrant import QdrantInstrumentor
50
50
  from openlit.instrumentation.milvus import MilvusInstrumentor
51
+ from openlit.instrumentation.astra import AstraInstrumentor
51
52
  from openlit.instrumentation.transformers import TransformersInstrumentor
52
53
  from openlit.instrumentation.litellm import LiteLLMInstrumentor
53
54
  from openlit.instrumentation.crewai import CrewAIInstrumentor
@@ -56,6 +57,7 @@ from openlit.instrumentation.multion import MultiOnInstrumentor
56
57
  from openlit.instrumentation.dynamiq import DynamiqInstrumentor
57
58
  from openlit.instrumentation.phidata import PhidataInstrumentor
58
59
  from openlit.instrumentation.julep import JulepInstrumentor
60
+ from openlit.instrumentation.ai21 import AI21Instrumentor
59
61
  from openlit.instrumentation.gpu import GPUInstrumentor
60
62
  import openlit.guard
61
63
  import openlit.evals
@@ -250,6 +252,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
250
252
  "reka-api": "reka",
251
253
  "premai": "premai",
252
254
  "julep": "julep",
255
+ "astra": "astrapy",
256
+ "ai21": "ai21",
253
257
  }
254
258
 
255
259
  invalid_instrumentors = [
@@ -339,6 +343,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
339
343
  "reka-api": RekaInstrumentor(),
340
344
  "premai": PremAIInstrumentor(),
341
345
  "julep": JulepInstrumentor(),
346
+ "astra": AstraInstrumentor(),
347
+ "ai21": AI21Instrumentor(),
342
348
  }
343
349
 
344
350
  # 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