mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-28 21:12:13 +00:00
feat(core): APP use new SDK component (#1050)
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
import sys
|
||||
from typing import Type, Dict, TypeVar, Optional, Union, TYPE_CHECKING
|
||||
from enum import Enum
|
||||
import logging
|
||||
import asyncio
|
||||
from dbgpt.util.annotations import PublicAPI
|
||||
import logging
|
||||
import sys
|
||||
from abc import ABC, abstractmethod
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Dict, Optional, Type, TypeVar, Union
|
||||
|
||||
from dbgpt.util import AppConfig
|
||||
from dbgpt.util.annotations import PublicAPI
|
||||
|
||||
# Checking for type hints during runtime
|
||||
if TYPE_CHECKING:
|
||||
@@ -80,6 +81,9 @@ class ComponentType(str, Enum):
|
||||
UNIFIED_METADATA_DB_MANAGER_FACTORY = "dbgpt_unified_metadata_db_manager_factory"
|
||||
|
||||
|
||||
_EMPTY_DEFAULT_COMPONENT = "_EMPTY_DEFAULT_COMPONENT"
|
||||
|
||||
|
||||
@PublicAPI(stability="beta")
|
||||
class BaseComponent(LifeCycle, ABC):
|
||||
"""Abstract Base Component class. All custom components should extend this."""
|
||||
@@ -98,11 +102,37 @@ class BaseComponent(LifeCycle, ABC):
|
||||
with the main system app.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_instance(
|
||||
cls,
|
||||
system_app: SystemApp,
|
||||
default_component=_EMPTY_DEFAULT_COMPONENT,
|
||||
or_register_component: Type[BaseComponent] = None,
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> BaseComponent:
|
||||
"""Get the current component instance.
|
||||
|
||||
Args:
|
||||
system_app (SystemApp): The system app
|
||||
default_component : The default component instance if not retrieve by name
|
||||
or_register_component (Type[BaseComponent]): The new component to register if not retrieve by name
|
||||
|
||||
Returns:
|
||||
BaseComponent: The component instance
|
||||
"""
|
||||
return system_app.get_component(
|
||||
cls.name,
|
||||
cls,
|
||||
default_component=default_component,
|
||||
or_register_component=or_register_component,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
T = TypeVar("T", bound=BaseComponent)
|
||||
|
||||
_EMPTY_DEFAULT_COMPONENT = "_EMPTY_DEFAULT_COMPONENT"
|
||||
|
||||
|
||||
@PublicAPI(stability="beta")
|
||||
class SystemApp(LifeCycle):
|
||||
|
Reference in New Issue
Block a user