""" Model manager for Clover - A terminal assistant for AI-powered project management Handles switching between different language models and manages API connections """ import json import os from typing import Any, Dict, Optional from config.settings import load_config from models.api_client import APIClient class ModelManager: """ Manages different language models for Clover CLI tool """ def __init__(self): """Initialize the model manager with configuration""" self.config = load_config() self.api_client = APIClient() def list_models(self) -> Dict[str, Any]: """ List available models on the server Returns: dict: Available models information """ try: result = self.api_client.list_models() if "error" in result: return { "error": result.get("error", "Failed to list models"), "models": [], } models_list = result.get("models", []) return { "models": models_list, "active_model": self.config.get("model", "qwen2.5-coder:7b"), "base_url": self.config.get("base_url", "http://192.168.8.223:11434"), } except Exception as e: return {"error": f"Failed to list models: {str(e)}", "models": []} def get_model(self, model_name: str = None) -> str: """ Get the active model name Args: model_name (str): Specific model name to use Returns: str: Model name to use """ if model_name: return model_name return self.config.get("model", "gpt-oss:20b") def set_model(self, model_name: str) -> bool: """ Set the active model for future operations Args: model_name (str): Name of the model to use Returns: bool: True if successful """ try: self.config["model"] = model_name # In a full implementation, we would save this to config file return True except Exception as e: print(f"Error setting model: {e}") return False def get_active_model_info(self) -> Dict[str, Any]: """ Get information about the currently active model Returns: dict: Information about active model """ return { "model": self.config.get("model", "gpt-oss:20b"), "base_url": self.config.get("base_url", "http://192.168.8.223:11434"), "timeout": self.config.get("timeout", 300), } def get_available_models(self) -> list: """ Get list of available models from the LLM server Returns: list: List of model names """ result = self.list_models() if "error" in result: return [] models = result.get("models", []) return [model.get("name", "") for model in models]