Spaces:
Runtime error
Runtime error
Create core_agent.py
Browse files- core_agent.py +51 -0
core_agent.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import (
|
| 2 |
+
CodeAgent,
|
| 3 |
+
DuckDuckGoSearchTool,
|
| 4 |
+
HfApiModel,
|
| 5 |
+
LiteLLMModel,
|
| 6 |
+
OpenAIServerModel,
|
| 7 |
+
PythonInterpreterTool,
|
| 8 |
+
tool,
|
| 9 |
+
InferenceClientModel
|
| 10 |
+
)
|
| 11 |
+
from typing import List, Dict, Any, Optional
|
| 12 |
+
import os
|
| 13 |
+
import tempfile
|
| 14 |
+
import re
|
| 15 |
+
import json
|
| 16 |
+
import requests
|
| 17 |
+
from urllib.parse import urlparse
|
| 18 |
+
|
| 19 |
+
class GAIAAgent:
|
| 20 |
+
def __init__(
|
| 21 |
+
self,
|
| 22 |
+
model_type: str = "HfApiModel",
|
| 23 |
+
model_id: Optional[str] = None,
|
| 24 |
+
api_key: Optional[str] = None,
|
| 25 |
+
api_base: Optional[str] = None,
|
| 26 |
+
temperature: float = 0.2,
|
| 27 |
+
executor_type: str = "local", # Changed from use_e2b to executor_type
|
| 28 |
+
additional_imports: List[str] = None,
|
| 29 |
+
additional_tools: List[Any] = None,
|
| 30 |
+
system_prompt: Optional[str] = None, # We'll still accept this parameter but not use it directly
|
| 31 |
+
verbose: bool = False,
|
| 32 |
+
provider: Optional[str] = None, # Add provider for InferenceClientModel
|
| 33 |
+
timeout: Optional[int] = None # Add timeout for InferenceClientModel
|
| 34 |
+
):
|
| 35 |
+
"""
|
| 36 |
+
Initialize a GAIAAgent with specified configuration
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
model_type: Type of model to use (HfApiModel, LiteLLMModel, OpenAIServerModel, InferenceClientModel)
|
| 40 |
+
model_id: ID of the model to use
|
| 41 |
+
api_key: API key for the model provider
|
| 42 |
+
api_base: Base URL for API calls
|
| 43 |
+
temperature: Temperature for text generation
|
| 44 |
+
executor_type: Type of executor for code execution ('local' or 'e2b')
|
| 45 |
+
additional_imports: Additional Python modules to allow importing
|
| 46 |
+
additional_tools: Additional tools to provide to the agent
|
| 47 |
+
system_prompt: Custom system prompt to use (not directly used, kept for backward compatibility)
|
| 48 |
+
verbose: Enable verbose logging
|
| 49 |
+
provider: Provider for InferenceClientModel (e.g., "hf-inference")
|
| 50 |
+
timeout: Timeout in seconds for API calls
|
| 51 |
+
"""
|