ragaai-catalyst 2.1.5b16__py3-none-any.whl → 2.1.5b18__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.
@@ -10,6 +10,8 @@ from datetime import datetime
10
10
  import uuid
11
11
  import contextvars
12
12
  import traceback
13
+ import importlib
14
+ import sys
13
15
 
14
16
  from ..utils.llm_utils import (
15
17
  extract_model_name,
@@ -45,7 +47,6 @@ class LLMTracerMixin:
45
47
  self.model_costs = load_model_costs()
46
48
  except Exception as e:
47
49
  self.model_costs = {
48
- # TODO: Default cost handling needs to be improved
49
50
  "default": {"input_cost_per_token": 0.0, "output_cost_per_token": 0.0}
50
51
  }
51
52
  self.MAX_PARAMETERS_TO_DISPLAY = 10
@@ -59,25 +60,31 @@ class LLMTracerMixin:
59
60
  self.total_cost = 0.0
60
61
  self.llm_data = {}
61
62
 
62
- # Add auto_instrument options
63
63
  self.auto_instrument_llm = False
64
64
  self.auto_instrument_user_interaction = False
65
65
  self.auto_instrument_file_io = False
66
66
  self.auto_instrument_network = False
67
67
 
68
+ def check_package_available(self, package_name):
69
+ """Check if a package is available in the environment"""
70
+ try:
71
+ importlib.import_module(package_name)
72
+ return True
73
+ except ImportError:
74
+ return False
75
+
76
+ def validate_openai_key(self):
77
+ """Validate if OpenAI API key is available"""
78
+ return bool(os.getenv("OPENAI_API_KEY"))
79
+
68
80
  def instrument_llm_calls(self):
69
81
  """Enable LLM instrumentation"""
70
82
  self.auto_instrument_llm = True
71
83
 
72
- # Handle modules that are already imported
73
- import sys
74
-
84
+ # Check currently loaded modules
75
85
  if "vertexai" in sys.modules:
76
86
  self.patch_vertex_ai_methods(sys.modules["vertexai"])
77
- if "vertexai.generative_models" in sys.modules:
78
- self.patch_vertex_ai_methods(sys.modules["vertexai.generative_models"])
79
-
80
- if "openai" in sys.modules:
87
+ if "openai" in sys.modules and self.validate_openai_key():
81
88
  self.patch_openai_methods(sys.modules["openai"])
82
89
  self.patch_openai_beta_methods(sys.modules["openai"])
83
90
  if "litellm" in sys.modules:
@@ -87,32 +94,42 @@ class LLMTracerMixin:
87
94
  if "google.generativeai" in sys.modules:
88
95
  self.patch_google_genai_methods(sys.modules["google.generativeai"])
89
96
  if "langchain_google_vertexai" in sys.modules:
90
- self.patch_langchain_google_methods(
91
- sys.modules["langchain_google_vertexai"]
92
- )
97
+ self.patch_langchain_google_methods(sys.modules["langchain_google_vertexai"])
93
98
  if "langchain_google_genai" in sys.modules:
94
99
  self.patch_langchain_google_methods(sys.modules["langchain_google_genai"])
95
100
 
96
- # Register hooks for future imports
97
- wrapt.register_post_import_hook(self.patch_vertex_ai_methods, "vertexai")
98
- wrapt.register_post_import_hook(
99
- self.patch_vertex_ai_methods, "vertexai.generative_models"
100
- )
101
- wrapt.register_post_import_hook(self.patch_openai_methods, "openai")
102
- wrapt.register_post_import_hook(self.patch_openai_beta_methods, "openai")
103
- wrapt.register_post_import_hook(self.patch_litellm_methods, "litellm")
104
- wrapt.register_post_import_hook(self.patch_anthropic_methods, "anthropic")
105
- wrapt.register_post_import_hook(
106
- self.patch_google_genai_methods, "google.generativeai"
107
- )
101
+ # Register hooks for future imports with availability checks
102
+ if self.check_package_available("vertexai"):
103
+ wrapt.register_post_import_hook(self.patch_vertex_ai_methods, "vertexai")
104
+ wrapt.register_post_import_hook(
105
+ self.patch_vertex_ai_methods, "vertexai.generative_models"
106
+ )
107
+
108
+ if self.check_package_available("openai") and self.validate_openai_key():
109
+ wrapt.register_post_import_hook(self.patch_openai_methods, "openai")
110
+ wrapt.register_post_import_hook(self.patch_openai_beta_methods, "openai")
111
+
112
+ if self.check_package_available("litellm"):
113
+ wrapt.register_post_import_hook(self.patch_litellm_methods, "litellm")
114
+
115
+ if self.check_package_available("anthropic"):
116
+ wrapt.register_post_import_hook(self.patch_anthropic_methods, "anthropic")
117
+
118
+ if self.check_package_available("google.generativeai"):
119
+ wrapt.register_post_import_hook(
120
+ self.patch_google_genai_methods, "google.generativeai"
121
+ )
108
122
 
109
- # Add hooks for LangChain integrations
110
- wrapt.register_post_import_hook(
111
- self.patch_langchain_google_methods, "langchain_google_vertexai"
112
- )
113
- wrapt.register_post_import_hook(
114
- self.patch_langchain_google_methods, "langchain_google_genai"
115
- )
123
+ # Add hooks for LangChain integrations with availability checks
124
+ if self.check_package_available("langchain_google_vertexai"):
125
+ wrapt.register_post_import_hook(
126
+ self.patch_langchain_google_methods, "langchain_google_vertexai"
127
+ )
128
+
129
+ if self.check_package_available("langchain_google_genai"):
130
+ wrapt.register_post_import_hook(
131
+ self.patch_langchain_google_methods, "langchain_google_genai"
132
+ )
116
133
 
117
134
  def instrument_user_interaction_calls(self):
118
135
  """Enable user interaction instrumentation for LLM calls"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ragaai_catalyst
3
- Version: 2.1.5b16
3
+ Version: 2.1.5b18
4
4
  Summary: RAGA AI CATALYST
5
5
  Author-email: Kiran Scaria <kiran.scaria@raga.ai>, Kedar Gaikwad <kedar.gaikwad@raga.ai>, Dushyant Mahajan <dushyant.mahajan@raga.ai>, Siddhartha Kosti <siddhartha.kosti@raga.ai>, Ritika Goel <ritika.goel@raga.ai>, Vijay Chaurasia <vijay.chaurasia@raga.ai>
6
6
  Requires-Python: <3.13,>=3.9
@@ -32,7 +32,7 @@ ragaai_catalyst/tracers/agentic_tracing/tracers/agent_tracer.py,sha256=8d6YovuWi
32
32
  ragaai_catalyst/tracers/agentic_tracing/tracers/base.py,sha256=88rX7OkOGEyVNECUrc4bYqODyulXve_-99d9ku5hBeQ,37373
33
33
  ragaai_catalyst/tracers/agentic_tracing/tracers/custom_tracer.py,sha256=OHet_Cphyrsq2CP4WiooTsWSgg3Rc1n8QsOl1s2vqdY,13480
34
34
  ragaai_catalyst/tracers/agentic_tracing/tracers/langgraph_tracer.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
- ragaai_catalyst/tracers/agentic_tracing/tracers/llm_tracer.py,sha256=NklCHbkG_ITlJ0zxGm-QHdk6it5xeu5gUHnK18YuLGo,34499
35
+ ragaai_catalyst/tracers/agentic_tracing/tracers/llm_tracer.py,sha256=OSRGwftAYpylvziXD50HGjEfEMe8k11-3SRSZKw2tHI,35255
36
36
  ragaai_catalyst/tracers/agentic_tracing/tracers/main_tracer.py,sha256=JEwvFV6KdYcg8zt2qUTKmmPvrkEft0YNAyUYK6FWF7c,18335
37
37
  ragaai_catalyst/tracers/agentic_tracing/tracers/network_tracer.py,sha256=m8CxYkl7iMiFya_lNwN1ykBc3Pmo-2pR_2HmpptwHWQ,10352
38
38
  ragaai_catalyst/tracers/agentic_tracing/tracers/tool_tracer.py,sha256=nmgkE3jRlTpq_uk6FYw0hTv2VgT8ejxvvBRL7gso39I,21037
@@ -66,8 +66,8 @@ ragaai_catalyst/tracers/utils/__init__.py,sha256=KeMaZtYaTojilpLv65qH08QmpYclfpa
66
66
  ragaai_catalyst/tracers/utils/convert_langchain_callbacks_output.py,sha256=ofrNrxf2b1hpjDh_zeaxiYq86azn1MF3kW8-ViYPEg0,1641
67
67
  ragaai_catalyst/tracers/utils/langchain_tracer_extraction_logic.py,sha256=qK67fdUBz5Xr99ajqXbYf1ueKS1V3a3_XR0zCcN4iGI,3061
68
68
  ragaai_catalyst/tracers/utils/utils.py,sha256=ViygfJ7vZ7U0CTSA1lbxVloHp4NSlmfDzBRNCJuMhis,2374
69
- ragaai_catalyst-2.1.5b16.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
70
- ragaai_catalyst-2.1.5b16.dist-info/METADATA,sha256=HtFk47NJx5iIsozMdsDyLdbodnfEwAfksqNyeiqzDWo,12796
71
- ragaai_catalyst-2.1.5b16.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
72
- ragaai_catalyst-2.1.5b16.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
73
- ragaai_catalyst-2.1.5b16.dist-info/RECORD,,
69
+ ragaai_catalyst-2.1.5b18.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
70
+ ragaai_catalyst-2.1.5b18.dist-info/METADATA,sha256=U0TwkW7NhS1k21IvYfh-g5WtmMcFbeGJYQwl4L18xyc,12796
71
+ ragaai_catalyst-2.1.5b18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
72
+ ragaai_catalyst-2.1.5b18.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
73
+ ragaai_catalyst-2.1.5b18.dist-info/RECORD,,