fix(model): Fix the bug that the webserver cannot return model instances

This commit is contained in:
FangYin Cheng
2023-09-14 12:36:18 +08:00
parent 7b64c03d58
commit f304f9709d
5 changed files with 29 additions and 18 deletions

View File

@@ -3,12 +3,15 @@ from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Type, Dict, TypeVar, Optional, Union, TYPE_CHECKING
from enum import Enum
import logging
import asyncio
# Checking for type hints during runtime
if TYPE_CHECKING:
from fastapi import FastAPI
logger = logging.getLogger(__name__)
class LifeCycle:
"""This class defines hooks for lifecycle events of a component."""
@@ -40,6 +43,7 @@ class LifeCycle:
class ComponetType(str, Enum):
WORKER_MANAGER = "dbgpt_worker_manager"
MODEL_CONTROLLER = "dbgpt_model_controller"
class BaseComponet(LifeCycle, ABC):
@@ -92,6 +96,7 @@ class SystemApp(LifeCycle):
raise RuntimeError(
f"Componse name {name} already exists: {self.componets[name]}"
)
logger.info(f"Register componet with name {name} and instance: {instance}")
self.componets[name] = instance
instance.init_app(self)