mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-04 10:34:30 +00:00
feat(core): AWEL flow 2.0 backend code (#1879)
Co-authored-by: yhjun1026 <460342015@qq.com>
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import List, Optional, Union
|
||||
from sqlalchemy import URL
|
||||
|
||||
from dbgpt.component import SystemApp
|
||||
from dbgpt.core.interface.variables import VariablesProvider
|
||||
from dbgpt.serve.core import BaseServe
|
||||
from dbgpt.storage.metadata import DatabaseManager
|
||||
|
||||
@@ -40,6 +41,8 @@ class Serve(BaseServe):
|
||||
system_app, api_prefix, api_tags, db_url_or_db, try_create_tables
|
||||
)
|
||||
self._db_manager: Optional[DatabaseManager] = None
|
||||
self._variables_provider: Optional[VariablesProvider] = None
|
||||
self._serve_config: Optional[ServeConfig] = None
|
||||
|
||||
def init_app(self, system_app: SystemApp):
|
||||
if self._app_has_initiated:
|
||||
@@ -62,5 +65,37 @@ class Serve(BaseServe):
|
||||
|
||||
def before_start(self):
|
||||
"""Called before the start of the application."""
|
||||
# TODO: Your code here
|
||||
from dbgpt.core.interface.variables import (
|
||||
FernetEncryption,
|
||||
StorageVariablesProvider,
|
||||
)
|
||||
from dbgpt.storage.metadata.db_storage import SQLAlchemyStorage
|
||||
from dbgpt.util.serialization.json_serialization import JsonSerializer
|
||||
|
||||
from .models.models import ServeEntity, VariablesEntity
|
||||
from .models.variables_adapter import VariablesAdapter
|
||||
|
||||
self._db_manager = self.create_or_get_db_manager()
|
||||
self._serve_config = ServeConfig.from_app_config(
|
||||
self._system_app.config, SERVE_CONFIG_KEY_PREFIX
|
||||
)
|
||||
|
||||
self._db_manager = self.create_or_get_db_manager()
|
||||
storage_adapter = VariablesAdapter()
|
||||
serializer = JsonSerializer()
|
||||
storage = SQLAlchemyStorage(
|
||||
self._db_manager,
|
||||
VariablesEntity,
|
||||
storage_adapter,
|
||||
serializer,
|
||||
)
|
||||
self._variables_provider = StorageVariablesProvider(
|
||||
storage=storage,
|
||||
encryption=FernetEncryption(self._serve_config.encrypt_key),
|
||||
system_app=self._system_app,
|
||||
)
|
||||
|
||||
@property
|
||||
def variables_provider(self):
|
||||
"""Get the variables provider of the serve app with db storage"""
|
||||
return self._variables_provider
|
||||
|
Reference in New Issue
Block a user