Skip to content

Commit

Permalink
chore(wren-ai-service): improve text2chart and text2answer (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyeh authored Dec 19, 2024
1 parent 1eff501 commit 5df4d03
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions wren-ai-service/src/pipelines/generation/chart_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def run(
generation_result = orjson.loads(replies[0])
reasoning = generation_result.get("reasoning", "")
if chart_schema := generation_result.get("chart_schema", {}):
# sometimes the chart_schema is still in string format
if isinstance(chart_schema, str):
chart_schema = orjson.loads(chart_schema)

validate(chart_schema, schema=vega_schema)
chart_schema["data"]["values"] = []
return {
Expand Down
6 changes: 5 additions & 1 deletion wren-ai-service/src/pipelines/generation/chart_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def run(
generation_result = orjson.loads(replies[0])
reasoning = generation_result.get("reasoning", "")
if chart_schema := generation_result.get("chart_schema", {}):
# sometimes the chart_schema is still in string format
if isinstance(chart_schema, str):
chart_schema = orjson.loads(chart_schema)

validate(chart_schema, schema=vega_schema)
chart_schema["data"]["values"] = []
return {
Expand Down Expand Up @@ -168,7 +172,7 @@ class ChartGenerationResults(BaseModel):
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "matched_schema",
"name": "chart_generation_schema",
"schema": ChartGenerationResults.model_json_schema(),
},
}
Expand Down
5 changes: 3 additions & 2 deletions wren-ai-service/src/pipelines/generation/sql_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
sql_to_answer_system_prompt = """
### TASK
You are a data analyst that great at answering user's questions based on the data, sql so that even non technical users can easily understand.
You are a data analyst that great at answering non-technical user's questions based on the data, sql so that even non technical users can easily understand.
Please answer the user's question in concise and clear manner in Markdown format.
### INSTRUCTIONS
1. Read the user's question and understand the user's intention.
2. Read the sql and understand the data.
4. Generate a consice and clear answer in string format and a reasoning process in string format to the user's question based on the data, sql.
3. Make sure the answer is aimed for non-technical users, so don't mention any technical terms such as SQL syntax.
4. Generate a concise and clear answer in string format to answerthe user's question based on the data and sql.
5. If answer is in list format, only list top few examples, and tell users there are more results omitted.
6. Answer must be in the same language user specified.
Expand Down
2 changes: 1 addition & 1 deletion wren-ai-service/src/pipelines/retrieval/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class RetrievalResults(BaseModel):
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "matched_schema",
"name": "retrieval_schema",
"schema": RetrievalResults.model_json_schema(),
},
}
Expand Down

0 comments on commit 5df4d03

Please sign in to comment.