Spaces:
Sleeping
Sleeping
Update core_agent.py
Browse files- core_agent.py +9 -73
core_agent.py
CHANGED
@@ -6,7 +6,8 @@ from smolagents import (
|
|
6 |
OpenAIServerModel,
|
7 |
PythonInterpreterTool,
|
8 |
tool,
|
9 |
-
InferenceClientModel
|
|
|
10 |
)
|
11 |
from typing import List, Dict, Any, Optional
|
12 |
import os
|
@@ -211,80 +212,15 @@ class GAIAAgent:
|
|
211 |
self.system_prompt = system_prompt # Store for potential future use
|
212 |
|
213 |
# Initialize model based on configuration
|
214 |
-
|
215 |
-
if api_key is None:
|
216 |
-
api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
217 |
-
if not api_key:
|
218 |
-
raise ValueError("No Hugging Face token provided. Please set HUGGINGFACEHUB_API_TOKEN environment variable or pass api_key parameter.")
|
219 |
-
|
220 |
-
if self.verbose:
|
221 |
-
print(f"Using Hugging Face token: {api_key[:5]}...")
|
222 |
-
|
223 |
-
self.model = HfApiModel(
|
224 |
-
model_id=model_id or "meta-llama/Llama-3-70B-Instruct",
|
225 |
-
token=api_key,
|
226 |
-
temperature=temperature
|
227 |
-
)
|
228 |
-
elif model_type == "InferenceClientModel":
|
229 |
-
if api_key is None:
|
230 |
-
api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
231 |
-
if not api_key:
|
232 |
-
raise ValueError("No Hugging Face token provided. Please set HUGGINGFACEHUB_API_TOKEN environment variable or pass api_key parameter.")
|
233 |
-
|
234 |
-
if self.verbose:
|
235 |
-
print(f"Using Hugging Face token: {api_key[:5]}...")
|
236 |
|
237 |
-
|
238 |
-
model_id=model_id or "meta-llama/Llama-3-70B-Instruct",
|
239 |
-
provider=provider or "hf-inference",
|
240 |
-
token=api_key,
|
241 |
-
timeout=timeout or 120,
|
242 |
-
temperature=temperature
|
243 |
-
)
|
244 |
-
elif model_type == "LiteLLMModel":
|
245 |
-
from smolagents import LiteLLMModel
|
246 |
-
self.model = LiteLLMModel(
|
247 |
-
model_id=model_id or "gpt-4o",
|
248 |
-
api_key=api_key or os.getenv("OPENAI_API_KEY"),
|
249 |
-
temperature=temperature
|
250 |
-
)
|
251 |
-
elif model_type == "OpenAIServerModel":
|
252 |
-
# Check for xAI API key and base URL first
|
253 |
-
xai_api_key = os.getenv("XAI_API_KEY")
|
254 |
-
xai_api_base = os.getenv("XAI_API_BASE")
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
# If no API key specified, fall back to OPENAI_API_KEY
|
263 |
-
if api_key is None:
|
264 |
-
api_key = os.getenv("OPENAI_API_KEY")
|
265 |
-
if not api_key:
|
266 |
-
raise ValueError("No OpenAI API key provided. Please set OPENAI_API_KEY or XAI_API_KEY environment variable or pass api_key parameter.")
|
267 |
-
|
268 |
-
# If xAI API base is available and no api_base is provided, use it
|
269 |
-
if xai_api_base and api_base is None:
|
270 |
-
api_base = xai_api_base
|
271 |
-
if self.verbose:
|
272 |
-
print(f"Using xAI API base URL: {api_base}")
|
273 |
-
|
274 |
-
# If no API base specified but environment variable available, use it
|
275 |
-
if api_base is None:
|
276 |
-
api_base = os.getenv("AGENT_API_BASE")
|
277 |
-
if api_base and self.verbose:
|
278 |
-
print(f"Using API base from AGENT_API_BASE: {api_base}")
|
279 |
-
|
280 |
-
self.model = OpenAIServerModel(
|
281 |
-
model_id=model_id or "gpt-4o",
|
282 |
-
api_key=api_key,
|
283 |
-
api_base=api_base,
|
284 |
-
temperature=temperature
|
285 |
-
)
|
286 |
-
else:
|
287 |
-
raise ValueError(f"Unknown model type: {model_type}")
|
288 |
|
289 |
if self.verbose:
|
290 |
print(f"Initialized model: {model_type} - {model_id}")
|
|
|
6 |
OpenAIServerModel,
|
7 |
PythonInterpreterTool,
|
8 |
tool,
|
9 |
+
InferenceClientModel,
|
10 |
+
LiteLLMModel
|
11 |
)
|
12 |
from typing import List, Dict, Any, Optional
|
13 |
import os
|
|
|
212 |
self.system_prompt = system_prompt # Store for potential future use
|
213 |
|
214 |
# Initialize model based on configuration
|
215 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
+
model_type == "LiteLLMModel":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
+
self.model = LiteLLMModel(
|
220 |
+
model_id="gemini/gemini-2.0-flash",
|
221 |
+
api_key=os.getenv("GEMINI_API_KEY"),
|
222 |
+
temperature=temperature
|
223 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
if self.verbose:
|
226 |
print(f"Initialized model: {model_type} - {model_id}")
|