feat: optimize chart generation file name

This commit is contained in:
ZJU_czx
2025-04-03 18:48:41 +08:00
parent ca63cb1b32
commit f1cad2f69e
4 changed files with 19 additions and 10 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
SYSTEM_PROMPT = """You are an AI agent designed to data analysis / visualization task. You have various tools at your disposal that you can call upon to efficiently complete complex requests.
# Note:
1. The workspace directory is: {directory}; Read / write file in workspace
2. Generate analysis conclusion report in the end"""
2. Generate analysis conclusion report in the end
3. Use at most One Tool in each step"""
NEXT_STEP_PROMPT = """Based on user needs, break down the problem and use different tools step by step to solve it.
# Note
@@ -28,7 +28,7 @@ class VisualizationPrepare(NormalPythonExecute):
3. Save information in json file.( format: {"csvFilePath": string, "chartTitle": string}[])
## Insight Type
1. Select the insights from the data_visualization results that you want to add to the chart.
2. Save information in json file.( format: {"chartPath": string, "insights_id": number[]}[])
2. Save information in json file.( format: {"chartPath": string, "insights_id": number[]}[]) (chartPath is output by data_visualization tool)
# Note
1. You can generate one or multiple csv data with different visualization needs.
2. Make each chart data esay, clean and different.
@@ -195,7 +195,11 @@ Outputs:
return {"observation": f"{success_template}"}
async def execute(
self, json_path: str, output_type: str, tool_type: str, language: str
self,
json_path: str,
output_type: str | None = "html",
tool_type: str | None = "visualization",
language: str | None = "en",
) -> str:
try:
logger.info(f"📈 data_visualization with {json_path} in: {tool_type} ")
@@ -140,7 +140,10 @@ const setInsightTemplate = (
}
if (res) {
fs.writeFileSync(path, res, "utf-8");
return { insight_path: path, insight_md: res };
return {
insight_path: path,
insight_md: res + "\n ## Next Step\nConsider add insights into chart",
};
}
return {};
};
@@ -191,7 +194,7 @@ async function generateChart(
} = {};
const {
dataset,
userPrompt,
userPrompt = "",
directory,
width,
height,
@@ -199,11 +202,12 @@ async function generateChart(
fileName,
language,
} = options;
const chartTitle = userPrompt.trim();
try {
// Get chart spec and save in local file
const jsonDataset = isString(dataset) ? JSON.parse(dataset) : dataset;
const { spec, error, chartType } = await vmind.generateChart(
userPrompt,
chartTitle,
undefined,
jsonDataset,
{
@@ -218,18 +222,18 @@ async function generateChart(
}
spec.title = {
text: userPrompt,
text: chartTitle,
};
if (!fs.existsSync(path.join(directory, "visualization"))) {
fs.mkdirSync(path.join(directory, "visualization"));
}
const specPath = getSavedPathName(directory, fileName, "json");
const specPath = getSavedPathName(directory, chartTitle, "json");
res.chart_path = await saveChartRes({
directory,
spec,
width,
height,
fileName,
fileName: chartTitle,
outputType,
});
@@ -274,7 +278,7 @@ async function generateChart(
res = {
...res,
...setInsightTemplate(
getSavedPathName(directory, fileName, "md"),
getSavedPathName(directory, chartTitle, "md"),
userPrompt,
insightsText
),