wangzhibo
2026-08-30 c8515170fd399b4d2dfaebb59128d4674e58915e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os
import sys
import importlib
from config.logger import setup_logging
 
logger = setup_logging()
 
 
def create_instance(class_name, *args, **kwargs):
    if os.path.exists(
        os.path.join("core", "providers", "memory", class_name, f"{class_name}.py")
    ):
        lib_name = f"core.providers.memory.{class_name}.{class_name}"
        if lib_name not in sys.modules:
            sys.modules[lib_name] = importlib.import_module(f"{lib_name}")
        return sys.modules[lib_name].MemoryProvider(*args, **kwargs)
 
    raise ValueError(f"不支持的记忆服务类型: {class_name}")