""" Abstract base class for all LLM implementations. """ from abc import ABC, abstractmethod from typing import Optional, List, Dict, Any class BaseLLM(ABC): """Abstract interface for LLM models.""" def __init__(self, name: str, model_id: str): self.name = name self.model_id = model_id self._initialized = False @property def is_initialized(self) -> bool: return self._initialized @abstractmethod async def initialize(self) -> None: """Initialize the model. Must be called before generate().""" pass @abstractmethod async def generate( self, prompt: str = None, chat_messages: List[Dict[str, str]] = None, max_new_tokens: int = 150, temperature: float = 0.7, top_p: float = 0.9, **kwargs ) -> str: """ Generate text from prompt or chat messages. Args: prompt: Raw text prompt chat_messages: List of {"role": "...", "content": "..."} messages max_new_tokens: Maximum tokens to generate temperature: Sampling temperature top_p: Nucleus sampling parameter Returns: Generated text string """ pass @abstractmethod def get_info(self) -> Dict[str, Any]: """Return model information for /models endpoint.""" pass