feat(Agent): ChatAgent And AgentHub

1.ChatExcel support stream response
2.ChatExcel support Multiple charts
This commit is contained in:
yhjun1026
2023-10-09 16:26:05 +08:00
parent ed702db9bc
commit f8de26b5ff
10 changed files with 270 additions and 192 deletions

View File

@@ -9,50 +9,52 @@ from pilot.common.schema import SeparatorStyle
CFG = Config()
PROMPT_SCENE_DEFINE = "You are a data analysis expert. "
_PROMPT_SCENE_DEFINE_EN = "You are a data analysis expert. "
_DEFAULT_TEMPLATE_EN = """
Please use the data structure information of the above historical dialogue, make sure not to use column names that are not in the data structure.
According to the user goal: {user_input}give the correct duckdb SQL for data analysis.
Use the table name: {table_name}
Please use the data structure and column information in the above historical dialogue and combine it with data analysis to answer the user's questions while satisfying the constraints.
According to the analysis SQL obtained by the user's goal, select the best one from the following display forms, if it cannot be determined, use Text as the display,Just need to return the type name into the result.
Display type:
{disply_type}
Respond in the following json format:
{response}
Ensure the response is correct json and can be parsed by Python json.loads
Constraint:
1.Please output your thinking process and analysis ideas first, and then output the specific data analysis results. The data analysis results are output in the following format:<api-call><name>display type</name><args><sql>Correct duckdb data analysis sql</sql></args></api-call>
2.For the available display methods of data analysis results, please choose the most appropriate one from the following display methods. If you are not sure, use 'response_data_text' as the display. The available display types are as follows:{disply_type}
3.The table name that needs to be used in SQL is: {table_name}, please make sure not to use column names that are not in the data structure.
4.Give priority to answering using data analysis. If the user's question does not involve data analysis, you can answer according to your understanding.
User Questions:
{user_input}
"""
_PROMPT_SCENE_DEFINE_ZH = """你是一个数据分析专家!"""
_DEFAULT_TEMPLATE_ZH = """
请使用上述历史对话中的数据结构和列信息,根据用户目标:{user_input}给出正确的duckdb SQL进行数据分析和问题回答
请确保不要使用不在数据结构中的列名。
SQL中需要使用的表名是: {table_name}
请使用上述历史对话中的数据结构信息,在满足约束条件下结合数据分析回答用户的问题
根据用户目标得到的分析SQL请从以下显示类型中选择最合适的一种用来展示结果数据如果无法确定则使用'Text'作为显示, 只需要将类型名称返回到结果中。
显示类型如下:
{disply_type}
以以下 json 格式响应::
{response}
确保响应是正确的json,并且可以被Python的json.loads方法解析.
约束条件:
1.请先输出你的分析思路内容,再输出具体的数据分析结果,其中数据分析结果部分确保用如下格式输出:<api-call><name>[数据展示方式]</name><args><sql>[正确的duckdb数据分析sql]</sql></args></api-call>
2.请确保数据分析结果格式的内容在整个回答中只出现一次,确保上述结构稳定,把[]部分内容替换为对应的值
3.数据分析结果可用的展示方式请在下面的展示方式中选择最合适的一种,放入数据分析结果的name字段内如果无法确定则使用'Text'作为显示,可用显示类型如下: {disply_type}
4.SQL中需要使用的表名是: {table_name},请确保不要使用不在数据结构中的列名。
5.优先使用数据分析的方式回答,如果用户问题不涉及数据分析内容,你可以按你的理解进行回答
6.请确保你的输出内容有良好的markdown格式的排版
用户问题:{user_input}
请确保你的输出格式如下:
需要告诉用户的分析思路.
<api-call><name>[数据展示方式]</name><args><sql>[正确的duckdb数据分析sql]</sql></args></api-call>
"""
RESPONSE_FORMAT_SIMPLE = {
"sql": "analysis SQL",
"thoughts": "Current thinking and value of data analysis",
"display": "display type name",
}
_DEFAULT_TEMPLATE = (
_DEFAULT_TEMPLATE_EN if CFG.LANGUAGE == "en" else _DEFAULT_TEMPLATE_ZH
)
_PROMPT_SCENE_DEFINE = (
_PROMPT_SCENE_DEFINE_EN if CFG.LANGUAGE == "en" else _PROMPT_SCENE_DEFINE_ZH
)
PROMPT_SEP = SeparatorStyle.SINGLE.value
PROMPT_NEED_NEED_STREAM_OUT = False
PROMPT_NEED_NEED_STREAM_OUT = True
# Temperature is a configuration hyperparameter that controls the randomness of language model output.
# A high temperature produces more unpredictable and creative results, while a low temperature produces more common and conservative output.
@@ -62,8 +64,7 @@ PROMPT_TEMPERATURE = 0.8
prompt = PromptTemplate(
template_scene=ChatScene.ChatExcel.value(),
input_variables=["user_input", "table_name", "disply_type"],
response_format=json.dumps(RESPONSE_FORMAT_SIMPLE, ensure_ascii=False, indent=4),
template_define=PROMPT_SCENE_DEFINE,
template_define=_PROMPT_SCENE_DEFINE,
template=_DEFAULT_TEMPLATE,
stream_out=PROMPT_NEED_NEED_STREAM_OUT,
output_parser=ChatExcelOutputParser(