Skip to content

Commit

Permalink
python code style -- black, yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
IamWWT committed May 9, 2024
1 parent 0a4a2b3 commit 8b8a9b9
Show file tree
Hide file tree
Showing 195 changed files with 466 additions and 257 deletions.
1 change: 1 addition & 0 deletions dbgpt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""DB-GPT: Next Generation Data Interaction Solution with LLMs.
"""

from dbgpt import _version # noqa: E402
from dbgpt.component import BaseComponent, SystemApp # noqa: F401

Expand Down
8 changes: 4 additions & 4 deletions dbgpt/_private/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def __init__(self) -> None:
self.wenxin_model_version = os.getenv("WEN_XIN_MODEL_VERSION")
if self.wenxin_proxy_api_key and self.wenxin_proxy_api_secret:
os.environ["wenxin_proxyllm_proxy_api_key"] = self.wenxin_proxy_api_key
os.environ[
"wenxin_proxyllm_proxy_api_secret"
] = self.wenxin_proxy_api_secret
os.environ["wenxin_proxyllm_proxy_api_secret"] = (
self.wenxin_proxy_api_secret
)
os.environ["wenxin_proxyllm_proxyllm_backend"] = (
self.wenxin_model_version or ""
)
Expand Down Expand Up @@ -251,7 +251,7 @@ def __init__(self) -> None:
self.ElasticSearch_PORT = os.getenv("ElasticSearch_PORT", "9200")
self.ElasticSearch_USERNAME = os.getenv("ElasticSearch_USERNAME", None)
self.ElasticSearch_PASSWORD = os.getenv("ElasticSearch_PASSWORD", None)

## OceanBase Configuration
self.OB_HOST = os.getenv("OB_HOST", "127.0.0.1")
self.OB_PORT = int(os.getenv("OB_PORT", "2881"))
Expand Down
6 changes: 3 additions & 3 deletions dbgpt/agent/core/agent_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def __init__(self, system_app: SystemApp):
"""Create a new AgentManager."""
super().__init__(system_app)
self.system_app = system_app
self._agents: Dict[
str, Tuple[Type[ConversableAgent], ConversableAgent]
] = defaultdict()
self._agents: Dict[str, Tuple[Type[ConversableAgent], ConversableAgent]] = (
defaultdict()
)

self._core_agents: Set[str] = set()

Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/core/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Schema definition for the agent."""

from enum import Enum


Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/core/user_proxy_agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A proxy agent for the user."""

from .base_agent import ConversableAgent
from .profile import ProfileConfig

Expand Down
8 changes: 4 additions & 4 deletions dbgpt/agent/expand/actions/chart_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ async def run(
try:
if not self.resource_loader:
raise ValueError("ResourceLoader is not initialized!")
resource_db_client: Optional[
ResourceDbClient
] = self.resource_loader.get_resource_api(
self.resource_need, ResourceDbClient
resource_db_client: Optional[ResourceDbClient] = (
self.resource_loader.get_resource_api(
self.resource_need, ResourceDbClient
)
)
if not resource_db_client:
raise ValueError(
Expand Down
8 changes: 4 additions & 4 deletions dbgpt/agent/expand/actions/dashboard_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ async def run(
try:
if not self.resource_loader:
raise ValueError("Resource loader is not initialized!")
resource_db_client: Optional[
ResourceDbClient
] = self.resource_loader.get_resource_api(
self.resource_need, ResourceDbClient
resource_db_client: Optional[ResourceDbClient] = (
self.resource_loader.get_resource_api(
self.resource_need, ResourceDbClient
)
)
if not resource_db_client:
raise ValueError(
Expand Down
8 changes: 4 additions & 4 deletions dbgpt/agent/expand/actions/plugin_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ async def run(
try:
if not self.resource_loader:
raise ValueError("No resource_loader found!")
resource_plugin_client: Optional[
ResourcePluginClient
] = self.resource_loader.get_resource_api(
self.resource_need, ResourcePluginClient
resource_plugin_client: Optional[ResourcePluginClient] = (
self.resource_loader.get_resource_api(
self.resource_need, ResourcePluginClient
)
)
if not resource_plugin_client:
raise ValueError("No implementation of the use of plug-in resources!")
Expand Down
8 changes: 4 additions & 4 deletions dbgpt/agent/expand/data_scientist_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ async def correctness_check(
"generated is not found.",
)
try:
resource_db_client: Optional[
ResourceDbClient
] = self.not_null_resource_loader.get_resource_api(
ResourceType(action_out.resource_type), ResourceDbClient
resource_db_client: Optional[ResourceDbClient] = (
self.not_null_resource_loader.get_resource_api(
ResourceType(action_out.resource_type), ResourceDbClient
)
)
if not resource_db_client:
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Visualize Data."""

