Skip to content

Commit 277480c

Browse files
committed
update
1 parent 6a5fd8e commit 277480c

File tree

6 files changed

+69
-7
lines changed

6 files changed

+69
-7
lines changed

wren-ai-service/src/pipelines/generation/data_assistance.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
data_assistance_system_prompt = """
2121
### TASK ###
2222
You are a data analyst great at answering user's questions about given database schema.
23-
Please carefully read user's question and database schema to answer it in easy to understand manner
23+
Please carefully read user's question, intent for the question, and database schema to answer it in easy to understand manner
2424
using the Markdown format. Your goal is to help guide user understand its database!
2525
2626
### INSTRUCTIONS ###
@@ -50,6 +50,7 @@
5050
5151
### INPUT ###
5252
User's question: {{query}}
53+
Intent for user's question: {{intent_reasoning}}
5354
Language: {{language}}
5455
5556
Custom Instruction: {{ custom_instruction }}
@@ -62,6 +63,7 @@
6263
@observe(capture_input=False)
6364
def prompt(
6465
query: str,
66+
intent_reasoning: str,
6567
db_schemas: list[str],
6668
language: str,
6769
histories: list[AskHistory],
@@ -70,6 +72,7 @@ def prompt(
7072
) -> dict:
7173
_prompt = prompt_builder.run(
7274
query=query,
75+
intent_reasoning=intent_reasoning,
7376
histories=histories,
7477
db_schemas=db_schemas,
7578
language=language,
@@ -153,6 +156,7 @@ async def _get_streaming_results(query_id):
153156
async def run(
154157
self,
155158
query: str,
159+
intent_reasoning: str,
156160
db_schemas: list[str],
157161
language: str,
158162
query_id: Optional[str] = None,
@@ -164,6 +168,7 @@ async def run(
164168
["data_assistance"],
165169
inputs={
166170
"query": query,
171+
"intent_reasoning": intent_reasoning,
167172
"db_schemas": db_schemas,
168173
"language": language,
169174
"query_id": query_id or "",

wren-ai-service/src/pipelines/generation/data_exploration_assistance.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
data_exploration_assistance_system_prompt = """
2121
You are a great data analyst good at exploring data.
22-
You are given a user question and a sql data.
23-
You need to understand the user question and the sql data, and then answer the user question.
22+
You are given a user question, an intent for the question, and a sql data.
23+
You need to understand the user question, the intent for the question, and the sql data, and then answer the user question.
24+
2425
### INSTRUCTIONS ###
2526
1. Your answer should be in the same language as the language user provided.
2627
2. You must follow the sql data to answer the user question.
@@ -30,6 +31,7 @@
3031
- provide insights and trends in the data
3132
- find out anomalies and outliers in the data
3233
5. You only need to use the skills required to answer the user question based on the user question and the sql data.
34+
3335
### OUTPUT FORMAT ###
3436
Please provide your response in proper Markdown format without ```markdown``` tags.
3537
"""
@@ -44,6 +46,7 @@
4446
4547
### INPUT ###
4648
User Question: {{query}}
49+
Intent for user's question: {{intent_reasoning}}
4750
Language: {{language}}
4851
SQL Data:
4952
{{ sql_data }}
@@ -58,6 +61,7 @@
5861
@observe(capture_input=False)
5962
def prompt(
6063
query: str,
64+
intent_reasoning: str,
6165
histories: list[AskHistory],
6266
language: str,
6367
sql_data: dict,
@@ -66,6 +70,7 @@ def prompt(
6670
) -> dict:
6771
_prompt = prompt_builder.run(
6872
query=query,
73+
intent_reasoning=intent_reasoning,
6974
language=language,
7075
sql_data=sql_data,
7176
histories=histories,
@@ -144,6 +149,7 @@ async def _get_streaming_results(query_id):
144149
async def run(
145150
self,
146151
query: str,
152+
intent_reasoning: str,
147153
sql_data: dict,
148154
language: str,
149155
query_id: Optional[str] = None,
@@ -155,6 +161,7 @@ async def run(
155161
["data_exploration_assistance"],
156162
inputs={
157163
"query": query,
164+
"intent_reasoning": intent_reasoning,
158165
"language": language,
159166
"query_id": query_id or "",
160167
"sql_data": sql_data,

wren-ai-service/src/pipelines/generation/misleading_assistance.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
misleading_assistance_system_prompt = """
2121
### TASK ###
22-
You are a helpful assistant that can help users understand their data better. Currently, you are given a user's question that is potentially misleading.
23-
Your goal is to help guide user understand its data better and suggest few better questions to ask.
22+
You are a helpful assistant that can help users understand their data better. Currently, you are given a user's question, an intent for the question, and a database schema.
23+
Your goal is to help guide user understand its data better and suggest few better questions to ask based on the intent for the question and the database schema.
2424
2525
### INSTRUCTIONS ###
2626
@@ -50,6 +50,7 @@
5050
5151
### INPUT ###
5252
User's question: {{query}}
53+
Intent for user's question: {{intent_reasoning}}
5354
Language: {{language}}
5455
5556
Custom Instruction: {{ custom_instruction }}
@@ -62,6 +63,7 @@
6263
@observe(capture_input=False)
6364
def prompt(
6465
query: str,
66+
intent_reasoning: str,
6567
db_schemas: list[str],
6668
language: str,
6769
histories: list[AskHistory],
@@ -70,6 +72,7 @@ def prompt(
7072
) -> dict:
7173
_prompt = prompt_builder.run(
7274
query=query,
75+
intent_reasoning=intent_reasoning,
7376
histories=histories,
7477
db_schemas=db_schemas,
7578
language=language,
@@ -153,6 +156,7 @@ async def _get_streaming_results(query_id):
153156
async def run(
154157
self,
155158
query: str,
159+
intent_reasoning: str,
156160
db_schemas: list[str],
157161
language: str,
158162
query_id: Optional[str] = None,
@@ -164,6 +168,7 @@ async def run(
164168
["misleading_assistance"],
165169
inputs={
166170
"query": query,
171+
"intent_reasoning": intent_reasoning,
167172
"db_schemas": db_schemas,
168173
"language": language,
169174
"query_id": query_id or "",

wren-ai-service/src/pipelines/generation/user_clarification_assistance.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,48 @@
1818

1919

2020
user_clarification_assistance_system_prompt = """
21+
You are a helpful assistant that can help users understand their data better. Currently, you are given a user's question, an intent for the question, and a database schema.
22+
You should tell user why the question is not clear enough or vague and suggest a better question based on the intent for the question and the database schema.
23+
24+
### INSTRUCTIONS ###
25+
1. Response must be in the same language user specified in the Language section of the `### INPUT ###` section.
26+
2. There should be proper line breaks, whitespace, and Markdown formatting(headers, lists, tables, etc.) in your response.
27+
3. MUST NOT add SQL code in your response.
28+
4. MUST consider database schema when suggesting better questions.
29+
5. The maximum response length is 100 words.
30+
6. If the user provides a custom instruction, it should be followed strictly and you should use it to change the style of response.
31+
32+
### OUTPUT FORMAT ###
33+
Please provide your response in proper Markdown format without ```markdown``` tags.
2134
"""
2235

2336
user_clarification_assistance_user_prompt_template = """
37+
{% if histories %}
38+
### PREVIOUS QUESTIONS ###
39+
{% for history in histories %}
40+
{{ history.question }}
41+
{% endfor %}
42+
{% endif %}
43+
44+
### DATABASE SCHEMA ###
45+
{% for db_schema in db_schemas %}
46+
{{ db_schema }}
47+
{% endfor %}
48+
49+
### INPUT ###
50+
User Question: {{query}}
51+
Intent for user's question: {{intent_reasoning}}
52+
Language: {{language}}
53+
54+
Custom Instruction: {{ custom_instruction }}
2455
"""
2556

2657

2758
## Start of Pipeline
2859
@observe(capture_input=False)
2960
def prompt(
3061
query: str,
62+
intent_reasoning: str,
3163
db_schemas: list[str],
3264
language: str,
3365
histories: list[AskHistory],
@@ -36,6 +68,7 @@ def prompt(
3668
) -> dict:
3769
_prompt = prompt_builder.run(
3870
query=query,
71+
intent_reasoning=intent_reasoning,
3972
histories=histories,
4073
db_schemas=db_schemas,
4174
language=language,
@@ -119,6 +152,7 @@ async def _get_streaming_results(query_id):
119152
async def run(
120153
self,
121154
query: str,
155+
intent_reasoning: str,
122156
db_schemas: list[str],
123157
language: str,
124158
query_id: Optional[str] = None,
@@ -130,6 +164,7 @@ async def run(
130164
["user_clarification_assistance"],
131165
inputs={
132166
"query": query,
167+
"intent_reasoning": intent_reasoning,
133168
"db_schemas": db_schemas,
134169
"language": language,
135170
"query_id": query_id or "",

wren-ai-service/src/pipelines/generation/user_guide_assistance.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
user_guide_assistance_system_prompt = """
2121
You are a helpful assistant that can help users understand Wren AI.
22-
You are given a user question and a user guide.
23-
You need to understand the user question and the user guide, and then answer the user question.
22+
You are given a user question, an intent for the question, and a user guide.
23+
You need to understand the user question, the intent reasoning, and the user guide, and then answer the user question.
2424
2525
### INSTRUCTIONS ###
2626
1. Your answer should be in the same language as the language user provided.
@@ -44,6 +44,7 @@
4444
4545
### INPUT ###
4646
User Question: {{query}}
47+
Intent for user's question: {{intent_reasoning}}
4748
Language: {{language}}
4849
User Guide:
4950
{% for doc in docs %}
@@ -60,6 +61,7 @@
6061
@observe(capture_input=False)
6162
def prompt(
6263
query: str,
64+
intent_reasoning: str,
6365
language: str,
6466
wren_ai_docs: list[dict],
6567
histories: list[AskHistory],
@@ -68,6 +70,7 @@ def prompt(
6870
) -> dict:
6971
_prompt = prompt_builder.run(
7072
query=query,
73+
intent_reasoning=intent_reasoning,
7174
histories=histories,
7275
language=language,
7376
docs=wren_ai_docs,
@@ -153,6 +156,7 @@ async def _get_streaming_results(query_id):
153156
async def run(
154157
self,
155158
query: str,
159+
intent_reasoning: str,
156160
language: str,
157161
query_id: Optional[str] = None,
158162
histories: Optional[list[AskHistory]] = None,
@@ -163,6 +167,7 @@ async def run(
163167
["user_guide_assistance"],
164168
inputs={
165169
"query": query,
170+
"intent_reasoning": intent_reasoning,
166171
"language": language,
167172
"query_id": query_id or "",
168173
"histories": histories or [],

wren-ai-service/src/web/v1/services/ask.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ async def ask(
290290
asyncio.create_task(
291291
self._pipelines["misleading_assistance"].run(
292292
query=user_query,
293+
intent_reasoning=intent_reasoning,
293294
histories=histories,
294295
db_schemas=table_ddls,
295296
language=ask_request.configurations.language,
@@ -313,6 +314,7 @@ async def ask(
313314
asyncio.create_task(
314315
self._pipelines["data_assistance"].run(
315316
query=user_query,
317+
intent_reasoning=intent_reasoning,
316318
histories=histories,
317319
db_schemas=table_ddls,
318320
language=ask_request.configurations.language,
@@ -336,6 +338,7 @@ async def ask(
336338
asyncio.create_task(
337339
self._pipelines["user_guide_assistance"].run(
338340
query=user_query,
341+
intent_reasoning=intent_reasoning,
339342
histories=histories,
340343
language=ask_request.configurations.language,
341344
query_id=ask_request.query_id,
@@ -358,6 +361,7 @@ async def ask(
358361
asyncio.create_task(
359362
self._pipelines["data_exploration_assistance"].run(
360363
query=user_query,
364+
intent_reasoning=intent_reasoning,
361365
histories=histories,
362366
sql_data=last_sql_data,
363367
language=ask_request.configurations.language,
@@ -381,6 +385,7 @@ async def ask(
381385
asyncio.create_task(
382386
self._pipelines["user_clarification_assistance"].run(
383387
query=user_query,
388+
intent_reasoning=intent_reasoning,
384389
histories=histories,
385390
db_schemas=table_ddls,
386391
language=ask_request.configurations.language,

0 commit comments

Comments
 (0)