feat(core): Support i18n (#1327)

This commit is contained in:
Fangyin Cheng
2024-03-25 20:15:39 +08:00
committed by GitHub
parent fa06be64c1
commit fcc325d411
179 changed files with 12052 additions and 69512 deletions

View File

@@ -2,12 +2,16 @@ import logging
from typing import Any, Optional
from dbgpt.core import (
BaseMessage,
InMemoryStorage,
MessageStorageItem,
ModelRequest,
StorageConversation,
StorageInterface,
)
from dbgpt.core.awel.flow import IOField, OperatorCategory, ViewMetadata
from dbgpt.core.operators import PreChatHistoryLoadOperator
from dbgpt.util.i18n_utils import _
from .serve import Serve
@@ -35,7 +39,9 @@ class ServePreChatHistoryLoadOperator(PreChatHistoryLoadOperator):
message_storage: Optional[StorageInterface[MessageStorageItem, Any]] = None,
**kwargs,
):
super().__init__(storage, message_storage, **kwargs)
super().__init__(
storage, message_storage, use_in_memory_storage_if_not_set=False, **kwargs
)
@property
def storage(self):
@@ -69,3 +75,41 @@ class ServePreChatHistoryLoadOperator(PreChatHistoryLoadOperator):
self._message_storage = InMemoryStorage()
return self._message_storage
return storage
class DefaultServePreChatHistoryLoadOperator(ServePreChatHistoryLoadOperator):
"""Default pre-chat history load operator for DB-GPT serve component
Use the storage and message storage of the serve component.
"""
metadata = ViewMetadata(
label=_("Default Chat History Load Operator"),
name="default_serve_pre_chat_history_load_operator",
category=OperatorCategory.CONVERSION,
description=_(
"Load chat history from the storage of the serve component."
"It is the default storage of DB-GPT"
),
parameters=[],
inputs=[
IOField.build_from(
_("Model Request"),
"model_request",
type=ModelRequest,
description=_("The model request."),
)
],
outputs=[
IOField.build_from(
label=_("Stored Messages"),
name="output_value",
type=BaseMessage,
description=_("The messages stored in the storage."),
is_list=True,
)
],
)
def __init__(self, **kwargs):
super().__init__(**kwargs)

View File

@@ -91,6 +91,8 @@ class Serve(BaseServe):
from dbgpt.storage.metadata.db_storage import SQLAlchemyStorage
from dbgpt.util.serialization.json_serialization import JsonSerializer
from .operators import DefaultServePreChatHistoryLoadOperator
self._db_manager = self.create_or_get_db_manager()
self._conv_storage = SQLAlchemyStorage(