from .show_chart_gen import static_message_img_path # noqa: F401
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Chart display command implementation."""

import logging
import os
import uuid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generate a table display for the response."""

import logging

from pandas import DataFrame
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generate text display content for the data frame."""

import logging

from pandas import DataFrame
Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/plugin/commands/command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command module."""

import json
from typing import Any, Dict

Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/plugin/generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A module for generating custom prompt strings."""

from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional

from dbgpt._private.pydantic import BaseModel, Field
Expand Down
4 changes: 3 additions & 1 deletion dbgpt/agent/plugin/plugins_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def update_from_git(
f.write(response.content)
return plugin_repo_name
else:
logger.error(f"Update plugins failed,response code:{response.status_code}")
logger.error(
f"Update plugins failed,response code:{response.status_code}"
)
raise ValueError(f"Download plugin failed: {response.status_code}")
except Exception as e:
logger.error("update plugins from git exception!" + str(e))
Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/resource/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Resource module for Agent."""

from .resource_api import AgentResource, ResourceClient, ResourceType # noqa: F401
from .resource_db_api import ResourceDbClient, SqliteLoadClient # noqa: F401
from .resource_knowledge_api import ResourceKnowledgeClient # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/resource/resource_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Resource API for the agent."""

import json
from abc import ABC, abstractmethod
from enum import Enum
Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/resource/resource_db_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Database resource client API."""

import logging
from contextlib import contextmanager
from typing import TYPE_CHECKING, Iterator, List, Optional, Union
Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/resource/resource_knowledge_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Knowledge resource API for the agent."""

from typing import Any, Optional

from .resource_api import ResourceClient, ResourceType
Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/resource/resource_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Resource loader module."""

from collections import defaultdict
from typing import Optional, Type, TypeVar

Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/resource/resource_plugin_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Resource plugin client API."""

import logging
import os
from typing import Any, Dict, List, Optional, Union, cast
Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utils for the agent module."""

from .cmp import cmp_string_equal # noqa: F401

__ALL__ = ["cmp_string_equal"]
1 change: 1 addition & 0 deletions dbgpt/agent/util/cmp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Compare string utility functions."""

import string


Expand Down
1 change: 1 addition & 0 deletions dbgpt/agent/util/llm/llm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""LLM module."""

import logging
from collections import defaultdict
from enum import Enum
Expand Down
19 changes: 11 additions & 8 deletions dbgpt/agent/util/llm/llm_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""AIWrapper for LLM."""

import json
import logging
import traceback
Expand Down Expand Up @@ -75,14 +76,16 @@ def _construct_create_params(self, create_config: Dict, extra_kwargs: Dict) -> D
elif context and messages and isinstance(messages, list):
# Instantiate the messages
params["messages"] = [
{
**m,
"content": self.instantiate(
m["content"], context, allow_format_str_template
),
}
if m.get("content")
else m
(
{
**m,
"content": self.instantiate(
m["content"], context, allow_format_str_template
),
}
if m.get("content")
else m
)
for m in messages
]
return params
Expand Down
1 change: 1 addition & 0 deletions dbgpt/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This package will not be uploaded to PyPI. So, your can't import it if some other package depends on it.
"""

import os
import random
import sys
Expand Down
1 change: 1 addition & 0 deletions dbgpt/app/chat_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This code file will be deprecated in the future.
We have integrated fastchat. For details, see: dbgpt/model/model_adapter.py
"""

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

