Skip to content

Commit

Permalink
chore: Format agent code
Browse files Browse the repository at this point in the history
  • Loading branch information
fangyinc committed Dec 26, 2023
1 parent 50a2929 commit 9665fc5
Show file tree
Hide file tree
Showing 28 changed files with 161 additions and 149 deletions.
7 changes: 2 additions & 5 deletions dbgpt/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from .commands.command import execute_command, get_command
from .commands.generator import PluginPromptGenerator
from .commands.command_mange import ApiCall
from .commands.disply_type.show_chart_gen import static_message_img_path

from .commands.generator import PluginPromptGenerator
from .common.schema import PluginStorageType

from .commands.command_mange import ApiCall
from .commands.command import execute_command
5 changes: 3 additions & 2 deletions dbgpt/agent/agents/agent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from typing import Dict, List, Optional, Union, Any
from dataclasses import dataclass, asdict, fields
import dataclasses
from dataclasses import asdict, dataclass, fields
from typing import Any, Dict, List, Optional, Union

from ..memory.gpts_memory import GptsMemory


Expand Down
2 changes: 1 addition & 1 deletion dbgpt/agent/agents/agents_mange.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union
from .agent import Agent

from .agent import Agent
from .expand.code_assistant_agent import CodeAssistantAgent
from .expand.dashboard_assistant_agent import DashboardAssistantAgent
from .expand.data_scientist_agent import DataScientistAgent
Expand Down
12 changes: 7 additions & 5 deletions dbgpt/agent/agents/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import json
import logging
from typing import Any, Callable, Dict, List, Optional, Type, Union
from .agent import Agent, AgentContext

from dbgpt.agent.agents.llm.llm_client import AIWrapper
from ..memory.gpts_memory import GptsMemory
from ..memory.base import GptsMessage
from dbgpt.util.error_types import LLMChatError
from dbgpt.core.interface.message import ModelMessageRoleType
from dbgpt.core.awel import BaseOperator
from dbgpt.core.interface.message import ModelMessageRoleType
from dbgpt.util.error_types import LLMChatError

from ..memory.base import GptsMessage
from ..memory.gpts_memory import GptsMemory
from .agent import Agent, AgentContext

try:
from termcolor import colored
Expand Down
52 changes: 24 additions & 28 deletions dbgpt/agent/agents/expand/code_assistant_agent.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import json

from ..base_agent import ConversableAgent
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union
from dbgpt.util.code_utils import (
UNKNOWN,
execute_code,
extract_code,
infer_lang,
)
from ..agent import Agent
from ...memory.gpts_memory import GptsMemory
from dbgpt.util.string_utils import str_to_bool

from dbgpt.core.awel import BaseOperator
from dbgpt.util.code_utils import UNKNOWN, execute_code, extract_code, infer_lang
from dbgpt.util.string_utils import str_to_bool

from ...memory.gpts_memory import GptsMemory
from ..agent import Agent
from ..base_agent import ConversableAgent

try:
from termcolor import colored
Expand Down Expand Up @@ -58,17 +54,17 @@ class CodeAssistantAgent(ConversableAgent):
"""

def __init__(
self,
agent_context: "AgentContext",
memory: GptsMemory = None,
llm_operator: Optional[BaseOperator] = None,
model_priority: Optional[List[str]] = None,
describe: Optional[str] = DEFAULT_DESCRIBE,
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
max_consecutive_auto_reply: Optional[int] = None,
human_input_mode: Optional[str] = "NEVER",
code_execution_config: Optional[Union[Dict, Literal[False]]] = None,
**kwargs,
self,
agent_context: "AgentContext",
memory: GptsMemory = None,
llm_operator: Optional[BaseOperator] = None,
model_priority: Optional[List[str]] = None,
describe: Optional[str] = DEFAULT_DESCRIBE,
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
max_consecutive_auto_reply: Optional[int] = None,
human_input_mode: Optional[str] = "NEVER",
code_execution_config: Optional[Union[Dict, Literal[False]]] = None,
**kwargs,
):
"""
Args:
Expand Down Expand Up @@ -116,11 +112,11 @@ def _vis_code_idea(self, code, exit_success, log, language):
return f"```vis-code\n{json.dumps(param)}\n```"

