Skip to content

Commit 63ab612

Browse files
authored
Gpts app v0.4 (#1169)
1 parent 37f7ad1 commit 63ab612

File tree

7 files changed

+60
-27
lines changed

7 files changed

+60
-27
lines changed

dbgpt/agent/actions/dashboard_action.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ async def a_run(
7575
sql_df = await resource_db_client.a_query_to_df(
7676
resource.value, chart_item.sql
7777
)
78-
chart_item["data"] = sql_df
78+
chart_dict = chart_item.dict()
79+
80+
chart_dict["data"] = sql_df
7981
except Exception as e:
8082
logger.warn(f"Sql excute Failed!{str(e)}")
81-
chart_item["err_msg"] = str(e)
82-
chart_params.append(chart_item)
83+
chart_dict["err_msg"] = str(e)
84+
chart_params.append(chart_dict)
8385
view = await self.render_protocal.disply(charts=chart_params)
8486
return ActionOutput(
8587
is_exe_success=True,

dbgpt/agent/agents/expand/dashboard_assistant_agent.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DashboardAssistantAgent(ConversableAgent):
1717
constraints: List[str] = [
1818
"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.",
1919
"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}",
20+
"Please read and completely collect all analysis sql in the historical conversation, and do not omit or modify the content of the analysis sql.",
2021
]
2122
desc: str = "Observe and organize various analysis results and construct professional reports"
2223

dbgpt/agent/agents/role.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ class Role(ABC, BaseModel):
1212

1313
expand_prompt: str = ""
1414

15+
fixed_subgoal: Optional[str] = None
16+
1517
constraints: List[str] = []
1618
examples: str = ""
1719
desc: str = ""
1820
language: str = "en"
1921
is_human: bool = False
2022
is_team: bool = False
2123

22-
def __init__(self, **kwargs):
23-
super().__init__(**kwargs)
24+
class Config:
25+
arbitrary_types_allowed = True
2426

2527
def prompt_template(
2628
self,
@@ -32,16 +34,16 @@ def prompt_template(
3234
template = f"""
3335
{self.role_prompt}
3436
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.
35-
37+
3638
{{resource_prompt}}
37-
38-
{self.expand_prompt if len(self.expand_prompt)>0 else ""}
39-
39+
40+
{self.expand_prompt if len(self.expand_prompt) > 0 else ""}
41+
4042
*** IMPORTANT REMINDER ***
4143
{self.language_require_prompt}
4244
{self.constraints_prompt}
43-
44-
{'You can refer to the following examples:' if len(self.examples) > 0 else ""}
45+
46+
{'You can refer to the following examples:' if len(self.examples) > 0 else ""}
4547
{self.examples if len(self.examples) > 0 else ""}
4648
4749
{{out_schema}}
@@ -61,7 +63,7 @@ def role_prompt(self):
6163
def constraints_prompt(self):
6264
if len(self.constraints) > 0:
6365
return "\n".join(
64-
f"{i+1}. {item}" for i, item in enumerate(self.constraints)
66+
f"{i + 1}. {item}" for i, item in enumerate(self.constraints)
6567
)
6668

6769
@property

dbgpt/serve/agent/team/layout/agent_operator.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,30 @@ async def map(
135135
self,
136136
input_value: AgentGenerateContext,
137137
) -> AgentGenerateContext:
138-
now_rely_messages: List[Dict] = []
139-
138+
now_message = input_value.message
140139
agent = await self.get_agent(input_value)
140+
if agent.fixed_subgoal and len(agent.fixed_subgoal) > 0:
141+
# Isolate the message delivery mechanism and pass it to the operator
142+
input_value.message["current_gogal"] = (
143+
f"[{agent.name if agent.name else agent.profile}]:"
144+
+ agent.fixed_subgoal
145+
)
146+
now_message["content"] = agent.fixed_subgoal
147+
else:
148+
# Isolate the message delivery mechanism and pass it to the operator
149+
input_value.message["current_gogal"] = (
150+
f"[{agent.name if agent.name else agent.profile}]:"
151+
+ input_value.message["content"]
152+
)
141153

142-
# Isolate the message delivery mechanism and pass it to the operator
143-
input_value.message["current_gogal"] = (
144-
f"[{agent.name if agent.name else agent.profile}]:"
145-
+ input_value.message["content"]
146-
)
154+
now_rely_messages: List[Dict] = []
147155
###What was received was the User message
148156
human_message = input_value.message.copy()
149157
human_message["role"] = ModelMessageRoleType.HUMAN
150158
now_rely_messages.append(human_message)
151159

152160
###Send a message (no reply required) and pass the message content
153-
now_message = input_value.message
161+
154162
if input_value.rely_messages and len(input_value.rely_messages) > 0:
155163
now_message = input_value.rely_messages[-1]
156164
await input_value.sender.a_send(now_message, agent, input_value.reviewer, False)
@@ -200,9 +208,13 @@ async def get_agent(
200208
llm_config = LLMConfig(llm_client=input_value.llm_client)
201209
else:
202210
llm_config = LLMConfig(llm_client=self.llm_client)
203-
211+
kwargs = {}
212+
if self.awel_agent.role_name:
213+
kwargs["name"] = self.awel_agent.role_name
214+
if self.awel_agent.fixed_subgoal:
215+
kwargs["fixed_subgoal"] = self.awel_agent.fixed_subgoal
204216
agent = (
205-
await agent_cls(name=self.awel_agent.role_name)
217+
await agent_cls(**kwargs)
206218
.bind(input_value.memory)
207219
.bind(llm_config)
208220
.bind(input_value.agent_context)

dbgpt/serve/agent/team/layout/agent_operator_resource.py

+9
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]:
139139
default=None,
140140
description="The agent role name.",
141141
),
142+
Parameter.build_from(
143+
label="Fixed Gogal",
144+
name="fixed_subgoal",
145+
type=str,
146+
optional=True,
147+
default=None,
148+
description="The agent fixed gogal.",
149+
),
142150
Parameter.build_from(
143151
label="Agent Resource",
144152
name="agent_resource",
@@ -162,6 +170,7 @@ class AwelAgent(BaseModel):
162170
role_name: Optional[str] = None
163171
llm_config: Optional[LLMConfig] = None
164172
resources: List[AgentResource] = Field(default_factory=list)
173+
fixed_subgoal: Optional[str] = None
165174

166175
class Config:
167176
arbitrary_types_allowed = True

dbgpt/serve/agent/team/plan/team_auto_plan.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ async def a_act(
117117
reviewer: Optional[ConversableAgent] = None,
118118
) -> Optional[ActionOutput]:
119119
speaker = sender
120+
final_message = message
120121
for i in range(self.max_round):
121122
plans = self.memory.plans_memory.get_by_conv_id(self.agent_context.conv_id)
122123

@@ -153,7 +154,7 @@ async def a_act(
153154
# complete
154155
return ActionOutput(
155156
is_exe_success=True,
156-
content=f"{plans[-1].result}", # work results message
157+
content=final_message, # work results message
157158
)
158159
else:
159160
try:
@@ -201,19 +202,21 @@ async def a_act(
201202
)
202203

203204
plan_result = ""
205+
final_message = reply_message["content"]
204206
if is_success:
205207
if reply_message:
206208
action_report = reply_message.get("action_report", None)
207209
if action_report:
208210
plan_result = action_report.get("content", "")
211+
final_message = action_report["view"]
212+
209213
### The current planned Agent generation verification is successful
210214
##Plan executed successfully
211215
self.memory.plans_memory.complete_task(
212216
self.agent_context.conv_id,
213217
now_plan.sub_task_num,
214218
plan_result,
215219
)
216-
217220
else:
218221
plan_result = reply_message["content"]
219222
self.memory.plans_memory.update_task(
@@ -228,6 +231,7 @@ async def a_act(
228231
return ActionOutput(
229232
is_exe_success=False, content=plan_result
230233
)
234+
231235
except Exception as e:
232236
logger.exception(
233237
f"An exception was encountered during the execution of the current plan step.{str(e)}"

dbgpt/vis/tags/vis_dashboard.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import json
2+
import logging
23
from typing import Optional
34

45
from ..base import Vis
56

7+
logger = logging.getLogger(__name__)
8+
69

710
class VisDashboard(Vis):
8-
async def generate_content(self, **kwargs) -> Optional[str]:
11+
async def generate_param(self, **kwargs) -> Optional[str]:
912
charts = kwargs.get("charts", None)
1013
title = kwargs.get("title", None)
1114
if not charts:
@@ -24,14 +27,14 @@ async def generate_content(self, **kwargs) -> Optional[str]:
2427
try:
2528
df = chart.get("data", None)
2629
err_msg = chart.get("err_msg", None)
27-
if not df:
30+
if df is None:
2831
param["err_msg"] = err_msg
2932
else:
3033
param["data"] = json.loads(
3134
df.to_json(orient="records", date_format="iso", date_unit="s")
3235
)
33-
3436
except Exception as e:
37+
logger.exception("dashboard chart build faild!")
3538
param["data"] = []
3639
param["err_msg"] = str(e)
3740
chart_items.append(param)

0 commit comments

Comments
 (0)