Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(wren-ai-service): improve text2chart and text2answer #1016

Merged
merged 7 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
paopa marked this conversation as resolved.
Show resolved Hide resolved
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
Loading