async def generate_code_execution_reply(
self,
message: Optional[str] = None,
sender: Optional[Agent] = None,
reviewer: "Agent" = None,
config: Optional[Union[Dict, Literal[False]]] = None,
self,
message: Optional[str] = None,
sender: Optional[Agent] = None,
reviewer: "Agent" = None,
config: Optional[Union[Dict, Literal[False]]] = None,
):
"""Generate a reply using code execution."""
code_execution_config = (
Expand Down Expand Up @@ -240,7 +236,7 @@ def execute_code_blocks(self, code_blocks):
)
elif lang in ["python", "Python"]:
if code.startswith("# filename: "):
filename = code[11: code.find("\n")].strip()
filename = code[11 : code.find("\n")].strip()
else:
filename = None
exitcode, logs, image = self.run_code(
Expand Down
10 changes: 5 additions & 5 deletions dbgpt/agent/agents/expand/dashboard_assistant_agent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json

from ..base_agent import ConversableAgent
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union

from ..agent import Agent
from ...memory.gpts_memory import GptsMemory
from dbgpt.util.json_utils import find_json_objects
from dbgpt.agent.commands.command_mange import ApiCall
from dbgpt.util.json_utils import find_json_objects

from ...memory.gpts_memory import GptsMemory
from ..agent import Agent
from ..base_agent import ConversableAgent

try:
from termcolor import colored
Expand Down
13 changes: 7 additions & 6 deletions dbgpt/agent/agents/expand/data_scientist_agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import json

from ..base_agent import ConversableAgent
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union
import logging
from ..agent import Agent
from ...memory.gpts_memory import GptsMemory
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union

from dbgpt._private.config import Config
from dbgpt.agent.commands.command_mange import ApiCall
from dbgpt.util.json_utils import find_json_objects
from dbgpt.core.awel import BaseOperator
from dbgpt.util.json_utils import find_json_objects

from ...memory.gpts_memory import GptsMemory
from ..agent import Agent
from ..base_agent import ConversableAgent

try:
from termcolor import colored
Expand Down
15 changes: 8 additions & 7 deletions dbgpt/agent/agents/expand/plugin_assistant_agent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json

from ..base_agent import ConversableAgent
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union
import logging
from ..agent import Agent
from ...memory.gpts_memory import GptsMemory
from dbgpt.util.json_utils import find_json_objects
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union

from dbgpt.core.awel import BaseOperator
from dbgpt.util.json_utils import find_json_objects

from ...memory.gpts_memory import GptsMemory
from ..agent import Agent
from ..base_agent import ConversableAgent

try:
from termcolor import colored
Expand All @@ -15,6 +16,7 @@
def colored(x, *args, **kwargs):
return x


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -89,7 +91,6 @@ def __init__(
self.register_reply(Agent, PluginAgent.tool_call)
self.agent_context = agent_context


async def a_system_fill_param(self):
params = {
"tool_infos": self.db_connect.get_table_info(),
Expand Down
9 changes: 5 additions & 4 deletions dbgpt/agent/agents/expand/sql_assistant_agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from dbgpt.agent.agents.base_agent import ConversableAgent
from typing import Callable, Dict, List, Literal, Optional, Union

from ..agent import Agent
from ...memory.gpts_memory import GptsMemory
from ...commands.command_mange import ApiCall
from dbgpt.agent.agents.base_agent import ConversableAgent
from dbgpt.core.awel import BaseOperator

from ...commands.command_mange import ApiCall
from ...memory.gpts_memory import GptsMemory
from ..agent import Agent

try:
from termcolor import colored
except ImportError:
Expand Down
5 changes: 2 additions & 3 deletions dbgpt/agent/agents/llm/llm.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from abc import ABC
from typing import Optional, Dict, List, Any, Union, AsyncIterator
from typing import Any, AsyncIterator, Dict, List, Optional, Union

from dbgpt.core.interface.message import ModelMessage, ModelMessageRoleType
from dbgpt.core.awel import MapOperator

from dbgpt.core.interface.llm import ModelRequest
from dbgpt.core.interface.message import ModelMessage, ModelMessageRoleType


class GptsRequestBuildOperator(MapOperator[Union[Dict, str], ModelRequest], ABC):
Expand Down
26 changes: 13 additions & 13 deletions dbgpt/agent/agents/llm/llm_client.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from __future__ import annotations
import os
import sys

import asyncio
from typing import List, Optional, Dict, Callable
import json
import logging
import os
import sys
from typing import Callable, Dict, List, Optional

import diskcache
import json
from dbgpt.util.executor_utils import ExecutorFactory, blocking_func_to_async
from dbgpt.core.awel import BaseOperator, SimpleCallDataInputSource, InputOperator, DAG

from dbgpt.util.error_types import LLMChatError
from dbgpt.util.tracer import root_tracer, trace
from dbgpt._private.config import Config
from dbgpt.component import ComponentType, SystemApp
from dbgpt.core import LLMOperator, PromptTemplate, SQLOutputParser
from dbgpt.core.awel import DAG, BaseOperator, InputOperator, SimpleCallDataInputSource
from dbgpt.core.interface.output_parser import BaseOutputParser
from dbgpt.core import LLMOperator
from dbgpt.model import OpenAILLMClient

from dbgpt.model.operator.model_operator import ModelOperator, ModelStreamOperator
from dbgpt.util.error_types import LLMChatError
from dbgpt.util.executor_utils import ExecutorFactory, blocking_func_to_async
from dbgpt.util.tracer import root_tracer, trace

from dbgpt.component import ComponentType, SystemApp
from dbgpt._private.config import Config
from dbgpt.core import SQLOutputParser, PromptTemplate
from ..llm.llm import GptsRequestBuildOperator

logger = logging.getLogger(__name__)
Expand Down
14 changes: 8 additions & 6 deletions dbgpt/agent/agents/plan_group_chat.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import json
import logging
import sys
import random
import re
import sys
from dataclasses import dataclass
from typing import Dict, List, Optional, Union
import re
from .agent import Agent, AgentContext
from .base_agent import ConversableAgent
from ..common.schema import Status

from dbgpt.core.awel import BaseOperator
from dbgpt.util.string_utils import str_to_bool
from ..memory.gpts_memory import GptsMemory, GptsPlan, GptsMessage

from ..common.schema import Status
from ..memory.gpts_memory import GptsMemory, GptsMessage, GptsPlan
from .agent import Agent, AgentContext
from .base_agent import ConversableAgent

logger = logging.getLogger(__name__)

Expand Down
21 changes: 9 additions & 12 deletions dbgpt/agent/agents/planner_agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from .agent import Agent, AgentContext
from .base_agent import ConversableAgent


from typing import Any, Callable, Dict, Optional, Tuple, Union
from dbgpt.util.json_utils import find_json_objects
from dbgpt.agent.common.schema import Status
from ..memory.gpts_memory import GptsMemory, GptsPlan
from dbgpt.agent.agents.plan_group_chat import PlanChat

from dbgpt._private.config import Config
from dbgpt.agent.agents.plan_group_chat import PlanChat
from dbgpt.agent.common.schema import Status
from dbgpt.core.awel import BaseOperator
from dbgpt.util.json_utils import find_json_objects

from ..memory.gpts_memory import GptsMemory, GptsPlan
from .agent import Agent, AgentContext
from .base_agent import ConversableAgent

CFG = Config()

Expand Down Expand Up @@ -125,10 +125,7 @@ def build_param(self, agent_context: AgentContext):
return {
"all_resources": "\n".join([f"- {item}" for item in resources]),
"agents": "\n".join(
[
f"- {item.name}:{item.describe}"
for item in self.plan_chat.agents
]
[f"- {item.name}:{item.describe}" for item in self.plan_chat.agents]
),
}

Expand Down
5 changes: 3 additions & 2 deletions dbgpt/agent/agents/user_proxy_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .base_agent import ConversableAgent
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union
from .agent import Agent

from ..memory.gpts_memory import GptsMemory
from .agent import Agent
from .base_agent import ConversableAgent

try:
from termcolor import colored
Expand Down
2 changes: 1 addition & 1 deletion dbgpt/agent/commands/built_in/audio_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import requests

from dbgpt.agent.commands.command_mange import command
from dbgpt._private.config import Config
from dbgpt.agent.commands.command_mange import command

CFG = Config()

Expand Down
4 changes: 2 additions & 2 deletions dbgpt/agent/commands/built_in/image_gen.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
""" Image Generation Module for AutoGPT."""
import io
import logging
import uuid
from base64 import b64decode
import logging

import requests
from PIL import Image

from dbgpt.agent.commands.command_mange import command
from dbgpt._private.config import Config
from dbgpt.agent.commands.command_mange import command

logger = logging.getLogger(__name__)
CFG = Config()
Expand Down
4 changes: 2 additions & 2 deletions dbgpt/agent/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import json
from typing import Dict

from dbgpt._private.config import Config

from .exception_not_commands import NotCommands
from .generator import PluginPromptGenerator

from dbgpt._private.config import Config


def _resolve_pathlike_command_args(command_args):
if "directory" in command_args and command_args["directory"] in {"", "/"}:
Expand Down
Loading

0 comments on commit 9665fc5

Please sign in to comment.