From 9bdb4f94b8f8c6be86ca9f45b4922c49da658680 Mon Sep 17 00:00:00 2001 From: Fangyin Cheng Date: Wed, 17 Jan 2024 10:26:48 +0800 Subject: [PATCH] chore: Format agent code (#1077) --- CONTRIBUTING.md | 36 ++++++++++++------- dbgpt/agent/agents/agents_mange.py | 2 +- .../agents/expand/plugin_assistant_agent.py | 5 ++- .../retrieve_summary_assistant_agent.py | 28 +++++++-------- .../agents/expand/summary_assistant_agent.py | 3 +- dbgpt/agent/agents/resource.py | 2 +- dbgpt/agent/common/schema.py | 13 +++---- dbgpt/agent/memory/gpts_memory.py | 2 +- dbgpt/app/openapi/api_v1/api_v1.py | 3 +- dbgpt/serve/agent/agents/controller.py | 11 +++--- dbgpt/serve/agent/db/gpts_manage_db.py | 2 +- dbgpt/vis/tags/vis_gpts_result.py | 3 +- 12 files changed, 56 insertions(+), 54 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2c9fcfa57..31014e1d1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,50 +8,62 @@ To contribute to this GitHub project, you can follow these steps: ``` git clone https://github.com//DB-GPT ``` + 3. Install the project requirements ``` pip install -e ".[default]" - ``` + 4. Install pre-commit hooks ``` pre-commit install ``` -5. Create a new branch for your changes using the following command: +5. Create a new branch for your changes using the following command: ``` git checkout -b "branch-name" ``` + 6. Make your changes to the code or documentation. + - Example: Improve User Interface or Add Documentation. +7. Format the code using the following command: +``` +make fmt +``` -7. Add the changes to the staging area using the following command: +8. Add the changes to the staging area using the following command: ``` git add . ``` -8. Commit the changes with a meaningful commit message using the following command: +9. Make sure the tests pass and your code lints using the following command: +``` +make pre-commit +``` + +10. Commit the changes with a meaningful commit message using the following command: ``` git commit -m "your commit message" ``` -9. Push the changes to your forked repository using the following command: +11. Push the changes to your forked repository using the following command: ``` git push origin branch-name ``` -10. Go to the GitHub website and navigate to your forked repository. +12. Go to the GitHub website and navigate to your forked repository. -11. Click the "New pull request" button. +13. Click the "New pull request" button. -12. Select the branch you just pushed to and the branch you want to merge into on the original repository. +14. Select the branch you just pushed to and the branch you want to merge into on the original repository. -13. Add a description of your changes and click the "Create pull request" button. +15. Add a description of your changes and click the "Create pull request" button. -14. Wait for the project maintainer to review your changes and provide feedback. +16. Wait for the project maintainer to review your changes and provide feedback. -15. Make any necessary changes based on feedback and repeat steps 5-12 until your changes are accepted and merged into the main project. +17. Make any necessary changes based on feedback and repeat steps 5-12 until your changes are accepted and merged into the main project. -16. Once your changes are merged, you can update your forked repository and local copy of the repository with the following commands: +18. Once your changes are merged, you can update your forked repository and local copy of the repository with the following commands: ``` git fetch upstream diff --git a/dbgpt/agent/agents/agents_mange.py b/dbgpt/agent/agents/agents_mange.py index 4f8486191..e8338d018 100644 --- a/dbgpt/agent/agents/agents_mange.py +++ b/dbgpt/agent/agents/agents_mange.py @@ -8,9 +8,9 @@ from .expand.code_assistant_agent import CodeAssistantAgent from .expand.dashboard_assistant_agent import DashboardAssistantAgent from .expand.data_scientist_agent import DataScientistAgent from .expand.plugin_assistant_agent import PluginAssistantAgent +from .expand.retrieve_summary_assistant_agent import RetrieveSummaryAssistantAgent from .expand.sql_assistant_agent import SQLAssistantAgent from .expand.summary_assistant_agent import SummaryAssistantAgent -from .expand.retrieve_summary_assistant_agent import RetrieveSummaryAssistantAgent logger = logging.getLogger(__name__) diff --git a/dbgpt/agent/agents/expand/plugin_assistant_agent.py b/dbgpt/agent/agents/expand/plugin_assistant_agent.py index 18420dff7..0c723f05a 100644 --- a/dbgpt/agent/agents/expand/plugin_assistant_agent.py +++ b/dbgpt/agent/agents/expand/plugin_assistant_agent.py @@ -2,6 +2,8 @@ import logging from pathlib import Path from typing import Callable, Dict, Literal, Optional, Union +# TODO +from dbgpt.configs.model_config import PLUGINS_DIR from dbgpt.util.json_utils import find_json_objects from dbgpt.vis import VisPlugin, vis_client @@ -20,9 +22,6 @@ except ImportError: return x -# TODO -from dbgpt.configs.model_config import PLUGINS_DIR - logger = logging.getLogger(__name__) diff --git a/dbgpt/agent/agents/expand/retrieve_summary_assistant_agent.py b/dbgpt/agent/agents/expand/retrieve_summary_assistant_agent.py index efffbde52..8d59fe39f 100644 --- a/dbgpt/agent/agents/expand/retrieve_summary_assistant_agent.py +++ b/dbgpt/agent/agents/expand/retrieve_summary_assistant_agent.py @@ -1,26 +1,23 @@ -import os -import glob -import requests -import logging -import tiktoken -import pypdf import asyncio +import glob import json +import logging +import os import pdb - - +from typing import Callable, Dict, List, Literal, Optional, Union from urllib.parse import urlparse -from typing import Callable, Dict, Literal, Optional, Union, List + +import pypdf +import requests +import tiktoken from bs4 import BeautifulSoup -from dbgpt.agent.agents.base_agent import ConversableAgent -from dbgpt.agent.plugin.commands.command_mange import ApiCall - -from dbgpt.agent.memory.gpts_memory import GptsMemory from dbgpt.agent.agents.agent import Agent, AgentContext -from dbgpt.core.interface.message import ModelMessageRoleType - +from dbgpt.agent.agents.base_agent import ConversableAgent +from dbgpt.agent.memory.gpts_memory import GptsMemory +from dbgpt.agent.plugin.commands.command_mange import ApiCall from dbgpt.configs.model_config import PILOT_PATH +from dbgpt.core.interface.message import ModelMessageRoleType try: from termcolor import colored @@ -581,7 +578,6 @@ if __name__ == "__main__": from dbgpt.agent.agents.agent import AgentContext from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent - from dbgpt.core.interface.llm import ModelMetadata from dbgpt.model import OpenAILLMClient diff --git a/dbgpt/agent/agents/expand/summary_assistant_agent.py b/dbgpt/agent/agents/expand/summary_assistant_agent.py index f4c0045cf..87ea95f52 100644 --- a/dbgpt/agent/agents/expand/summary_assistant_agent.py +++ b/dbgpt/agent/agents/expand/summary_assistant_agent.py @@ -1,3 +1,4 @@ +import logging from typing import Callable, Dict, Literal, Optional, Union from dbgpt.agent.agents.base_agent import ConversableAgent @@ -6,8 +7,6 @@ from dbgpt.core.interface.message import ModelMessageRoleType from ...memory.gpts_memory import GptsMemory from ..agent import Agent, AgentContext -import logging - logger = logging.getLogger() diff --git a/dbgpt/agent/agents/resource.py b/dbgpt/agent/agents/resource.py index a891faa37..7e04ed755 100644 --- a/dbgpt/agent/agents/resource.py +++ b/dbgpt/agent/agents/resource.py @@ -1,7 +1,7 @@ from __future__ import annotations -from enum import Enum import dataclasses +from enum import Enum from typing import Any, Dict, List, Optional, Tuple, Union diff --git a/dbgpt/agent/common/schema.py b/dbgpt/agent/common/schema.py index 815f12036..48818eca0 100644 --- a/dbgpt/agent/common/schema.py +++ b/dbgpt/agent/common/schema.py @@ -1,18 +1,15 @@ from __future__ import annotations + import asyncio import json import logging -from enum import Enum -from datetime import datetime from asyncio import Queue, QueueEmpty, wait_for +from datetime import datetime +from enum import Enum from json import JSONDecodeError from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union -from pydantic import ( - BaseModel, - ConfigDict, - Field, - PrivateAttr, -) + +from pydantic import BaseModel, ConfigDict, Field, PrivateAttr logger = logging.getLogger(__name__) diff --git a/dbgpt/agent/memory/gpts_memory.py b/dbgpt/agent/memory/gpts_memory.py index 430d85ccb..0c9586d85 100644 --- a/dbgpt/agent/memory/gpts_memory.py +++ b/dbgpt/agent/memory/gpts_memory.py @@ -5,10 +5,10 @@ from collections import defaultdict from typing import Dict, List, Optional from dbgpt.util.json_utils import EnhancedJSONEncoder +from dbgpt.vis.client import VisAgentMessages, VisAgentPlans, vis_client from .base import GptsMessage, GptsMessageMemory, GptsPlansMemory from .default_gpts_memory import DefaultGptsMessageMemory, DefaultGptsPlansMemory -from dbgpt.vis.client import vis_client, VisAgentMessages, VisAgentPlans class GptsMemory: diff --git a/dbgpt/app/openapi/api_v1/api_v1.py b/dbgpt/app/openapi/api_v1/api_v1.py index f0507d1bf..ba95e650c 100644 --- a/dbgpt/app/openapi/api_v1/api_v1.py +++ b/dbgpt/app/openapi/api_v1/api_v1.py @@ -28,6 +28,7 @@ from dbgpt.datasource.db_conn_info import DBConfig, DbTypeInfo from dbgpt.model.base import FlatSupportedModel from dbgpt.model.cluster import BaseModelController, WorkerManager, WorkerManagerFactory from dbgpt.rag.summary.db_summary_client import DBSummaryClient +from dbgpt.serve.agent.agents.controller import multi_agents from dbgpt.util.executor_utils import ( DefaultExecutorFactory, ExecutorFactory, @@ -35,8 +36,6 @@ from dbgpt.util.executor_utils import ( ) from dbgpt.util.tracer import SpanType, root_tracer -from dbgpt.serve.agent.agents.controller import multi_agents - router = APIRouter() CFG = Config() CHAT_FACTORY = ChatFactory() diff --git a/dbgpt/serve/agent/agents/controller.py b/dbgpt/serve/agent/agents/controller.py index 420f553f7..d5ca93fb3 100644 --- a/dbgpt/serve/agent/agents/controller.py +++ b/dbgpt/serve/agent/agents/controller.py @@ -4,7 +4,7 @@ import logging import uuid from abc import ABC from collections import defaultdict -from typing import Dict, List, Any, Optional +from typing import Any, Dict, List, Optional from fastapi import APIRouter, Body from fastapi.responses import StreamingResponse @@ -16,11 +16,15 @@ from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent from dbgpt.agent.common.schema import Status from dbgpt.agent.memory.gpts_memory import GptsMemory from dbgpt.app.openapi.api_view_model import Result +from dbgpt.app.scene.base import ChatScene from dbgpt.component import BaseComponent, ComponentType, SystemApp +from dbgpt.core.interface.message import StorageConversation from dbgpt.model.cluster import WorkerManagerFactory from dbgpt.model.cluster.client import DefaultLLMClient from dbgpt.serve.agent.model import PagenationFilter, PluginHubFilter from dbgpt.serve.agent.team.plan.team_auto_plan import AutoPlanChatManager +from dbgpt.serve.conversation.serve import Serve as ConversationServe +from dbgpt.util.json_utils import serialize from ..db.gpts_conversations_db import GptsConversationsDao, GptsConversationsEntity from ..db.gpts_manage_db import GptsInstanceDao, GptsInstanceEntity @@ -28,11 +32,6 @@ from ..team.base import TeamMode from ..team.layout.team_awel_layout import AwelLayoutChatManager from .db_gpts_memory import MetaDbGptsMessageMemory, MetaDbGptsPlansMemory from .dbgpts import DbGptsInstance -from dbgpt.util.json_utils import serialize - -from dbgpt.serve.conversation.serve import Serve as ConversationServe -from dbgpt.core.interface.message import StorageConversation -from dbgpt.app.scene.base import ChatScene CFG = Config() diff --git a/dbgpt/serve/agent/db/gpts_manage_db.py b/dbgpt/serve/agent/db/gpts_manage_db.py index cfedf6e99..4f1be2dcf 100644 --- a/dbgpt/serve/agent/db/gpts_manage_db.py +++ b/dbgpt/serve/agent/db/gpts_manage_db.py @@ -1,13 +1,13 @@ from datetime import datetime from sqlalchemy import ( + Boolean, Column, DateTime, Integer, String, Text, UniqueConstraint, - Boolean, ) from dbgpt.storage.metadata import BaseDao, Model diff --git a/dbgpt/vis/tags/vis_gpts_result.py b/dbgpt/vis/tags/vis_gpts_result.py index d5a00c007..af0bd901d 100644 --- a/dbgpt/vis/tags/vis_gpts_result.py +++ b/dbgpt/vis/tags/vis_gpts_result.py @@ -1,8 +1,9 @@ from typing import Optional -from ..base import Vis from webdriver_manager.chrome import ChromeDriverManager +from ..base import Vis + class VisDbgptsFlowResult(Vis): @classmethod