summaryrefslogtreecommitdiff
path: root/rag/generator/abstract.py
blob: a53b5d8845aba74385f2877ada9f5c2603487b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from abc import ABC, abstractmethod

from typing import Any, Generator

from .prompt import Prompt


class AbstractGenerator(ABC, type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            instance = super().__call__(*args, **kwargs)
            cls._instances[cls] = instance
        return cls._instances[cls]

    @abstractmethod
    def generate(self, prompt: Prompt) -> Generator[Any, Any, Any]:
        pass