SantoshKumar1310 commited on
Commit
76e7fd5
·
verified ·
1 Parent(s): 05a84b0

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +15 -6
model.py CHANGED
@@ -1,6 +1,7 @@
1
  """Model wrapper for LiteLLM"""
2
 
3
  import os
 
4
  from typing import List, Dict, Any, Optional
5
 
6
  try:
@@ -71,13 +72,21 @@ class LiteLLMModel:
71
  }
72
 
73
  if hasattr(message, 'tool_calls') and message.tool_calls:
74
- result["tool_calls"] = [
75
- {
 
 
 
 
 
 
 
 
 
 
76
  "name": tc.function.name,
77
- "arguments": eval(tc.function.arguments) if isinstance(tc.function.arguments, str) else tc.function.arguments
78
- }
79
- for tc in message.tool_calls
80
- ]
81
 
82
  return result
83
 
 
1
  """Model wrapper for LiteLLM"""
2
 
3
  import os
4
+ import json
5
  from typing import List, Dict, Any, Optional
6
 
7
  try:
 
72
  }
73
 
74
  if hasattr(message, 'tool_calls') and message.tool_calls:
75
+ result["tool_calls"] = []
76
+ for tc in message.tool_calls:
77
+ # Parse arguments if they're a string
78
+ args = tc.function.arguments
79
+ if isinstance(args, str):
80
+ try:
81
+ args = json.loads(args)
82
+ except:
83
+ args = {}
84
+
85
+ result["tool_calls"].append({
86
+ "id": tc.id if hasattr(tc, 'id') else f"call_{tc.function.name}",
87
  "name": tc.function.name,
88
+ "arguments": args
89
+ })
 
 
90
 
91
  return result
92