ragaai-catalyst 2.2.4b5__py3-none-any.whl → 2.2.5b2__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.
- ragaai_catalyst/__init__.py +0 -2
- ragaai_catalyst/dataset.py +59 -1
- ragaai_catalyst/tracers/agentic_tracing/tracers/main_tracer.py +5 -285
- ragaai_catalyst/tracers/agentic_tracing/utils/__init__.py +0 -2
- ragaai_catalyst/tracers/agentic_tracing/utils/create_dataset_schema.py +1 -1
- ragaai_catalyst/tracers/exporters/__init__.py +1 -2
- ragaai_catalyst/tracers/exporters/file_span_exporter.py +0 -1
- ragaai_catalyst/tracers/exporters/ragaai_trace_exporter.py +23 -1
- ragaai_catalyst/tracers/tracer.py +6 -186
- {ragaai_catalyst-2.2.4b5.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/METADATA +1 -1
- {ragaai_catalyst-2.2.4b5.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/RECORD +14 -45
- ragaai_catalyst/experiment.py +0 -486
- ragaai_catalyst/tracers/agentic_tracing/tests/FinancialAnalysisSystem.ipynb +0 -536
- ragaai_catalyst/tracers/agentic_tracing/tests/GameActivityEventPlanner.ipynb +0 -134
- ragaai_catalyst/tracers/agentic_tracing/tests/TravelPlanner.ipynb +0 -563
- ragaai_catalyst/tracers/agentic_tracing/tests/__init__.py +0 -0
- ragaai_catalyst/tracers/agentic_tracing/tests/ai_travel_agent.py +0 -197
- ragaai_catalyst/tracers/agentic_tracing/tests/unique_decorator_test.py +0 -172
- ragaai_catalyst/tracers/agentic_tracing/tracers/agent_tracer.py +0 -687
- ragaai_catalyst/tracers/agentic_tracing/tracers/base.py +0 -1319
- ragaai_catalyst/tracers/agentic_tracing/tracers/custom_tracer.py +0 -347
- ragaai_catalyst/tracers/agentic_tracing/tracers/langgraph_tracer.py +0 -0
- ragaai_catalyst/tracers/agentic_tracing/tracers/llm_tracer.py +0 -1182
- ragaai_catalyst/tracers/agentic_tracing/tracers/network_tracer.py +0 -288
- ragaai_catalyst/tracers/agentic_tracing/tracers/tool_tracer.py +0 -557
- ragaai_catalyst/tracers/agentic_tracing/tracers/user_interaction_tracer.py +0 -129
- ragaai_catalyst/tracers/agentic_tracing/upload/upload_local_metric.py +0 -74
- ragaai_catalyst/tracers/agentic_tracing/utils/api_utils.py +0 -21
- ragaai_catalyst/tracers/agentic_tracing/utils/generic.py +0 -32
- ragaai_catalyst/tracers/agentic_tracing/utils/get_user_trace_metrics.py +0 -28
- ragaai_catalyst/tracers/agentic_tracing/utils/span_attributes.py +0 -133
- ragaai_catalyst/tracers/agentic_tracing/utils/supported_llm_provider.toml +0 -34
- ragaai_catalyst/tracers/exporters/raga_exporter.py +0 -467
- ragaai_catalyst/tracers/langchain_callback.py +0 -821
- ragaai_catalyst/tracers/llamaindex_callback.py +0 -361
- ragaai_catalyst/tracers/llamaindex_instrumentation.py +0 -424
- ragaai_catalyst/tracers/upload_traces.py +0 -170
- ragaai_catalyst/tracers/utils/convert_langchain_callbacks_output.py +0 -62
- ragaai_catalyst/tracers/utils/convert_llama_instru_callback.py +0 -69
- ragaai_catalyst/tracers/utils/extraction_logic_llama_index.py +0 -74
- ragaai_catalyst/tracers/utils/langchain_tracer_extraction_logic.py +0 -82
- ragaai_catalyst/tracers/utils/rag_trace_json_converter.py +0 -403
- {ragaai_catalyst-2.2.4b5.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/WHEEL +0 -0
- {ragaai_catalyst-2.2.4b5.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/licenses/LICENSE +0 -0
- {ragaai_catalyst-2.2.4b5.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/top_level.txt +0 -0
@@ -1,347 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
import uuid
|
3
|
-
import psutil
|
4
|
-
import threading
|
5
|
-
from datetime import datetime
|
6
|
-
import functools
|
7
|
-
from typing import Optional, Any, Dict, List
|
8
|
-
from ..utils.unique_decorator import generate_unique_hash_simple, mydecorator
|
9
|
-
import contextvars
|
10
|
-
import asyncio
|
11
|
-
from ..utils.file_name_tracker import TrackName
|
12
|
-
|
13
|
-
|
14
|
-
class CustomTracerMixin:
|
15
|
-
def __init__(self, *args, **kwargs):
|
16
|
-
super().__init__(*args, **kwargs)
|
17
|
-
self.file_tracker = TrackName()
|
18
|
-
self.current_custom_name = contextvars.ContextVar("custom_name", default=None)
|
19
|
-
self.current_custom_id = contextvars.ContextVar("custom_id", default=None)
|
20
|
-
self.component_network_calls = {}
|
21
|
-
self.component_user_interaction = {}
|
22
|
-
self.gt = None
|
23
|
-
|
24
|
-
# Add auto instrument flags
|
25
|
-
self.auto_instrument_custom = False
|
26
|
-
self.auto_instrument_user_interaction = False
|
27
|
-
self.auto_instrument_network = False
|
28
|
-
self.auto_instrument_file_io = False
|
29
|
-
|
30
|
-
def trace_custom(self, name: str = None, custom_type: str = "generic", version: str = "1.0.0", trace_variables: bool = True):
|
31
|
-
def decorator(func):
|
32
|
-
# Add metadata attribute to the function
|
33
|
-
metadata = {
|
34
|
-
"name": name or func.__name__,
|
35
|
-
"custom_type": custom_type,
|
36
|
-
"version": version,
|
37
|
-
"trace_variables": trace_variables,
|
38
|
-
"is_active": True
|
39
|
-
}
|
40
|
-
|
41
|
-
# Check if the function is async
|
42
|
-
is_async = asyncio.iscoroutinefunction(func)
|
43
|
-
|
44
|
-
@functools.wraps(func)
|
45
|
-
async def async_wrapper(*args, **kwargs):
|
46
|
-
async_wrapper.metadata = metadata
|
47
|
-
gt = kwargs.get('gt') if kwargs else None
|
48
|
-
if gt is not None:
|
49
|
-
span = self.span(name)
|
50
|
-
span.add_gt(gt)
|
51
|
-
return await self._trace_custom_execution(
|
52
|
-
func, name or func.__name__, custom_type, version, trace_variables, *args, **kwargs
|
53
|
-
)
|
54
|
-
|
55
|
-
@functools.wraps(func)
|
56
|
-
def sync_wrapper(*args, **kwargs):
|
57
|
-
sync_wrapper.metadata = metadata
|
58
|
-
gt = kwargs.get('gt') if kwargs else None
|
59
|
-
if gt is not None:
|
60
|
-
span = self.span(name)
|
61
|
-
span.add_gt(gt)
|
62
|
-
return self._trace_sync_custom_execution(
|
63
|
-
func, name or func.__name__, custom_type, version, trace_variables, *args, **kwargs
|
64
|
-
)
|
65
|
-
|
66
|
-
wrapper = async_wrapper if is_async else sync_wrapper
|
67
|
-
wrapper.metadata = metadata
|
68
|
-
return wrapper
|
69
|
-
|
70
|
-
return decorator
|
71
|
-
|
72
|
-
def _trace_sync_custom_execution(self, func, name, custom_type, version, trace_variables, *args, **kwargs):
|
73
|
-
"""Synchronous version of custom tracing"""
|
74
|
-
if not self.is_active or not self.auto_instrument_custom:
|
75
|
-
return func(*args, **kwargs)
|
76
|
-
|
77
|
-
start_time = datetime.now().astimezone().isoformat()
|
78
|
-
start_memory = psutil.Process().memory_info().rss
|
79
|
-
component_id = str(uuid.uuid4())
|
80
|
-
hash_id = generate_unique_hash_simple(func)
|
81
|
-
variable_traces = []
|
82
|
-
|
83
|
-
# Set up variable tracing if enabled
|
84
|
-
if trace_variables:
|
85
|
-
def trace_variables_func(frame, event, arg):
|
86
|
-
if event == 'line' and frame.f_code == func.__code__:
|
87
|
-
try:
|
88
|
-
locals_dict = {k: v for k, v in frame.f_locals.items()
|
89
|
-
if not k.startswith('__') and isinstance(v, (int, float, bool, str, list, dict, tuple, set))}
|
90
|
-
if locals_dict:
|
91
|
-
variable_traces.append({
|
92
|
-
'variables': locals_dict,
|
93
|
-
'timestamp': datetime.now().astimezone().isoformat()
|
94
|
-
})
|
95
|
-
except:
|
96
|
-
pass
|
97
|
-
return trace_variables_func
|
98
|
-
|
99
|
-
|
100
|
-
# Start tracking network calls for this component
|
101
|
-
self.start_component(component_id)
|
102
|
-
|
103
|
-
try:
|
104
|
-
# Execute the function
|
105
|
-
result = func(*args, **kwargs)
|
106
|
-
|
107
|
-
# Calculate resource usage
|
108
|
-
end_time = datetime.now().astimezone().isoformat()
|
109
|
-
end_memory = psutil.Process().memory_info().rss
|
110
|
-
memory_used = max(0, end_memory - start_memory)
|
111
|
-
|
112
|
-
# End tracking network calls for this component
|
113
|
-
self.end_component(component_id)
|
114
|
-
|
115
|
-
# Create custom component
|
116
|
-
custom_component = self.create_custom_component(
|
117
|
-
component_id=component_id,
|
118
|
-
hash_id=hash_id,
|
119
|
-
name=name,
|
120
|
-
custom_type=custom_type,
|
121
|
-
version=version,
|
122
|
-
memory_used=memory_used,
|
123
|
-
start_time=start_time,
|
124
|
-
end_time=end_time,
|
125
|
-
variable_traces=variable_traces,
|
126
|
-
input_data=self._sanitize_input(args, kwargs),
|
127
|
-
output_data=self._sanitize_output(result)
|
128
|
-
)
|
129
|
-
|
130
|
-
self.add_component(custom_component)
|
131
|
-
return result
|
132
|
-
|
133
|
-
except Exception as e:
|
134
|
-
error_component = {
|
135
|
-
"code": 500,
|
136
|
-
"type": type(e).__name__,
|
137
|
-
"message": str(e),
|
138
|
-
"details": {}
|
139
|
-
}
|
140
|
-
|
141
|
-
# End tracking network calls for this component
|
142
|
-
self.end_component(component_id)
|
143
|
-
|
144
|
-
end_time = datetime.now().astimezone().isoformat()
|
145
|
-
|
146
|
-
custom_component = self.create_custom_component(
|
147
|
-
component_id=component_id,
|
148
|
-
hash_id=hash_id,
|
149
|
-
name=name,
|
150
|
-
custom_type=custom_type,
|
151
|
-
version=version,
|
152
|
-
memory_used=0,
|
153
|
-
start_time=start_time,
|
154
|
-
end_time=end_time,
|
155
|
-
variable_traces=variable_traces,
|
156
|
-
input_data=self._sanitize_input(args, kwargs),
|
157
|
-
output_data=None,
|
158
|
-
error=error_component
|
159
|
-
)
|
160
|
-
|
161
|
-
self.add_component(custom_component, is_error=True)
|
162
|
-
raise
|
163
|
-
|
164
|
-
async def _trace_custom_execution(self, func, name, custom_type, version, trace_variables, *args, **kwargs):
|
165
|
-
"""Asynchronous version of custom tracing"""
|
166
|
-
if not self.is_active or not self.auto_instrument_custom:
|
167
|
-
return await func(*args, **kwargs)
|
168
|
-
|
169
|
-
start_time = datetime.now().astimezone().isoformat()
|
170
|
-
start_memory = psutil.Process().memory_info().rss
|
171
|
-
component_id = str(uuid.uuid4())
|
172
|
-
hash_id = generate_unique_hash_simple(func)
|
173
|
-
variable_traces = []
|
174
|
-
|
175
|
-
# Set up variable tracing if enabled
|
176
|
-
if trace_variables:
|
177
|
-
def trace_variables_func(frame, event, arg):
|
178
|
-
if event == 'line' and frame.f_code == func.__code__:
|
179
|
-
try:
|
180
|
-
locals_dict = {k: v for k, v in frame.f_locals.items()
|
181
|
-
if not k.startswith('__') and isinstance(v, (int, float, bool, str, list, dict, tuple, set))}
|
182
|
-
if locals_dict:
|
183
|
-
variable_traces.append({
|
184
|
-
'variables': locals_dict,
|
185
|
-
'timestamp': datetime.now().astimezone().isoformat()
|
186
|
-
})
|
187
|
-
except:
|
188
|
-
pass
|
189
|
-
return trace_variables_func
|
190
|
-
|
191
|
-
try:
|
192
|
-
# Execute the function
|
193
|
-
result = await func(*args, **kwargs)
|
194
|
-
|
195
|
-
# Calculate resource usage
|
196
|
-
end_time = datetime.now().astimezone().isoformat()
|
197
|
-
end_memory = psutil.Process().memory_info().rss
|
198
|
-
memory_used = max(0, end_memory - start_memory)
|
199
|
-
|
200
|
-
# Create custom component
|
201
|
-
custom_component = self.create_custom_component(
|
202
|
-
component_id=component_id,
|
203
|
-
hash_id=hash_id,
|
204
|
-
name=name,
|
205
|
-
custom_type=custom_type,
|
206
|
-
version=version,
|
207
|
-
start_time=start_time,
|
208
|
-
end_time=end_time,
|
209
|
-
memory_used=memory_used,
|
210
|
-
variable_traces=variable_traces,
|
211
|
-
input_data=self._sanitize_input(args, kwargs),
|
212
|
-
output_data=self._sanitize_output(result)
|
213
|
-
)
|
214
|
-
self.add_component(custom_component)
|
215
|
-
return result
|
216
|
-
|
217
|
-
except Exception as e:
|
218
|
-
error_component = {
|
219
|
-
"code": 500,
|
220
|
-
"type": type(e).__name__,
|
221
|
-
"message": str(e),
|
222
|
-
"details": {}
|
223
|
-
}
|
224
|
-
|
225
|
-
end_time = datetime.now().astimezone().isoformat()
|
226
|
-
|
227
|
-
custom_component = self.create_custom_component(
|
228
|
-
component_id=component_id,
|
229
|
-
hash_id=hash_id,
|
230
|
-
name=name,
|
231
|
-
custom_type=custom_type,
|
232
|
-
version=version,
|
233
|
-
start_time=start_time,
|
234
|
-
end_time=end_time,
|
235
|
-
memory_used=0,
|
236
|
-
variable_traces=variable_traces,
|
237
|
-
input_data=self._sanitize_input(args, kwargs),
|
238
|
-
output_data=None,
|
239
|
-
error=error_component
|
240
|
-
)
|
241
|
-
self.add_component(custom_component, is_error=True)
|
242
|
-
raise
|
243
|
-
|
244
|
-
def create_custom_component(self, **kwargs):
|
245
|
-
"""Create a custom component according to the data structure"""
|
246
|
-
start_time = kwargs["start_time"]
|
247
|
-
|
248
|
-
network_calls = []
|
249
|
-
if self.auto_instrument_network:
|
250
|
-
network_calls = self.component_network_calls.get(kwargs["component_id"], [])
|
251
|
-
|
252
|
-
interactions = []
|
253
|
-
if self.auto_instrument_user_interaction:
|
254
|
-
input_output_interactions = []
|
255
|
-
for interaction in self.component_user_interaction.get(kwargs["component_id"], []):
|
256
|
-
if interaction["interaction_type"] in ["input", "output"]:
|
257
|
-
input_output_interactions.append(interaction)
|
258
|
-
interactions.extend(input_output_interactions)
|
259
|
-
if self.auto_instrument_file_io:
|
260
|
-
file_io_interactions = []
|
261
|
-
for interaction in self.component_user_interaction.get(kwargs["component_id"], []):
|
262
|
-
if interaction["interaction_type"] in ["file_read", "file_write"]:
|
263
|
-
file_io_interactions.append(interaction)
|
264
|
-
interactions.extend(file_io_interactions)
|
265
|
-
|
266
|
-
component = {
|
267
|
-
"id": kwargs["component_id"],
|
268
|
-
"hash_id": kwargs["hash_id"],
|
269
|
-
"source_hash_id": None,
|
270
|
-
"type": "custom",
|
271
|
-
"name": kwargs["name"],
|
272
|
-
"start_time": start_time,
|
273
|
-
"end_time": kwargs["end_time"],
|
274
|
-
"error": kwargs.get("error"),
|
275
|
-
"parent_id": self.current_agent_id.get() if hasattr(self, 'current_agent_id') else None,
|
276
|
-
"info": {
|
277
|
-
"custom_type": kwargs["custom_type"],
|
278
|
-
"version": kwargs["version"],
|
279
|
-
"memory_used": kwargs["memory_used"]
|
280
|
-
},
|
281
|
-
"data": {
|
282
|
-
"input": kwargs["input_data"],
|
283
|
-
"output": kwargs["output_data"],
|
284
|
-
"memory_used": kwargs["memory_used"],
|
285
|
-
"variable_traces": kwargs.get("variable_traces", [])
|
286
|
-
},
|
287
|
-
"network_calls": network_calls,
|
288
|
-
"interactions": interactions
|
289
|
-
}
|
290
|
-
|
291
|
-
if kwargs["name"] in self.span_attributes_dict:
|
292
|
-
span_gt = self.span_attributes_dict[kwargs["name"]].gt
|
293
|
-
if span_gt is not None:
|
294
|
-
component["data"]["gt"] = span_gt
|
295
|
-
span_context = self.span_attributes_dict[kwargs["name"]].context
|
296
|
-
if span_context:
|
297
|
-
component["data"]["context"] = span_context
|
298
|
-
return component
|
299
|
-
|
300
|
-
def start_component(self, component_id):
|
301
|
-
"""Start tracking network calls for a component"""
|
302
|
-
self.component_network_calls[component_id] = []
|
303
|
-
|
304
|
-
def end_component(self, component_id):
|
305
|
-
"""End tracking network calls for a component"""
|
306
|
-
pass
|
307
|
-
|
308
|
-
def _sanitize_input(self, args: tuple, kwargs: dict) -> dict:
|
309
|
-
"""Sanitize and format input data, including handling of nested lists and dictionaries."""
|
310
|
-
|
311
|
-
def sanitize_value(value):
|
312
|
-
if isinstance(value, (int, float, bool, str)):
|
313
|
-
return value
|
314
|
-
elif isinstance(value, list):
|
315
|
-
return [sanitize_value(item) for item in value]
|
316
|
-
elif isinstance(value, dict):
|
317
|
-
return {key: sanitize_value(val) for key, val in value.items()}
|
318
|
-
else:
|
319
|
-
return str(value) # Convert non-standard types to string
|
320
|
-
|
321
|
-
return {
|
322
|
-
"args": [sanitize_value(arg) for arg in args],
|
323
|
-
"kwargs": {key: sanitize_value(val) for key, val in kwargs.items()},
|
324
|
-
}
|
325
|
-
|
326
|
-
def _sanitize_output(self, output: Any) -> Any:
|
327
|
-
"""Sanitize and format output data"""
|
328
|
-
if isinstance(output, (int, float, bool, str, list, dict)):
|
329
|
-
return output
|
330
|
-
return str(output)
|
331
|
-
|
332
|
-
# Auto instrumentation methods
|
333
|
-
def instrument_custom_calls(self):
|
334
|
-
"""Enable auto-instrumentation for custom calls"""
|
335
|
-
self.auto_instrument_custom = True
|
336
|
-
|
337
|
-
def instrument_user_interaction_calls(self):
|
338
|
-
"""Enable auto-instrumentation for user interaction calls"""
|
339
|
-
self.auto_instrument_user_interaction = True
|
340
|
-
|
341
|
-
def instrument_network_calls(self):
|
342
|
-
"""Enable auto-instrumentation for network calls"""
|
343
|
-
self.auto_instrument_network = True
|
344
|
-
|
345
|
-
def instrument_file_io_calls(self):
|
346
|
-
"""Enable auto-instrumentation for file IO calls"""
|
347
|
-
self.auto_instrument_file_io = True
|
File without changes
|