ragaai-catalyst 2.2b0__py3-none-any.whl → 2.2.1__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.
@@ -1,16 +1,14 @@
1
- from ..data.data_structure import LLMCall
2
- from .trace_utils import (
3
- calculate_cost,
4
- convert_usage_to_dict,
5
- )
6
- from importlib import resources
1
+ import asyncio
2
+
7
3
  #from litellm import model_cost
8
4
  import json
5
+ import logging
9
6
  import os
10
- import asyncio
11
- import psutil
7
+ from importlib import resources
8
+
12
9
  import tiktoken
13
- import logging
10
+
11
+ from ..data.data_structure import LLMCall
14
12
 
15
13
  logger = logging.getLogger(__name__)
16
14
 
@@ -61,7 +59,7 @@ def extract_model_name(args, kwargs, result):
61
59
  try:
62
60
  if not model:
63
61
  model = result.raw.model
64
- except Exception as e:
62
+ except Exception:
65
63
  pass
66
64
 
67
65
 
@@ -604,3 +602,18 @@ def extract_llm_data(args, kwargs, result):
604
602
  tool_call=parsed_tool_call,
605
603
  )
606
604
  return llm_data
605
+
606
+
607
+ def count_tokens(input_str: str) -> int:
608
+ # Use tiktoken to count tokens
609
+ try:
610
+ import tiktoken
611
+
612
+ # Use GPT-4o model's encoding (cl100k_base)
613
+ encoding = tiktoken.get_encoding("cl100k_base")
614
+
615
+ # Count tokens
616
+ tokens = encoding.encode(input_str)
617
+ return len(tokens)
618
+ except Exception:
619
+ raise Exception("Failed to count tokens")
@@ -1,23 +1,23 @@
1
- import os
2
1
  import json
3
- import tempfile
4
- from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
5
2
  import logging
3
+ import os
4
+ import tempfile
6
5
  from dataclasses import asdict
7
- from ragaai_catalyst.tracers.utils.trace_json_converter import convert_json_format
6
+
7
+ from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
8
+
8
9
  from ragaai_catalyst.tracers.agentic_tracing.tracers.base import TracerJSONEncoder
10
+ from ragaai_catalyst.tracers.agentic_tracing.upload.trace_uploader import (
11
+ submit_upload_task,
12
+ )
9
13
  from ragaai_catalyst.tracers.agentic_tracing.utils.system_monitor import SystemMonitor
10
- from ragaai_catalyst.tracers.agentic_tracing.upload.trace_uploader import submit_upload_task
11
- from ragaai_catalyst.tracers.agentic_tracing.utils.zip_list_of_unique_files import zip_list_of_unique_files
12
- from ragaai_catalyst.tracers.agentic_tracing.utils.trace_utils import format_interactions
13
- from ragaai_catalyst.tracers.utils.rag_trace_json_converter import rag_trace_json_converter
14
- from ragaai_catalyst.tracers.utils.convert_langchain_callbacks_output import convert_langchain_callbacks_output
15
- from ragaai_catalyst.tracers.upload_traces import UploadTraces
16
- import datetime
17
- import logging
18
- import asyncio
19
- import concurrent.futures
20
- from functools import partial
14
+ from ragaai_catalyst.tracers.agentic_tracing.utils.trace_utils import (
15
+ format_interactions,
16
+ )
17
+ from ragaai_catalyst.tracers.agentic_tracing.utils.zip_list_of_unique_files import (
18
+ zip_list_of_unique_files,
19
+ )
20
+ from ragaai_catalyst.tracers.utils.trace_json_converter import convert_json_format
21
21
 
22
22
  logger = logging.getLogger("RagaAICatalyst")
