Skip to content
5 changes: 3 additions & 2 deletions application/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ def user_feedback(input_data: FeedBackInput):
input_data.query_intent, input_data.query_answer_list)
return upvote_res
else:
logger.info("user downvote {}", input_data)
return True
downvote_res = service.user_feedback_downvote(input_data.data_profiles, input_data.query,
input_data.query_intent, input_data.query_answer_list)
return downvote_res


@router.websocket("/ws")
Expand Down
29 changes: 27 additions & 2 deletions application/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def ask(question: Question) -> Answer:
database_profile['db_type'] = ConnectionManagement.get_db_type_by_name(conn_name)
prompt_map = database_profile['prompt_map']

entity_slot = []
# 通过标志位控制后续的逻辑
# 主要的意图有4个, 拒绝, 查询, 思维链, 知识问答
if intent_ner_recognition_flag:
Expand Down Expand Up @@ -292,7 +293,7 @@ def ask(question: Question) -> Answer:
search_intent_result = get_sql_result_tool(database_profile,
current_nlq_chain.get_generated_sql())
if search_intent_result["status_code"] == 500:
sql_search_result.data_analyse = "-1"
sql_search_result.data_analyse = "The query results are temporarily unavailable, please switch to debugging webpage to try the same query and check the log file for more information."
else:
if search_intent_result["data"] is not None and len(search_intent_result["data"]) > 0:
search_intent_analyse_result = data_analyse_tool(model_type, prompt_map, search_box,
Expand All @@ -315,7 +316,6 @@ def ask(question: Question) -> Answer:
intent="normal_search",
log_info=log_info,
time_str=current_time)

answer = Answer(query=search_box, query_intent="normal_search", knowledge_search_result=knowledge_search_result,
sql_search_result=sql_search_result, agent_search_result=agent_search_response,
suggested_question=generate_suggested_question_list)
Expand Down Expand Up @@ -382,6 +382,31 @@ def user_feedback_upvote(data_profiles: str, query: str, query_intent: str, quer
except Exception as e:
return False

def user_feedback_downvote(data_profiles: str, query: str, query_intent: str, query_answer_list):
try:
if query_intent == "normal_search":
if len(query_answer_list) > 0:
log_id = generate_log_id()
current_time = get_current_time()
LogManagement.add_log_to_database(log_id=log_id, profile_name=data_profiles,
sql=query_answer_list[0].sql, query=query,
intent="normal_search_user_downvote",
log_info="",
time_str=current_time)
elif query_intent == "agent_search":
for each in query_answer_list:
log_id = generate_log_id()
current_time = get_current_time()
LogManagement.add_log_to_database(log_id=log_id, profile_name=data_profiles,
sql=each.sql, query=query + "; The sub task is " + each.query,
intent="agent_search_user_downvote",
log_info="",
time_str=current_time)
return True
except Exception as e:
return False



def get_nlq_chain(question: Question) -> NLQChain:
logger.debug(question)
Expand Down
33 changes: 13 additions & 20 deletions application/utils/prompts/check_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,19 @@
},
'agent': {
'system_prompt': {
'mixtral-8x7b-instruct-0': [
'table_schema_data',
'sql_guidance',
'example_data'
],
'llama3-70b-instruct-0': [
'table_schema_data',
'sql_guidance',
'example_data'
],
'haiku-20240307v1-0': [
'table_schema_data',
'sql_guidance',
'example_data'
],
'sonnet-20240229v1-0': [
'table_schema_data',
'sql_guidance',
'example_data'
]
'mixtral-8x7b-instruct-0': ['table_schema_data',
'sql_guidance',
'example_data'
],
'llama3-70b-instruct-0': ['table_schema_data',
'sql_guidance',
'example_data'],
'haiku-20240307v1-0': ['table_schema_data',
'sql_guidance',
'example_data'],
'sonnet-20240229v1-0': ['table_schema_data',
'sql_guidance',
'example_data']
},
'user_prompt': {
'mixtral-8x7b-instruct-0': ['question'],
Expand Down
29 changes: 19 additions & 10 deletions application/utils/prompts/generate_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@
# agent任务拆分
agent_system_prompt_dict['mixtral-8x7b-instruct-0'] = """
you are a data analysis expert as well as a retail expert.
Your current task is to conduct an in-depth analysis of the data.
Your current task is to break down the current problem into multiple word problems based on the problem and the provided data table structure.

<instructions>
1. Fully understand the problem raised by the user
Expand All @@ -673,7 +673,8 @@

</guidelines>

here is a example:
Here are some examples of breaking down complex problems into subtasks:

<example>

{example_data}
Expand All @@ -682,11 +683,12 @@

Please conduct a thorough analysis of the user's question according to the above instructions, and finally only output the JSON structure without outputting any other content.


"""

agent_system_prompt_dict['llama3-70b-instruct-0'] = """
you are a data analysis expert as well as a retail expert.
Your current task is to conduct an in-depth analysis of the data.
Your current task is to break down the current problem into multiple word problems based on the problem and the provided data table structure.

<instructions>
1. Fully understand the problem raised by the user
Expand All @@ -709,7 +711,8 @@

</guidelines>

here is a example:
Here are some examples of breaking down complex problems into subtasks:

<example>

{example_data}
Expand All @@ -722,7 +725,7 @@

agent_system_prompt_dict['haiku-20240307v1-0'] = """
you are a data analysis expert as well as a retail expert.
Your current task is to conduct an in-depth analysis of the data.
Your current task is to break down the current problem into multiple word problems based on the problem and the provided data table structure.

<instructions>
1. Fully understand the problem raised by the user
Expand All @@ -745,7 +748,8 @@

</guidelines>

here is a example:
Here are some examples of breaking down complex problems into subtasks:

<example>

{example_data}
Expand All @@ -758,7 +762,7 @@

agent_system_prompt_dict['sonnet-20240229v1-0'] = """
you are a data analysis expert as well as a retail expert.
Your current task is to conduct an in-depth analysis of the data.
Your current task is to break down the current problem into multiple word problems based on the problem and the provided data table structure.

<instructions>
1. Fully understand the problem raised by the user
Expand All @@ -781,7 +785,8 @@

</guidelines>

here is a example:
Here are some examples of breaking down complex problems into subtasks:

<example>

{example_data}
Expand Down Expand Up @@ -1624,8 +1629,12 @@ def generate_agent_cot_system_prompt(ddl, prompt_map, search_box, model_id, agen
user_prompt = prompt_map.get('agent', {}).get('user_prompt', {}).get(name)

# reformat prompts
system_prompt = system_prompt.format(table_schema_data=ddl, sql_guidance=agent_cot_example_str,
example_data=AGENT_COT_EXAMPLE)
if agent_cot_example_str != "":
system_prompt = system_prompt.format(table_schema_data=ddl, sql_guidance="",
example_data=agent_cot_example_str)
else:
system_prompt = system_prompt.format(table_schema_data=ddl, sql_guidance="",
example_data=AGENT_COT_EXAMPLE)
user_prompt = user_prompt.format(question=search_box)

return user_prompt, system_prompt
Expand Down