File size: 1,767 Bytes
fcc38f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Abstract base class for model interfaces.
Defines the minimal standard interface that all model implementations must follow.
"""

from abc import ABC, abstractmethod
from typing import List, Dict, Any

class BaseModelInterface(ABC):
    """
    Base class for all model interfaces that provides a standardized
    interface for interacting with different underlying models.
    """

    def __init__(self, config: Dict[str, Any]):
        """
        Initialize the model interface with a configuration dictionary.
        
        Args:
            config: Configuration dictionary containing model parameters
        """
        self.config = config
        
    @abstractmethod
    def generate(self, prompts: List[Any], **kwargs) -> List[Dict[str, Any]]:
        """
        Generate responses for the given prompts.
        
        Args:
            prompts: List of prompts (strings or dicts with messages/images)
            **kwargs: Additional generation parameters
            
        Returns:
            List of response dictionaries with at least 'text' field
        """
        pass
    
    @abstractmethod
    def format_prompt(self, messages: List[Dict[str, Any]]) -> str:
        """
        Format conversation messages into a prompt string.
        
        Args:
            messages: List of message dictionaries
            
        Returns:
            Formatted prompt string
        """
        pass
    
    def get_model_info(self) -> Dict[str, Any]:
        """
        Get basic information about the model.
        
        Returns:
            Dictionary with model information
        """
        return {
            "name": self.config.get("name", "unknown"),
            "type": self.config.get("type", "unknown"),
        }