23
23
  logging_level = (
@@ -404,66 +404,27 @@ class Tracer(AgenticTracing):
404
404
 
405
405
  def recursive_mask_values(obj, parent_key=None):
406
406
  """Apply masking to all values in nested structure."""
407
- if isinstance(obj, dict):
408
- if self.tracer_type == "langchain":
409
- # Special handling for LangChain data
410
- if isinstance(obj, dict):
411
- if obj.get("name", "") == "retrieve_documents.langchain.workflow":
412
- prompt_structured_data = {
413
- "traceloop.entity.input": json.dumps({
414
- "kwargs": {
415
- "input": masking_func(json.loads(obj.get("attributes", {}).get("traceloop.entity.input", "")).get("kwargs", {}).get("input", "")),
416
- }
417
- })
418
- }
419
- prompt_data = {
420
- "name": "retrieve_documents.langchain.workflow",
421
- "attributes": prompt_structured_data,
422
- }
423
- return prompt_data
424
- elif obj.get("name", "") == "PromptTemplate.langchain.task":
425
- context_structured_data = {
426
- "traceloop.entity.input": json.dumps({
427
- "kwargs": {
428
- "context": masking_func(json.loads(obj.get("attributes", {}).get("traceloop.entity.input", "")).get("kwargs", {}).get("context", "")),
429
- }
430
- }),
431
- "traceloop.entity.output": json.dumps({
432
- "kwargs": {
433
- "text": masking_func(json.loads(obj.get("attributes", {}).get("traceloop.entity.output", "")).get("kwargs", {}).get("text", "")),
434
- }
435
- })
436
- }
437
- context_data = {
438
- "name": "PromptTemplate.langchain.task",
439
- "attributes": context_structured_data,
440
- }
441
- return context_data
442
- elif obj.get("name", "") == "ChatOpenAI.langchain.task":
443
- response_structured_data = {"gen_ai.completion.0.content": masking_func(obj.get("attributes", {}).get("gen_ai.completion.0.content", "")),
444
- "gen_ai.prompt.0.content": masking_func(obj.get("attributes", {}).get("gen_ai.prompt.0.content", ""))}
445
- response_data = {
446
- "name": "ChatOpenAI.langchain.task",
447
- "attributes" : response_structured_data
448
- }
449
- return response_data
450
- else:
407
+ try:
408
+ if isinstance(obj, dict):
451
409
  return {k: recursive_mask_values(v, k) for k, v in obj.items()}
452
- elif isinstance(obj, list):
453
- return [recursive_mask_values(item, parent_key) for item in obj]
454
- elif isinstance(obj, str):
455
- # List of keys that should NOT be masked
456
- excluded_keys = {
457
- 'start_time', 'end_time', 'name', 'id',
458
- 'hash_id', 'parent_id', 'source_hash_id',
459
- 'cost', 'type', 'feedback', 'error', 'ctx','telemetry.sdk.version',
460
- 'telemetry.sdk.language','service.name'
461
- }
462
- # Apply masking only if the key is NOT in the excluded list
463
- if parent_key and parent_key.lower() not in excluded_keys:
464
- return masking_func(obj)
465
- return obj
466
- else:
410
+ elif isinstance(obj, list):
411
+ return [recursive_mask_values(item, parent_key) for item in obj]
412
+ elif isinstance(obj, str):
413
+ # List of keys that should NOT be masked
414
+ excluded_keys = {
415
+ 'start_time', 'end_time', 'name', 'id',
416
+ 'hash_id', 'parent_id', 'source_hash_id',
417
+ 'cost', 'type', 'feedback', 'error', 'ctx','telemetry.sdk.version',
418
+ 'telemetry.sdk.language','service.name'
419
+ }
420
+ # Apply masking only if the key is NOT in the excluded list
421
+ if parent_key and parent_key.lower() not in excluded_keys:
422
+ return masking_func(obj)
423
+ return obj
424
+ else:
425
+ return obj
426
+ except Exception as e:
427
+ logger.error(f"Error masking value: {e}")
467
428
  return obj
468
429
 
469
430
  def file_post_processor(original_trace_json_path: os.PathLike) -> os.PathLike:
@@ -953,4 +914,4 @@ class Tracer(AgenticTracing):
953
914
  self.dynamic_exporter.user_details = user_details
954
915
  self.metadata = user_metadata
955
916
  else:
956
- logger.warning("metadata must be a dictionary")
917
+ logger.warning("metadata must be a dictionary")
@@ -1,12 +1,18 @@
1
1
  import json
2
+ import logging
2
3
  import sys
3
4
  import uuid
4
5
  from datetime import datetime
5
- from typing import final, List, Dict, Any, Optional
6
+ from typing import Any, Dict, List
7
+
6
8
  import pytz
7
- import uuid
8
- from ragaai_catalyst.tracers.agentic_tracing.utils.llm_utils import calculate_llm_cost, get_model_cost
9
- import logging
9
+
10
+ from ragaai_catalyst.tracers.agentic_tracing.utils.llm_utils import (
11
+ calculate_llm_cost,
12
+ count_tokens,
13
+ get_model_cost,
14
+ )
15
+
10
16
  logger = logging.getLogger(__name__)
11
17
 
12
18
  def convert_time_format(original_time_str, target_timezone_str="Asia/Kolkata"):
@@ -52,7 +58,6 @@ def get_ordered_family(parent_children_mapping: Dict[str, Any]) -> List[str]:
52
58
 
53
59
  def get_spans(input_trace):
54
60
  data = input_trace.copy()
55
- import uuid
56
61
  from collections import defaultdict
57
62
 
58
63
  name_counts = defaultdict(int)
@@ -123,15 +128,28 @@ def convert_json_format(input_trace, custom_model_cost, user_context, user_gt,ex
123
128
 
124
129
  final_trace["data"][0]["spans"] = spans
125
130
 
126
-
127
- # TODO: each span has token value from prompt ,completion and total tokens. i want the sum of all these tokens for each span
128
131
  # Calculate token counts and costs from spans
129
132
  for span in spans:
130
133
  if "attributes" in span:
131
134
  # Extract token counts
132
135
  prompt_tokens = span["attributes"].get("llm.token_count.prompt", 0)
133
136
  completion_tokens = span["attributes"].get("llm.token_count.completion", 0)
134
-
137
+
138
+ # If prompt tokens or/and completion tokens are not present, will calculate it using tiktoken
139
+ try:
140
+ if prompt_tokens == 0:
141
+ prompt_value = span["attributes"].get("input.value")
142
+ if prompt_value:
143
+ prompt_tokens = count_tokens(prompt_value)
144
+ logger.debug(f"Prompt tokens not present, calculated it: {prompt_tokens}")
145
+ if completion_tokens == 0:
146
+ completion_value = span["attributes"].get("output.value")
147
+ if completion_value:
148
+ completion_tokens = count_tokens(completion_value)
149
+ logger.debug(f"Completion tokens not present, calculated it: {completion_tokens}")
150
+ except Exception as e:
151
+ logger.warning(f"Failed to calculate token counts: {e}")
152
+
135
153
  # Update token counts
136
154
  final_trace["metadata"]["tokens"]["prompt_tokens"] += prompt_tokens
137
155
  final_trace["metadata"]["tokens"]["completion_tokens"] += completion_tokens
@@ -60,3 +60,4 @@ def get_unique_key(input_data):
60
60
  unique_key = hash_object.hexdigest()
61
61
 
62
62
  return unique_key
63
+
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ragaai_catalyst
3
- Version: 2.2b0
3
+ Version: 2.2.1
4
4
  Summary: RAGA AI CATALYST
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>, Tushar Kumar <tushar.kumar@raga.ai>
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>, Tushar Kumar <tushar.kumar@raga.ai>, Rishabh Pandey <rishabh.pandey@raga.ai>, Jyotsana C G <jyotsana@raga.ai>
6
6
  Requires-Python: <=3.13.2,>=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
@@ -31,7 +31,7 @@ ragaai_catalyst/tracers/distributed.py,sha256=MwlBwIxCAng-OI-7Ove_rkE1mTLeuW4Jw-
31
31
  ragaai_catalyst/tracers/langchain_callback.py,sha256=CB75zzG3-DkYTELj0vI1MOHQTY0MuQJfoHIXz9Cl8S8,34568
32
32
  ragaai_catalyst/tracers/llamaindex_callback.py,sha256=ZY0BJrrlz-P9Mg2dX-ZkVKG3gSvzwqBtk7JL_05MiYA,14028
33
33
  ragaai_catalyst/tracers/llamaindex_instrumentation.py,sha256=Ys_jLkvVqo12bKgXDmkp4TxJu9HkBATrFE8cIcTYxWw,14329
34
- ragaai_catalyst/tracers/tracer.py,sha256=4GRBnYtNCu-mXZdLuWyL3eDcgh1zdcZ9tokMUyX826w,44561
34
+ ragaai_catalyst/tracers/tracer.py,sha256=hdQK3-zV14lBqz8B6gLrMLNtfV34BmJ4-7eiNeLABq8,41931
35
35
  ragaai_catalyst/tracers/upload_traces.py,sha256=w1clGGfdOMpStUJX40NAlxe6dcFdN4pwcezyII0bGYA,6994
36
36
  ragaai_catalyst/tracers/agentic_tracing/README.md,sha256=X4QwLb7-Jg7GQMIXj-SerZIgDETfw-7VgYlczOR8ZeQ,4508
37
37
  ragaai_catalyst/tracers/agentic_tracing/__init__.py,sha256=yf6SKvOPSpH-9LiKaoLKXwqj5sez8F_5wkOb91yp0oE,260
@@ -64,7 +64,7 @@ ragaai_catalyst/tracers/agentic_tracing/utils/create_dataset_schema.py,sha256=Kx
64
64
  ragaai_catalyst/tracers/agentic_tracing/utils/file_name_tracker.py,sha256=YG601l1a29ov9VPu9Vl4RXxgL7l16k54_WWnoTNoG58,2064
65
65
  ragaai_catalyst/tracers/agentic_tracing/utils/generic.py,sha256=WwXT01xmp8MSr7KinuDCSK9a1ifpLcT7ajFkvYviG_A,1190
66
66
  ragaai_catalyst/tracers/agentic_tracing/utils/get_user_trace_metrics.py,sha256=vPZ4dn4EHFW0kqd1GyRpsYXbfrRrd0DXCmh-pzsDBNE,1109
67
- ragaai_catalyst/tracers/agentic_tracing/utils/llm_utils.py,sha256=McKB7TQchmFcgg2h0zg-inuxxKaRjcwbqV_OnRzzYEw,22387
67
+ ragaai_catalyst/tracers/agentic_tracing/utils/llm_utils.py,sha256=Tdi4nnxsXywx-X-4FOvyzRpvB04rgyd3Mzf4o9k_BAI,22697
68
68
  ragaai_catalyst/tracers/agentic_tracing/utils/model_costs.json,sha256=2tzGw_cKCTPcfjEm7iGvFE6pTw7gMTPzeBov_MTaXNY,321336
69
69
  ragaai_catalyst/tracers/agentic_tracing/utils/span_attributes.py,sha256=qmODERcFZhc8MX24boFCXkkh6sJ-vZngRHPvxhyWFeE,4347
70
70
  ragaai_catalyst/tracers/agentic_tracing/utils/supported_llm_provider.toml,sha256=LvFDivDIE96Zasp-fgDEqUJ5GEQZUawQucR3aOcSUTY,926
@@ -76,7 +76,7 @@ ragaai_catalyst/tracers/exporters/__init__.py,sha256=wQbaqyeIjVZxYprHCKZ9BeiqxeX
76
76
  ragaai_catalyst/tracers/exporters/dynamic_trace_exporter.py,sha256=JhYVSN9t6-9MFcg0IrYEJIyD6rg9O96Arg2poQSb5g8,6855
77
77
  ragaai_catalyst/tracers/exporters/file_span_exporter.py,sha256=RgGteu-NVGprXKkynvyIO5yOjpbtA41R3W_NzCjnkwE,6445
78
78
  ragaai_catalyst/tracers/exporters/raga_exporter.py,sha256=6xvjWXyh8XPkHKSLLmAZUQSvwuyY17ov8pv2VdfI0qA,17875
79
- ragaai_catalyst/tracers/exporters/ragaai_trace_exporter.py,sha256=exiAHrHlMPWwwlQnMFeAYwjeicgUjCL97OKPHl-g5GI,9275
79
+ ragaai_catalyst/tracers/exporters/ragaai_trace_exporter.py,sha256=0ybb8GQMN-WERum-L9LSbSvWm6hPDj7ywV3_pfgBMBA,8935
80
80
  ragaai_catalyst/tracers/instrumentators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
81
81
  ragaai_catalyst/tracers/utils/__init__.py,sha256=KeMaZtYaTojilpLv65qH08QmpYclfpacDA0U3wg6Ybw,64
82
82
  ragaai_catalyst/tracers/utils/convert_langchain_callbacks_output.py,sha256=SehrD7q8ytAiUYoWr406b4mWs3Lk0Rcy6Ekkihh22TI,1703
@@ -86,10 +86,10 @@ ragaai_catalyst/tracers/utils/langchain_tracer_extraction_logic.py,sha256=XS2_x2
86
86
  ragaai_catalyst/tracers/utils/model_prices_and_context_window_backup.json,sha256=C3uwkibJ08C9sOX-54kulZYmJlIpZ-SQpfE6HNGrjbM,343502
87
87
  ragaai_catalyst/tracers/utils/rag_extraction_logic_final.py,sha256=3ygkRT__lLDRflRttjzPu28tIA8cTCiGQVMQjqMItqQ,11309
88
88
  ragaai_catalyst/tracers/utils/rag_trace_json_converter.py,sha256=54IEZO-YRjUAahV5nw8KClXqTF1LhfDry_TsZ4KGow4,20467
89
- ragaai_catalyst/tracers/utils/trace_json_converter.py,sha256=K4X4yUmB01UtFX-_xmJsgFOAmzGe8qQ6SYQRHUyWlKs,9405
90
- ragaai_catalyst/tracers/utils/utils.py,sha256=ViygfJ7vZ7U0CTSA1lbxVloHp4NSlmfDzBRNCJuMhis,2374
91
- ragaai_catalyst-2.2b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
92
- ragaai_catalyst-2.2b0.dist-info/METADATA,sha256=Uj1EV64kf4yuPEMNIf3VhgguogYZaFdqNE4bTALMrcA,17603
93
- ragaai_catalyst-2.2b0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
94
- ragaai_catalyst-2.2b0.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
95
- ragaai_catalyst-2.2b0.dist-info/RECORD,,
89
+ ragaai_catalyst/tracers/utils/trace_json_converter.py,sha256=YllXhkfyYOuQ0rsX9VqiUjMUeztDMs8TFMudIPkWvrY,10191
90
+ ragaai_catalyst/tracers/utils/utils.py,sha256=L19LQGc8h08FFhyptBtixIHGG_e-VdSPsKs7JNaXnGE,2378
91
+ ragaai_catalyst-2.2.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
92
+ ragaai_catalyst-2.2.1.dist-info/METADATA,sha256=GjsoMgBgsiwIVyWzWkz_k8y08gnD2TsdvnGJbTM7its,17677
93
+ ragaai_catalyst-2.2.1.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
94
+ ragaai_catalyst-2.2.1.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
95
+ ragaai_catalyst-2.2.1.dist-info/RECORD,,