""" Configuration file for Smolagents GAIA Evaluation Agent Contains all model parameters, system prompts, and tools settings """ import os import json MODEL_CONFIG = { "model_strategy": "remote", "local_models": { "llm_model": "./models/Llama-3.3-70B-Instruct", "fallback_model": "./models/zephyr-7b-beta", "embedding_model": "./models/gte-small", }, "remote_models": { "llm_model": "mistralai/Mistral-7B-Instruct-v0.2", "fallback_model": "HuggingFaceH4/zephyr-7b-beta", "embedding_model": "sentence-transformers/all-MiniLM-L6-v2", }, "local_light_models": { "llm_model": "./models/DialoGPT-medium", "fallback_model": "./models/Qwen2.5-7B-Instruct", "embedding_model": "./models/all-MiniLM-L6-v2", }, "llm_model": "mistralai/Mistral-7B-Instruct-v0.2", "fallback_model": "HuggingFaceH4/zephyr-7b-beta", "embedding_model": "sentence-transformers/all-MiniLM-L6-v2", "temperature": 0.7, "max_new_tokens": 8192, "top_p": 0.9, "device": "auto", "torch_dtype": "auto", "load_in_8bit": False, "load_in_4bit": False, "use_cache": True, "enable_web_search": True, "enable_article_extraction": True, "enable_rag": True, "enable_calculator": True, "max_search_results": 5, "search_timeout": 15, "max_articles_to_read": 3, "max_article_length": 2000, "chunk_size": 500, "chunk_overlap": 50, "max_retrieved_chunks": 3, } SYSTEM_PROMPTS = { "code_agent": ( "You are a general AI assistant tasked with solving complex questions accurately.\n" "Use tools and write Python code to gather information, perform calculations, or process data.\n" "Follow a Thought-Action-Observation cycle:\n" "- Thought: Plan the steps to solve the task\n" "- Action: Write and execute code or call tools\n" "- Observation: Analyze the output and adjust if needed\n" "Provide concise, exact answers. For calculations, show your work step by step.\n" "When using web search, synthesize information from multiple sources." ), "evaluation": ( "You are answering tricky and hard questions. " "Provide accurate, comprehensive, and concise answers. " "Use available tools to gather current information or perform calculations. " "Focus on precision and exactness in your responses." "Penguins are birds." ) } TOOL_DESCRIPTIONS = { "web_search": "Search the web for current information using DuckDuckGo", "article_extractor": "Extract full content from web articles and news sites", "calculator": "Perform mathematical calculations and evaluations", "file_processor": "Process and extract text from uploaded files", "wikipedia_search": "Search Wikipedia for factual information", "rag_search": "Search through a knowledge base using vector similarity" } SUPPORTED_FILE_TYPES = [".txt", ".pdf", ".csv", ".docx", ".xlsx", ".png", ".jpg", ".jpeg"] CONFIG_FILE = "local_config.json" def save_config(): """Save current configuration to file""" try: config_data = { "model_strategy": MODEL_CONFIG["model_strategy"], "local_models": MODEL_CONFIG["local_models"], "local_light_models": MODEL_CONFIG["local_light_models"] } with open(CONFIG_FILE, 'w') as f: json.dump(config_data, f, indent=2) except Exception as e: print(f"Warning: Could not save config: {e}") def load_config(): """Load configuration from file""" try: if os.path.exists(CONFIG_FILE): with open(CONFIG_FILE, 'r') as f: config_data = json.load(f) MODEL_CONFIG["model_strategy"] = config_data.get("model_strategy", "auto") MODEL_CONFIG["local_models"].update(config_data.get("local_models", {})) MODEL_CONFIG["local_light_models"].update(config_data.get("local_light_models", {})) print(f"Loaded configuration from {CONFIG_FILE}") except Exception as e: print(f"Warning: Could not load config: {e}") load_config() def get_model_config(): """Get the model configuration dictionary""" config = MODEL_CONFIG.copy() strategy = config["model_strategy"] if strategy == "local" or (strategy == "auto" and _check_local_models_available()): config.update(config["local_models"]) config["use_local"] = True config["model_type"] = "local" print("Using local models") elif strategy == "local_light" or (strategy == "auto" and _check_local_light_models_available()): config.update(config["local_light_models"]) config["use_local"] = True config["model_type"] = "local_light" print("Using local light models") else: config.update(config["remote_models"]) config["use_local"] = False config["model_type"] = "remote" print("Using remote models") return config def _check_local_models_available(): """Check if local models are available""" import os local_models = MODEL_CONFIG["local_models"] for model_type, path in local_models.items(): if not os.path.exists(path): return False return True def _check_local_light_models_available(): """Check if local light models are available""" import os local_models = MODEL_CONFIG["local_light_models"] for model_type, path in local_models.items(): if not os.path.exists(path): return False return True def set_model_strategy(strategy): valid_strategies = ["local", "local_light", "remote", "auto"] if strategy not in valid_strategies: raise ValueError(f"Invalid strategy. Must be one of: {valid_strategies}") MODEL_CONFIG["model_strategy"] = strategy save_config() def set_local_model_paths(llm_path=None, fallback_path=None, embedding_path=None): """Set custom paths for local models""" if llm_path: MODEL_CONFIG["local_models"]["llm_model"] = llm_path if fallback_path: MODEL_CONFIG["local_models"]["fallback_model"] = fallback_path if embedding_path: MODEL_CONFIG["local_models"]["embedding_model"] = embedding_path save_config() def get_device_config(): """Get device configuration for local models""" import torch config = get_model_config() device = config["device"] if device == "auto": if torch.cuda.is_available(): device = "cuda" elif hasattr(torch.backends, 'mps') and torch.backends.mps.is_available(): device = "mps" else: device = "cpu" return { "device": device, "torch_dtype": config["torch_dtype"], "load_in_8bit": config["load_in_8bit"], "load_in_4bit": config["load_in_4bit"], "use_cache": config["use_cache"] } def get_system_prompt(prompt_type: str = "code_agent") -> str: """Get system prompt for the specified type""" return SYSTEM_PROMPTS.get(prompt_type, SYSTEM_PROMPTS["code_agent"]) def get_supported_file_types(): """Get list of supported file types""" return SUPPORTED_FILE_TYPES.copy() def get_hf_token(): """Get Hugging Face API token from environment""" return os.getenv("HF_TOKEN", "") def get_smolagents_config(): """Get configuration specific to smolagents setup""" return { "model_id": MODEL_CONFIG["llm_model"], "temperature": MODEL_CONFIG["temperature"], "max_new_tokens": MODEL_CONFIG["max_new_tokens"] } def get_tools_config(): """Get configuration for custom tools""" return { "web_search": { "enabled": MODEL_CONFIG["enable_web_search"], "max_results": MODEL_CONFIG["max_search_results"], "timeout": MODEL_CONFIG["search_timeout"] }, "article_extraction": { "enabled": MODEL_CONFIG["enable_article_extraction"], "max_articles": MODEL_CONFIG["max_articles_to_read"], "max_length": MODEL_CONFIG["max_article_length"] }, "rag": { "enabled": MODEL_CONFIG["enable_rag"], "embedding_model": MODEL_CONFIG["embedding_model"], "chunk_size": MODEL_CONFIG["chunk_size"], "max_chunks": MODEL_CONFIG["max_retrieved_chunks"] } }