File size: 1,371 Bytes
0d599d9
02422e3
0d599d9
02422e3
0d599d9
 
 
02422e3
0d599d9
 
 
 
02422e3
0d599d9
02422e3
 
 
 
 
 
 
 
 
 
0d599d9
 
 
02422e3
 
 
 
 
 
0d599d9
02422e3
0d599d9
02422e3
 
0d599d9
02422e3
 
 
0d599d9
 
 
02422e3
0d599d9
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
"""
llm_adapter.py — Abstract base class for all LLM adapters.

V3 (Sidecar): adds stream_chat() abstract method.
"""

from abc import ABC, abstractmethod
from typing import AsyncGenerator, Optional


class LLMAdapter(ABC):
    """
    Minimal interface that all LLM adapters must implement.

    Methods
    -------
    chat(prompt, system_prompt) -> str
        Blocking single-turn call. Returns full response text.

    stream_chat(prompt, system_prompt) -> AsyncGenerator[str, None]
        Async streaming call. Yields token chunks as they arrive.

    get_model_name() -> str
        Returns the model identifier string.
    """

    @abstractmethod
    def chat(self, prompt: str, system_prompt: Optional[str] = None) -> str:
        """Blocking call — return full response as a string."""
        ...

    @abstractmethod
    async def stream_chat(
        self,
        prompt:        str,
        system_prompt: Optional[str] = None,
    ) -> AsyncGenerator[str, None]:
        """Async generator — yield token chunks as they arrive."""
        ...
        # Make this an async generator (required by ABC)
        # Concrete classes must use `yield` in their implementation
        yield  # type: ignore[misc]

    @abstractmethod
    def get_model_name(self) -> str:
        """Return the model identifier (e.g. 'gemini-2.0-flash-lite')."""
        ...