Skip to content

Commit

Permalink
feat(core): Support cross-service data recording and analyze (#665)
Browse files Browse the repository at this point in the history
Close #659
  • Loading branch information
Aries-ckt authored Oct 12, 2023
2 parents c0219a6 + 87f2484 commit 1acb8da
Show file tree
Hide file tree
Showing 29 changed files with 2,215 additions and 109 deletions.
4 changes: 2 additions & 2 deletions docker/base/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ IMAGE_NAME_ARGS=""
PIP_INDEX_URL="https://pypi.org/simple"
# en or zh
LANGUAGE="en"
BUILD_LOCAL_CODE="false"
BUILD_LOCAL_CODE="true"
LOAD_EXAMPLES="true"
BUILD_NETWORK=""
DB_GPT_INSTALL_MODEL="default"
Expand All @@ -26,7 +26,7 @@ usage () {
echo " [-n|--image-name image name] Current image name, default: db-gpt"
echo " [-i|--pip-index-url pip index url] Pip index url, default: https://pypi.org/simple"
echo " [--language en or zh] You language, default: en"
echo " [--build-local-code true or false] Whether to use the local project code to package the image, default: false"
echo " [--build-local-code true or false] Whether to use the local project code to package the image, default: true"
echo " [--load-examples true or false] Whether to load examples to default database default: true"
echo " [--network network name] The network of docker build"
echo " [--install-mode mode name] Installation mode name, default: default, If you completely use openai's service, you can set the mode name to 'openai'"
Expand Down
309 changes: 309 additions & 0 deletions docs/getting_started/observability.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Getting Started
getting_started/concepts.md
getting_started/tutorials.md
getting_started/faq.rst
getting_started/observability.md


Modules
Expand Down
121 changes: 121 additions & 0 deletions docs/locales/zh_CN/LC_MESSAGES/getting_started/observability.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2023, csunny
# This file is distributed under the same license as the DB-GPT package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: DB-GPT 👏👏 0.3.9\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-12 11:54+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: zh_CN\n"
"Language-Team: zh_CN <LL@li.org>\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"

#: ../../getting_started/observability.md:1 c88ce18295444597baa7355efc79ab15
msgid "Debugging"
msgstr ""

#: ../../getting_started/observability.md:4 522a4e83c62c493381ca3a452ced8ecf
msgid ""
"DB-GPT provides a set of tools to help you troubleshoot and resolve some "
"of the issues you may encounter."
msgstr ""
"DB-GPT 提供了一套工具来帮助你排查和解决一些遇到的问题。"

#: ../../getting_started/observability.md:7 7fe5b8ab29194e42b74a8ab3e77006c7
msgid "Trace Logs"
msgstr "追踪日志"

#: ../../getting_started/observability.md:9 8a55f7a2b5a247d49728969f179bf50d
msgid ""
"DB-GPT writes some critical system runtime information to trace logs. By "
"default, these are located in `logs/dbgpt*.jsonl`."
msgstr ""
"DB-GPT 会将一些系统运行的关键的信息写入到追踪日志中,默认情况下,在 `logs/dbgpt*.jsonl` 中。"

#: ../../getting_started/observability.md:11 5e2b847179e9427a8ae022b5338cbbd9
msgid ""
"DB-GPT also offers a command-line tool, `dbgpt trace`, to help you "
"analyze these trace logs. You can see its specific usage with the command"
" `dbgpt trace --help`."
msgstr ""
"DB-GPT 也提供了命令工具 `dbgpt trace` 命令来帮助你分析追踪日志,你可以使用命令 `dbgpt trace --help` 来查看具体的用法。"

#: ../../getting_started/observability.md:14 6e0c9c4ba6ac4eb49d9289b0d63f77fb
msgid "查看对话详情"
msgstr ""

#: ../../getting_started/observability.md:16 b9badbab74de47f192ff117d7d36fa72
msgid ""
"You can use the `dbgpt trace chat` command to view chat details. By "
"default, it will display the latest chat message."
msgstr ""
"你可以使用 `dbgpt trace chat` 命令来查看对话信息,默认情况会显示你最新的一条对话信息。"

#: ../../getting_started/observability.md:18 55c7466bd80d43c9a355d87daf2a2be7
msgid "Viewing Service Runtime Information"
msgstr "查看服务运行信息"

#: ../../getting_started/observability.md:24
#: ../../getting_started/observability.md:66
#: ../../getting_started/observability.md:98
#: ../../getting_started/observability.md:146
#: ../../getting_started/observability.md:200
#: ../../getting_started/observability.md:229
#: ../../getting_started/observability.md:249
#: ../../getting_started/observability.md:267 18907a58a0c3493aa24c17e367309471
#: 387f08b6cd864a7682522b5a40863e79 5fe0baa5803d4ca5ad0e8cbd8a859c8c
#: 7abbfdd996444999a24cbad852d2e545 957bdf6826e045608c8c3ebd06c8fe76
#: acddf2cdf8c94bd6864d66739fa26459 f3fcaf2b47774779bad2feb3ef4318c4
#: f99bb110024443f68cc8b7f19956eff4
msgid "You will see an output like:"
msgstr "你将会看到类似的输出:"

#: ../../getting_started/observability.md:60 5c8c213a5bac434bb3defe6611a03813
msgid "Viewing the Latest Chat Message"
msgstr "查看最近的一条对话信息"

#: ../../getting_started/observability.md:92 ce19873d8e754173849d14eaeab963d2
msgid "Viewing Chat Details and Call Chain"
msgstr "查看对话信息和调用链路"

#: ../../getting_started/observability.md:140 36bcc37971ce4d6682f1ea32e2e9a980
msgid "Viewing Chat Details Based on trace_id"
msgstr "根据 `trace_id` 查看对应的对话信息"

#: ../../getting_started/observability.md:172 c74968492f7544758c9d95fa831c4fcf
msgid "More `chat` Usage"
msgstr "更多 `chat` 用法"

#: ../../getting_started/observability.md:194 c2e5a7e7b1ee40fea15790d66b79eb11
msgid "Viewing Call Tree Based on `trace_id`"
msgstr "根据 `trace_id` 查看调用树"

#: ../../getting_started/observability.md:220 6bd64d2ad0ce442e8e81aa1ae7dd2189
msgid "Listing Trace Information"
msgstr "列出追踪信息"

#: ../../getting_started/observability.md:222 ce643441e8744ab09fcbd4081d2adb4a
msgid "Listing All Trace Information"
msgstr "列出全部追踪信息"

#: ../../getting_started/observability.md:243 374376d81ed54bc2a450505abfe7dc6d
msgid "Listing Trace Information by Trace Type"
msgstr "根据追踪类型列出追踪信息"

#: ../../getting_started/observability.md:261 8fc08a9c924d47309dc7062811c4fb62
msgid "Searching Trace Information"
msgstr "搜索追踪信息"

#: ../../getting_started/observability.md:281 3681413d196144389431422010a7e30f
msgid "More `list` Usage"
msgstr "更多 `list` 用法"

11 changes: 10 additions & 1 deletion pilot/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class ComponentType(str, Enum):
WORKER_MANAGER_FACTORY = "dbgpt_worker_manager_factory"
MODEL_CONTROLLER = "dbgpt_model_controller"
EXECUTOR_DEFAULT = "dbgpt_thread_pool_default"
TRACER = "dbgpt_tracer"
TRACER_SPAN_STORAGE = "dbgpt_tracer_span_storage"


class BaseComponent(LifeCycle, ABC):
Expand All @@ -70,6 +72,8 @@ def init_app(self, system_app: SystemApp):

T = TypeVar("T", bound=BaseComponent)

_EMPTY_DEFAULT_COMPONENT = "_EMPTY_DEFAULT_COMPONENT"


class SystemApp(LifeCycle):
"""Main System Application class that manages the lifecycle and registration of components."""
Expand Down Expand Up @@ -104,13 +108,18 @@ def register_instance(self, instance: T):
instance.init_app(self)

def get_component(
self, name: Union[str, ComponentType], component_type: Type[T]
self,
name: Union[str, ComponentType],
component_type: Type[T],
default_component=_EMPTY_DEFAULT_COMPONENT,
) -> T:
"""Retrieve a registered component by its name and type."""
if isinstance(name, ComponentType):
name = name.value
component = self.components.get(name)
if not component:
if default_component != _EMPTY_DEFAULT_COMPONENT:
return default_component
raise ValueError(f"No component found with name {name}")
if not isinstance(component, component_type):
raise TypeError(f"Component {name} is not of type {component_type}")
Expand Down
2 changes: 1 addition & 1 deletion pilot/model/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _parse_model_path(model_path: str) -> Tuple[bool, str]:
if not path.is_file():
model_paths = list(path.glob("*ggml*.gguf"))
if not model_paths:
return False
return False, None
model_path = str(model_paths[0])
logger.warn(
f"Model path {model_path} is not single file, use first *gglm*.gguf model file: {model_path}"
Expand Down
3 changes: 3 additions & 0 deletions pilot/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class ModelOutput:
error_code: int
model_context: Dict = None

def to_dict(self) -> Dict:
return asdict(self)


@dataclass
class WorkerApplyOutput:
Expand Down
2 changes: 2 additions & 0 deletions pilot/model/cluster/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class PromptRequest(BaseModel):
max_new_tokens: int = None
stop: str = None
echo: bool = True
span_id: str = None


class EmbeddingsRequest(BaseModel):
model: str
input: List[str]
span_id: str = None


class WorkerApplyRequest(BaseModel):
Expand Down
30 changes: 20 additions & 10 deletions pilot/model/cluster/embedding/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import TYPE_CHECKING

from pilot.model.parameter import BaseEmbeddingModelParameters
from pilot.utils.parameter_utils import _get_dict_from_obj
from pilot.utils.tracer import root_tracer, SpanType, SpanTypeRunName

if TYPE_CHECKING:
from langchain.embeddings.base import Embeddings
Expand All @@ -15,13 +17,21 @@ def __init__(self) -> None:
def load(
self, model_name: str, param: BaseEmbeddingModelParameters
) -> "Embeddings":
# add more models
if model_name in ["proxy_openai", "proxy_azure"]:
from langchain.embeddings import OpenAIEmbeddings

return OpenAIEmbeddings(**param.build_kwargs())
else:
from langchain.embeddings import HuggingFaceEmbeddings

kwargs = param.build_kwargs(model_name=param.model_path)
return HuggingFaceEmbeddings(**kwargs)
metadata = {
"model_name": model_name,
"run_service": SpanTypeRunName.EMBEDDING_MODEL.value,
"params": _get_dict_from_obj(param),
}
with root_tracer.start_span(
"EmbeddingLoader.load", span_type=SpanType.RUN, metadata=metadata
):
# add more models
if model_name in ["proxy_openai", "proxy_azure"]:
from langchain.embeddings import OpenAIEmbeddings

return OpenAIEmbeddings(**param.build_kwargs())
else:
from langchain.embeddings import HuggingFaceEmbeddings

kwargs = param.build_kwargs(model_name=param.model_path)
return HuggingFaceEmbeddings(**kwargs)
Loading

0 comments on commit 1acb8da

Please sign in to comment.