From ba57257aceb2280bc0ad515834c9118d513a7e5b Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Mon, 19 Feb 2024 17:17:35 +0800 Subject: [PATCH] feat(agent):Agent App 1.Fix the display problem under dashboboard 2.Support Awel Agent to arrange fixed targets --- dbgpt/agent/actions/dashboard_action.py | 8 +++++--- .../expand/dashboard_assistant_agent.py | 1 + dbgpt/agent/agents/role.py | 20 ++++++++++--------- dbgpt/vis/tags/vis_dashboard.py | 9 ++++++--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/dbgpt/agent/actions/dashboard_action.py b/dbgpt/agent/actions/dashboard_action.py index dc5f5338e..d0472c09b 100644 --- a/dbgpt/agent/actions/dashboard_action.py +++ b/dbgpt/agent/actions/dashboard_action.py @@ -75,11 +75,13 @@ async def a_run( sql_df = await resource_db_client.a_query_to_df( resource.value, chart_item.sql ) - chart_item["data"] = sql_df + chart_dict = chart_item.dict() + + chart_dict["data"] = sql_df except Exception as e: logger.warn(f"Sql excute Failed!{str(e)}") - chart_item["err_msg"] = str(e) - chart_params.append(chart_item) + chart_dict["err_msg"] = str(e) + chart_params.append(chart_dict) view = await self.render_protocal.disply(charts=chart_params) return ActionOutput( is_exe_success=True, diff --git a/dbgpt/agent/agents/expand/dashboard_assistant_agent.py b/dbgpt/agent/agents/expand/dashboard_assistant_agent.py index a6ec35a2a..e962cb717 100644 --- a/dbgpt/agent/agents/expand/dashboard_assistant_agent.py +++ b/dbgpt/agent/agents/expand/dashboard_assistant_agent.py @@ -17,6 +17,7 @@ class DashboardAssistantAgent(ConversableAgent): constraints: List[str] = [ "You are only responsible for collecting and sorting out the analysis SQL that already exists in historical messages, and do not generate any analysis sql yourself.", "In order to build a report with rich display types, you can appropriately adjust the display type of the charts you collect so that you can build a better report. Of course, you can choose from the following available display types: {display_type}", + "Please read and completely collect all analysis sql in the historical conversation, and do not omit or modify the content of the analysis sql.", ] desc: str = "Observe and organize various analysis results and construct professional reports" diff --git a/dbgpt/agent/agents/role.py b/dbgpt/agent/agents/role.py index a9909678c..f309a9b27 100644 --- a/dbgpt/agent/agents/role.py +++ b/dbgpt/agent/agents/role.py @@ -12,6 +12,8 @@ class Role(ABC, BaseModel): expand_prompt: str = "" + fixed_subgoal: Optional[str] = None + constraints: List[str] = [] examples: str = "" desc: str = "" @@ -19,8 +21,8 @@ class Role(ABC, BaseModel): is_human: bool = False is_team: bool = False - def __init__(self, **kwargs): - super().__init__(**kwargs) + class Config: + arbitrary_types_allowed = True def prompt_template( self, @@ -32,16 +34,16 @@ def prompt_template( template = f""" {self.role_prompt} Please think step by step to achieve the goal. You can use the resources given below. At the same time, please strictly abide by the constraints and specifications in IMPORTANT REMINDER. - + {{resource_prompt}} - - {self.expand_prompt if len(self.expand_prompt)>0 else ""} - + + {self.expand_prompt if len(self.expand_prompt) > 0 else ""} + *** IMPORTANT REMINDER *** {self.language_require_prompt} {self.constraints_prompt} - - {'You can refer to the following examples:' if len(self.examples) > 0 else ""} + + {'You can refer to the following examples:' if len(self.examples) > 0 else ""} {self.examples if len(self.examples) > 0 else ""} {{out_schema}} @@ -61,7 +63,7 @@ def role_prompt(self): def constraints_prompt(self): if len(self.constraints) > 0: return "\n".join( - f"{i+1}. {item}" for i, item in enumerate(self.constraints) + f"{i + 1}. {item}" for i, item in enumerate(self.constraints) ) @property diff --git a/dbgpt/vis/tags/vis_dashboard.py b/dbgpt/vis/tags/vis_dashboard.py index 85e75d682..eab3ef068 100644 --- a/dbgpt/vis/tags/vis_dashboard.py +++ b/dbgpt/vis/tags/vis_dashboard.py @@ -1,11 +1,14 @@ import json +import logging from typing import Optional from ..base import Vis +logger = logging.getLogger(__name__) + class VisDashboard(Vis): - async def generate_content(self, **kwargs) -> Optional[str]: + async def generate_param(self, **kwargs) -> Optional[str]: charts = kwargs.get("charts", None) title = kwargs.get("title", None) if not charts: @@ -24,14 +27,14 @@ async def generate_content(self, **kwargs) -> Optional[str]: try: df = chart.get("data", None) err_msg = chart.get("err_msg", None) - if not df: + if df is None: param["err_msg"] = err_msg else: param["data"] = json.loads( df.to_json(orient="records", date_format="iso", date_unit="s") ) - except Exception as e: + logger.exception("dashboard chart build faild!") param["data"] = [] param["err_msg"] = str(e) chart_items.append(param)