SantoshKumar1310 commited on
Commit
321243d
·
verified ·
1 Parent(s): b63587d

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +36 -15
model.py CHANGED
@@ -11,6 +11,7 @@ except ImportError:
11
  print("⚠️ litellm not installed. Install with: pip install litellm")
12
  litellm = None
13
 
 
14
  class LiteLLMModel:
15
  """Wrapper for LiteLLM models"""
16
 
@@ -52,22 +53,40 @@ class LiteLLMModel:
52
  api_key = os.getenv("GEMINI_API_KEY")
53
  if not api_key:
54
  raise RuntimeError("GEMINI_API_KEY not set in environment")
55
- provider = "google"
56
- model_name = (
57
- f"google/{self.model_id}"
58
- if not self.model_id.startswith("google/")
59
- else self.model_id
60
- )
61
- response = litellm.completion(
62
- provider=provider, # <-- REQUIRED
63
- model=model_name,
64
- api_key=api_key, # <-- REQUIRED
65
- messages=messages,
66
- tools=formatted_tools,
67
- temperature=0.1
68
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  else:
70
- # For other models/providers, only pass model (configure as needed for your environment)
71
  response = litellm.completion(
72
  model=self.model_id,
73
  messages=messages,
@@ -89,12 +108,14 @@ class LiteLLMModel:
89
  }
90
  for tc in message.tool_calls
91
  ]
 
92
  return result
93
 
94
  except Exception as e:
95
  print(f"Model error: {e}")
96
  return {"content": "Unknown"}
97
 
 
98
  def get_model(model_type: str, model_id: str):
99
  """Get model instance"""
100
  if model_type == "LiteLLMModel":
 
11
  print("⚠️ litellm not installed. Install with: pip install litellm")
12
  litellm = None
13
 
14
+
15
  class LiteLLMModel:
16
  """Wrapper for LiteLLM models"""
17
 
 
53
  api_key = os.getenv("GEMINI_API_KEY")
54
  if not api_key:
55
  raise RuntimeError("GEMINI_API_KEY not set in environment")
56
+
57
+ # Try with original model ID
58
+ model_name_1 = self.model_id
59
+ # Try adding "google/" prefix if missing
60
+ model_name_2 = f"google/{self.model_id}" if not self.model_id.startswith("google/") else self.model_id
61
+
62
+ # Debug print for environment details
63
+ print("DEBUG: GEMINI_API_KEY last4:", api_key[-4:])
64
+
65
+ # Try first model_name_1
66
+ try:
67
+ print(f"DEBUG: Trying Gemini with model_name_1 = {model_name_1}")
68
+ response = litellm.completion(
69
+ provider="google",
70
+ model=model_name_1,
71
+ api_key=api_key,
72
+ messages=messages,
73
+ tools=formatted_tools,
74
+ temperature=0.1
75
+ )
76
+ except Exception as e1:
77
+ print(f"DEBUG: model_name_1 failed: {e1}")
78
+ # Try model_name_2
79
+ print(f"DEBUG: Trying Gemini with model_name_2 = {model_name_2}")
80
+ response = litellm.completion(
81
+ provider="google",
82
+ model=model_name_2,
83
+ api_key=api_key,
84
+ messages=messages,
85
+ tools=formatted_tools,
86
+ temperature=0.1
87
+ )
88
  else:
89
+ # For other models/providers, pass model without provider and api_key
90
  response = litellm.completion(
91
  model=self.model_id,
92
  messages=messages,
 
108
  }
109
  for tc in message.tool_calls
110
  ]
111
+
112
  return result
113
 
114
  except Exception as e:
115
  print(f"Model error: {e}")
116
  return {"content": "Unknown"}
117
 
118
+
119
  def get_model(model_type: str, model_id: str):
120
  """Get model instance"""
121
  if model_type == "LiteLLMModel":