ragaai-catalyst 2.1.7.2b0__py3-none-any.whl → 2.1.7.3b0__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/tracers/utils/rag_trace_json_converter.py +38 -87
- {ragaai_catalyst-2.1.7.2b0.dist-info → ragaai_catalyst-2.1.7.3b0.dist-info}/METADATA +1 -1
- {ragaai_catalyst-2.1.7.2b0.dist-info → ragaai_catalyst-2.1.7.3b0.dist-info}/RECORD +6 -6
- {ragaai_catalyst-2.1.7.2b0.dist-info → ragaai_catalyst-2.1.7.3b0.dist-info}/WHEEL +1 -1
- {ragaai_catalyst-2.1.7.2b0.dist-info → ragaai_catalyst-2.1.7.3b0.dist-info}/licenses/LICENSE +0 -0
- {ragaai_catalyst-2.1.7.2b0.dist-info → ragaai_catalyst-2.1.7.3b0.dist-info}/top_level.txt +0 -0
@@ -44,7 +44,7 @@ def rag_trace_json_converter(input_trace, custom_model_cost, trace_id, user_deta
|
|
44
44
|
if isinstance(message, str):
|
45
45
|
human_index = message.find("Human:")
|
46
46
|
if human_index != -1:
|
47
|
-
human_message = message[human_index:]
|
47
|
+
human_message = message[human_index:].replace("Human:", "")
|
48
48
|
break
|
49
49
|
return human_message if human_message else value
|
50
50
|
except Exception as e:
|
@@ -212,14 +212,14 @@ def get_additional_metadata(spans, custom_model_cost, model_cost_dict, prompt=""
|
|
212
212
|
additional_metadata["tokens"]["prompt"] = span["attributes"]["llm.token_count.prompt"]
|
213
213
|
|
214
214
|
except:
|
215
|
-
logger.
|
215
|
+
logger.debug("Warning: prompt token not found. using fallback strategies to get tokens.")
|
216
216
|
try:
|
217
217
|
additional_metadata["tokens"]["prompt"] = num_tokens_from_messages(
|
218
218
|
model=additional_metadata["model_name"],
|
219
219
|
message=prompt
|
220
220
|
)
|
221
221
|
except Exception as e:
|
222
|
-
logger.
|
222
|
+
logger.debug(f"Failed to count prompt tokens: {str(e)}. Using 'gpt-4o-mini' model count as fallback.")
|
223
223
|
additional_metadata["tokens"]["prompt"] = num_tokens_from_messages(
|
224
224
|
model="gpt-4o-mini",
|
225
225
|
message=prompt
|
@@ -228,14 +228,14 @@ def get_additional_metadata(spans, custom_model_cost, model_cost_dict, prompt=""
|
|
228
228
|
try:
|
229
229
|
additional_metadata["tokens"]["completion"] = span["attributes"]["llm.token_count.completion"]
|
230
230
|
except:
|
231
|
-
logger.
|
231
|
+
logger.debug("Warning: completion token not found. using fallback strategies to get tokens.")
|
232
232
|
try:
|
233
233
|
additional_metadata["tokens"]["completion"] = num_tokens_from_messages(
|
234
234
|
model=additional_metadata["model_name"],
|
235
235
|
message=response
|
236
236
|
)
|
237
237
|
except Exception as e:
|
238
|
-
logger.
|
238
|
+
logger.debug(f"Failed to count completion tokens: {str(e)}. Using 'gpt-4o-mini' model count as fallback.")
|
239
239
|
additional_metadata["tokens"]["completion"] = num_tokens_from_messages(
|
240
240
|
model="gpt-4o-mini",
|
241
241
|
message=response
|
@@ -299,96 +299,47 @@ def get_additional_metadata(spans, custom_model_cost, model_cost_dict, prompt=""
|
|
299
299
|
|
300
300
|
def num_tokens_from_messages(model, message):
|
301
301
|
try:
|
302
|
-
# Handle None or empty message
|
303
302
|
if not message:
|
304
|
-
logger.
|
303
|
+
logger.error("Empty or None message provided to token counter")
|
305
304
|
return 0
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
305
|
+
|
306
|
+
def num_tokens_from_string(text_content: str, encoding_name: str) -> int:
|
307
|
+
"""Returns the number of tokens in a text string."""
|
308
|
+
if isinstance(text_content, list):
|
309
|
+
list_str = str(text_content[0]) if text_content else ""
|
310
|
+
pattern = r"content=\'(.*?)\'(?:\s+additional_kwargs=|$)"
|
311
|
+
match = re.search(pattern, list_str, re.DOTALL)
|
312
|
+
if match:
|
313
|
+
text_content = match.group(1) # Extract content and process it for tokens
|
314
|
+
else:
|
315
|
+
text_content = list_str
|
316
|
+
try:
|
317
|
+
encoding = tiktoken.get_encoding(encoding_name)
|
318
|
+
return len(encoding.encode(text_content))
|
319
|
+
except Exception as e:
|
320
|
+
logger.warning(f"Error encoding with {encoding_name}: {str(e)}")
|
314
321
|
try:
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
if re.match(r'^gpt-4o.*', model):
|
329
|
-
"""Check for GPT-4 Optimized models (pattern: ^gpt-4o.*)
|
330
|
-
Examples that match:
|
331
|
-
- gpt-4o
|
332
|
-
- gpt-4o-mini
|
333
|
-
- gpt-4o-2024-08-06
|
334
|
-
The .* allows for any characters after 'gpt-4o'
|
335
|
-
"""
|
322
|
+
fallback_encoding = tiktoken.get_encoding("cl100k_base")
|
323
|
+
return len(fallback_encoding.encode(text_content))
|
324
|
+
except:
|
325
|
+
logger.debug("Failed to use fallback encoding")
|
326
|
+
return 0
|
327
|
+
|
328
|
+
# Determine which encoding to use based on model name
|
329
|
+
encoding_name = "o200k_base"
|
330
|
+
|
331
|
+
if re.match(r'^gpt-', model):
|
332
|
+
if re.match(r'^gpt-(4o|4\.1).*', model):
|
333
|
+
# GPT-4o and GPT-4.1 models
|
336
334
|
encoding_name = "o200k_base"
|
337
|
-
return num_tokens_from_string(message, encoding_name)
|
338
|
-
|
339
335
|
elif re.match(r'^gpt-(4|3\.5).*', model):
|
340
|
-
|
341
|
-
Uses cl100k_base encoding for GPT-4 and GPT-3.5 models
|
342
|
-
Examples that match:
|
343
|
-
- gpt-4
|
344
|
-
- gpt-4-turbo
|
345
|
-
- gpt-4-2024-08-06
|
346
|
-
- gpt-3.5-turbo
|
347
|
-
- gpt-3.5-turbo-16k
|
348
|
-
"""
|
336
|
+
# GPT-4 and GPT-3.5 models
|
349
337
|
encoding_name = "cl100k_base"
|
350
|
-
|
338
|
+
else:
|
339
|
+
logger.debug(f"Using default token counter for: {model}.")
|
351
340
|
|
352
|
-
|
353
|
-
"""Default case for any other GPT models
|
354
|
-
Uses o200k_base encoding as the default tokenizer
|
355
|
-
"""
|
356
|
-
return num_tokens_from_string(message, encoding_name="o200k_base")
|
341
|
+
return num_tokens_from_string(message, encoding_name)
|
357
342
|
|
358
|
-
|
359
|
-
# Gemini models
|
360
|
-
elif re.match(r'^gemini-', model):
|
361
|
-
try:
|
362
|
-
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
363
|
-
if not GOOGLE_API_KEY:
|
364
|
-
logger.warning("GOOGLE_API_KEY not found in environment variables")
|
365
|
-
return 0
|
366
|
-
|
367
|
-
import google.generativeai as genai
|
368
|
-
client = genai.Client(api_key=GOOGLE_API_KEY)
|
369
|
-
|
370
|
-
response = client.models.count_tokens(
|
371
|
-
model=model,
|
372
|
-
contents=message,
|
373
|
-
)
|
374
|
-
return response.total_tokens
|
375
|
-
except ImportError:
|
376
|
-
logger.warning("google.generativeai module not found. Install with pip install google-generativeai")
|
377
|
-
return 0
|
378
|
-
except Exception as e:
|
379
|
-
logger.warning(f"Error counting tokens for Gemini model: {str(e)}")
|
380
|
-
return 0
|
381
|
-
|
382
|
-
# Default case for unknown models
|
383
|
-
else:
|
384
|
-
logger.warning(f"Unknown model type: {model}. Using default token counter.")
|
385
|
-
try:
|
386
|
-
# Use cl100k_base as a fallback for unknown models
|
387
|
-
encoding = tiktoken.get_encoding("cl100k_base")
|
388
|
-
return len(encoding.encode(message))
|
389
|
-
except:
|
390
|
-
logger.error("Failed to use fallback encoding for unknown model")
|
391
|
-
return 0
|
392
343
|
except Exception as e:
|
393
344
|
logger.error(f"Unexpected error in token counting: {str(e)}")
|
394
345
|
return 0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ragaai_catalyst
|
3
|
-
Version: 2.1.7.
|
3
|
+
Version: 2.1.7.3b0
|
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>, Tushar Kumar <tushar.kumar@raga.ai>
|
6
6
|
Requires-Python: <=3.13.2,>=3.10
|
@@ -85,11 +85,11 @@ ragaai_catalyst/tracers/utils/convert_llama_instru_callback.py,sha256=8qLo7x4Zsn
|
|
85
85
|
ragaai_catalyst/tracers/utils/extraction_logic_llama_index.py,sha256=ZhPs0YhVtB82-Pq9o1BvCinKE_WPvVxPTEcZjlJbFYM,2371
|
86
86
|
ragaai_catalyst/tracers/utils/langchain_tracer_extraction_logic.py,sha256=XS2_x2qneqEx9oAighLg-LRiueWcESLwIC2r7eJT-Ww,3117
|
87
87
|
ragaai_catalyst/tracers/utils/model_prices_and_context_window_backup.json,sha256=C3uwkibJ08C9sOX-54kulZYmJlIpZ-SQpfE6HNGrjbM,343502
|
88
|
-
ragaai_catalyst/tracers/utils/rag_trace_json_converter.py,sha256=
|
88
|
+
ragaai_catalyst/tracers/utils/rag_trace_json_converter.py,sha256=jwScK9bo0NGpaOgeII-m2l_ovcHNo9Pd2wkZHFBt0zc,18559
|
89
89
|
ragaai_catalyst/tracers/utils/trace_json_converter.py,sha256=E0_QfciQMMpCtQYrNB4l8HJhlaFalr5bkMqkVRgQahY,14073
|
90
90
|
ragaai_catalyst/tracers/utils/utils.py,sha256=ViygfJ7vZ7U0CTSA1lbxVloHp4NSlmfDzBRNCJuMhis,2374
|
91
|
-
ragaai_catalyst-2.1.7.
|
92
|
-
ragaai_catalyst-2.1.7.
|
93
|
-
ragaai_catalyst-2.1.7.
|
94
|
-
ragaai_catalyst-2.1.7.
|
95
|
-
ragaai_catalyst-2.1.7.
|
91
|
+
ragaai_catalyst-2.1.7.3b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
92
|
+
ragaai_catalyst-2.1.7.3b0.dist-info/METADATA,sha256=5TXfNHsBByRy9NfLRp8vCsmedgGXJpq0qc_18g43HYA,17607
|
93
|
+
ragaai_catalyst-2.1.7.3b0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
94
|
+
ragaai_catalyst-2.1.7.3b0.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
|
95
|
+
ragaai_catalyst-2.1.7.3b0.dist-info/RECORD,,
|
{ragaai_catalyst-2.1.7.2b0.dist-info → ragaai_catalyst-2.1.7.3b0.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
File without changes
|