File size: 1,243 Bytes
b5386e2
 
a2e1879
b5386e2
 
 
 
 
 
 
 
a2e1879
 
 
 
 
 
 
 
b5386e2
a2e1879
 
b5386e2
 
a2e1879
 
 
b5386e2
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
# llm_clients/base.py
from abc import ABC, abstractmethod
from typing import Generator, Any, Dict, List, Optional

class LlmClient(ABC):
    """Abstract base class for all LLM clients."""

    def __init__(self, config: Dict[str, Any], system_prompt: str):
        self.config = config
        self.system_prompt = system_prompt

    def generate_content(self, prompt: str, files: Optional[List[Dict[str, Any]]] = None) -> str:
        """Generates a non-streaming response from the LLM. Files parameter is optional and ignored by default."""
        return self._generate_content_impl(prompt)

    def generate_content_stream(self, prompt: str, files: Optional[List[Dict[str, Any]]] = None) -> Generator[Any, None, None]:
        """Generates a streaming response from the LLM. Files parameter is optional and ignored by default."""
        return self._generate_content_stream_impl(prompt)
    
    @abstractmethod
    def _generate_content_impl(self, prompt: str) -> str:
        """Concrete implementation of content generation."""
        pass

    @abstractmethod 
    def _generate_content_stream_impl(self, prompt: str) -> Generator[Any, None, None]:
        """Concrete implementation of streaming content generation."""
        pass