File size: 784 Bytes
bdafe83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from ..config import BackendConfig
from .anthropic import Claude
from .base import IntelligenceBackend
from .cohere import CohereAIChat
from .hf_transformers import TransformersConversational
from .human import Human
from .openai import OpenAIChat
from .dummy import Dummy

ALL_BACKENDS = [
    Human,
    OpenAIChat,
    CohereAIChat,
    TransformersConversational,
    Claude,
    Dummy,
]

BACKEND_REGISTRY = {backend.type_name: backend for backend in ALL_BACKENDS}


# Load a backend from a config dictionary
def load_backend(config: BackendConfig):
    try:
        backend_cls = BACKEND_REGISTRY[config.backend_type]
    except KeyError:
        raise ValueError(f"Unknown backend type: {config.backend_type}")

    backend = backend_cls.from_config(config)
    return backend