ragaai-catalyst 2.1.5b21__py3-none-any.whl → 2.1.5b22__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.
@@ -2,9 +2,9 @@ from ..data.data_structure import LLMCall
2
2
  from .trace_utils import (
3
3
  calculate_cost,
4
4
  convert_usage_to_dict,
5
- load_model_costs,
6
5
  )
7
6
  from importlib import resources
7
+ from litellm import model_cost
8
8
  import json
9
9
  import os
10
10
  import asyncio
@@ -38,7 +38,13 @@ def extract_model_name(args, kwargs, result):
38
38
  metadata = manager.metadata
39
39
  model_name = metadata.get('ls_model_name', None)
40
40
  if model_name:
41
- model = model_name
41
+ model = model_name
42
+
43
+ if not model:
44
+ if 'to_dict' in dir(result):
45
+ result = result.to_dict()
46
+ if 'model_version' in result:
47
+ model = result['model_version']
42
48
 
43
49
 
44
50
  # Normalize Google model names
@@ -50,11 +56,6 @@ def extract_model_name(args, kwargs, result):
50
56
  return "gemini-1.5-pro"
51
57
  if "gemini-pro" in model:
52
58
  return "gemini-pro"
53
-
54
- if 'to_dict' in dir(result):
55
- result = result.to_dict()
56
- if 'model_version' in result:
57
- model = result['model_version']
58
59
 
59
60
  return model or "default"
60
61
 
@@ -268,10 +269,21 @@ def num_tokens_from_messages(model="gpt-4o-mini-2024-07-18", prompt_messages=Non
268
269
  }
269
270
 
270
271
  def extract_input_data(args, kwargs, result):
271
- """Extract input data from function call"""
272
+ """Sanitize and format input data, including handling of nested lists and dictionaries."""
273
+
274
+ def sanitize_value(value):
275
+ if isinstance(value, (int, float, bool, str)):
276
+ return value
277
+ elif isinstance(value, list):
278
+ return [sanitize_value(item) for item in value]
279
+ elif isinstance(value, dict):
280
+ return {key: sanitize_value(val) for key, val in value.items()}
281
+ else:
282
+ return str(value) # Convert non-standard types to string
283
+
272
284
  return {
273
- 'args': args,
274
- 'kwargs': kwargs
285
+ "args": [sanitize_value(arg) for arg in args],
286
+ "kwargs": {key: sanitize_value(val) for key, val in kwargs.items()},
275
287
  }
276
288
 
277
289
 
@@ -370,6 +382,13 @@ def extract_llm_output(result):
370
382
  })
371
383
  return OutputResponse(output)
372
384
 
385
+ # Handle AIMessage Format
386
+ if hasattr(result, "content"):
387
+ return OutputResponse([{
388
+ "content": result.content,
389
+ "role": getattr(result, "role", "assistant")
390
+ }])
391
+
373
392
  # Handle Vertex AI format
374
393
  # format1
375
394
  if hasattr(result, "text"):
@@ -517,7 +536,7 @@ def extract_llm_data(args, kwargs, result):
517
536
  token_usage = extract_token_usage(result)
518
537
 
519
538
  # Load model costs
520
- model_costs = load_model_costs()
539
+ model_costs = model_cost
521
540
 
522
541
  # Calculate cost
523
542
  cost = calculate_llm_cost(token_usage, model_name, model_costs)