Expand Down
1 change: 1 addition & 0 deletions dbgpt/app/initialization/db_model_initialization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Import all models to make sure they are registered with SQLAlchemy.
"""

from dbgpt.app.knowledge.chunk_db import DocumentChunkEntity
from dbgpt.app.knowledge.document_db import KnowledgeDocumentEntity
from dbgpt.app.openapi.api_v1.feedback.feed_back_db import ChatFeedBackEntity
Expand Down
37 changes: 22 additions & 15 deletions dbgpt/app/knowledge/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,28 +480,35 @@ def delete_document(self, space_name: str, doc_name: str):
raise Exception(f"there are no or more than one document called {doc_name}")
vector_ids = documents[0].vector_ids
if vector_ids is not None:
embedding_factory = CFG.SYSTEM_APP.get_component("embedding_factory", EmbeddingFactory)
embedding_fn = embedding_factory.create(model_name=EMBEDDING_MODEL_CONFIG[CFG.EMBEDDING_MODEL])

embedding_factory = CFG.SYSTEM_APP.get_component(
"embedding_factory", EmbeddingFactory
)
embedding_fn = embedding_factory.create(
model_name=EMBEDDING_MODEL_CONFIG[CFG.EMBEDDING_MODEL]
)

if CFG.VECTOR_STORE_TYPE == "Milvus":
logger.info(f"正在删除Milvus类型的文档。")
config = VectorStoreConfig(name=space_name,
embedding_fn=embedding_fn,
max_chunks_once_load=CFG.KNOWLEDGE_MAX_CHUNKS_ONCE_LOAD,
user=CFG.MILVUS_USERNAME,
password=CFG.MILVUS_PASSWORD,
)
config = VectorStoreConfig(
name=space_name,
embedding_fn=embedding_fn,
max_chunks_once_load=CFG.KNOWLEDGE_MAX_CHUNKS_ONCE_LOAD,
user=CFG.MILVUS_USERNAME,
password=CFG.MILVUS_PASSWORD,
)
elif CFG.VECTOR_STORE_TYPE == "ElasticSearch":
logger.info(f"正在删除ES类型的文档。")
config = VectorStoreConfig(name=space_name, embedding_fn=embedding_fn, ## wwt add
max_chunks_once_load=CFG.KNOWLEDGE_MAX_CHUNKS_ONCE_LOAD, ## wwt add
user=CFG.ElasticSearch_USERNAME,
password=CFG.ElasticSearch_PASSWORD,
)
config = VectorStoreConfig(
name=space_name,
embedding_fn=embedding_fn, ## wwt add
max_chunks_once_load=CFG.KNOWLEDGE_MAX_CHUNKS_ONCE_LOAD, ## wwt add
user=CFG.ElasticSearch_USERNAME,
password=CFG.ElasticSearch_PASSWORD,
)
elif CFG.VECTOR_STORE_TYPE == "Chroma":
config = VectorStoreConfig(name=space_name)
else:
config = VectorStoreConfig(name=space_name)
config = VectorStoreConfig(name=space_name)
vector_store_connector = VectorStoreConnector(
vector_store_type=CFG.VECTOR_STORE_TYPE,
vector_store_config=config,
Expand Down
4 changes: 3 additions & 1 deletion dbgpt/app/openapi/api_v1/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def get_db_list():
def plugins_select_info():
plugins_infos: dict = {}
for plugin in CFG.plugins:
plugins_infos.update({f"【{plugin._name}】=>{plugin._description}": plugin._name})
plugins_infos.update(
{f"【{plugin._name}】=>{plugin._description}": plugin._name}
)
return plugins_infos


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
It will remove in the future, just support db store type now.
"""

import logging
from typing import Type

Expand Down
2 changes: 1 addition & 1 deletion dbgpt/app/scene/chat_dashboard/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def generate_input_values(self) -> Dict:
"input": self.current_user_input,
"dialect": self.database.dialect,
"table_info": self.database.table_simple_info(),
"supported_chat_type": self.dashboard_template["supported_chart_type"]
"supported_chat_type": self.dashboard_template["supported_chart_type"],
# "table_info": client.get_similar_tables(dbname=self.db_name, query=self.current_user_input, topk=self.top_k)
}

Expand Down
10 changes: 8 additions & 2 deletions dbgpt/app/scene/chat_db/auto_execute/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
EXAMPLES = [
{
"messages": [
{"type": "human", "data": {"content": "查询用户test1所在的城市", "example": True}},
{
"type": "human",
"data": {"content": "查询用户test1所在的城市", "example": True},
},
{
"type": "ai",
"data": {
Expand All @@ -16,7 +19,10 @@
},
{
"messages": [
{"type": "human", "data": {"content": "查询成都的用户的订单信息", "example": True}},
{
"type": "human",
"data": {"content": "查询成都的用户的订单信息", "example": True},
},
{
"type": "ai",
"data": {
Expand Down
4 changes: 1 addition & 3 deletions dbgpt/app/scene/chat_knowledge/refine_summary/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
PROMPT_SCENE_DEFINE = """A chat between a curious user and an artificial intelligence assistant, who very familiar with database related knowledge.
The assistant gives helpful, detailed, professional and polite answers to the user's questions."""

_DEFAULT_TEMPLATE_ZH = (
"""我们已经提供了一个到某一点的现有总结:{existing_answer}\n 请根据你之前推理的内容进行最终的总结,总结回答的时候最好按照1.2.3.进行."""
)
_DEFAULT_TEMPLATE_ZH = """我们已经提供了一个到某一点的现有总结:{existing_answer}\n 请根据你之前推理的内容进行最终的总结,总结回答的时候最好按照1.2.3.进行."""

_DEFAULT_TEMPLATE_EN = """
We have provided an existing summary up to a certain point: {existing_answer}\nWe have the opportunity to refine the existing summary (only if needed) with some more context below.
Expand Down
1 change: 1 addition & 0 deletions dbgpt/app/scene/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exceptions for Application."""

import logging

logger = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions dbgpt/client/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""App Client API."""

from typing import List

from dbgpt.core.schema.api import Result
Expand Down
1 change: 1 addition & 0 deletions dbgpt/client/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the client for the DB-GPT API."""

import atexit
import json
import os
Expand Down
Loading

0 comments on commit 8b8a9b9

Please sign in to comment.