refactor: refactor code by pre-commit
This commit is contained in:
@@ -18,9 +18,7 @@ class DataAnalysis(ToolCallAgent):
|
||||
"""
|
||||
|
||||
name: str = "DataAnalysis"
|
||||
description: str = (
|
||||
"An analytical agent that utilizes multiple tools to solve diverse data analysis tasks"
|
||||
)
|
||||
description: str = "An analytical agent that utilizes multiple tools to solve diverse data analysis tasks"
|
||||
|
||||
system_prompt: str = SYSTEM_PROMPT.format(directory=config.workspace_root)
|
||||
next_step_prompt: str = NEXT_STEP_PROMPT
|
||||
|
||||
@@ -119,4 +119,3 @@ python -m app.tool.chart_visualization.test.simple_chart
|
||||
python -m app.tool.chart_visualization.test.simple_report
|
||||
```
|
||||
结果同样位于`worksapce\visualization`下
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from app.tool.chart_visualization.data_visualization import DataVisualization
|
||||
from app.tool.chart_visualization.chart_prepare import VisualizationPrepare
|
||||
from app.tool.chart_visualization.data_visualization import DataVisualization
|
||||
from app.tool.chart_visualization.python_execute import NormalPythonExecute
|
||||
|
||||
|
||||
__all__ = ["DataVisualization", "VisualizationPrepare", "NormalPythonExecute"]
|
||||
|
||||
@@ -5,9 +5,7 @@ class VisualizationPrepare(NormalPythonExecute):
|
||||
"""A tool for Chart Generation Preparation"""
|
||||
|
||||
name: str = "visualization_preparation"
|
||||
description: str = (
|
||||
"Using Python code to generates metadata of data_visualization tool. Outputs: 1) JSON Information. 2) Cleaned CSV data files (Optional)."
|
||||
)
|
||||
description: str = "Using Python code to generates metadata of data_visualization tool. Outputs: 1) JSON Information. 2) Cleaned CSV data files (Optional)."
|
||||
parameters: dict = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
import json
|
||||
import asyncio
|
||||
import pandas as pd
|
||||
import json
|
||||
import os
|
||||
from typing import Any, Hashable
|
||||
|
||||
import pandas as pd
|
||||
from pydantic import Field, model_validator
|
||||
|
||||
from app.llm import LLM
|
||||
from app.tool.base import BaseTool
|
||||
from app.logger import logger
|
||||
from app.config import config
|
||||
from app.llm import LLM
|
||||
from app.logger import logger
|
||||
from app.tool.base import BaseTool
|
||||
|
||||
|
||||
class DataVisualization(BaseTool):
|
||||
name: str = "data_visualization"
|
||||
description: str = (
|
||||
"""Visualize statistical chart or Add insights in chart with JSON info from visualization_preparation tool. You can do steps as follows:
|
||||
description: str = """Visualize statistical chart or Add insights in chart with JSON info from visualization_preparation tool. You can do steps as follows:
|
||||
1. Visualize statistical chart
|
||||
2. Choose insights into chart based on step 1 (Optional)
|
||||
Outputs:
|
||||
1. Charts (png/html)
|
||||
2. Charts Insights (.md)(Optional)"""
|
||||
)
|
||||
parameters: dict = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -85,7 +84,7 @@ Outputs:
|
||||
if len(result) == 0:
|
||||
return "Is EMPTY!"
|
||||
for item in result:
|
||||
content += f"""## {item["title"]}\nChart saved in: {item["chart_path"]}"""
|
||||
content += f"""## {item['title']}\nChart saved in: {item['chart_path']}"""
|
||||
if "insight_path" in item and item["insight_path"] and "insight_md" in item:
|
||||
content += "\n" + item["insight_md"]
|
||||
else:
|
||||
@@ -130,7 +129,7 @@ Outputs:
|
||||
for index, result in enumerate(results):
|
||||
csv_path = csv_file_path[index]
|
||||
if "error" in result and "chart_path" not in result:
|
||||
error_list.append(f"Error in {csv_path}: {result["error"]}")
|
||||
error_list.append(f"Error in {csv_path}: {result['error']}")
|
||||
else:
|
||||
success_list.append(
|
||||
{
|
||||
@@ -178,11 +177,11 @@ Outputs:
|
||||
for index, result in enumerate(results):
|
||||
chart_path = chart_file_path[index]
|
||||
if "error" in result and "chart_path" not in result:
|
||||
error_list.append(f"Error in {chart_path}: {result["error"]}")
|
||||
error_list.append(f"Error in {chart_path}: {result['error']}")
|
||||
else:
|
||||
success_list.append(chart_path)
|
||||
success_template = (
|
||||
f"# Charts Update with Insights\n{",".join(success_list)}"
|
||||
f"# Charts Update with Insights\n{','.join(success_list)}"
|
||||
if len(success_list) > 0
|
||||
else ""
|
||||
)
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
from app.tool.python_execute import PythonExecute
|
||||
from app.config import config
|
||||
from app.tool.python_execute import PythonExecute
|
||||
|
||||
|
||||
class NormalPythonExecute(PythonExecute):
|
||||
"""A tool for executing Python code with timeout and safety restrictions."""
|
||||
|
||||
name: str = "python_execute"
|
||||
description: str = (
|
||||
"""Execute Python code for in-depth data analysis / data report(task conclusion) / other normal task without direct visualization."""
|
||||
)
|
||||
description: str = """Execute Python code for in-depth data analysis / data report(task conclusion) / other normal task without direct visualization."""
|
||||
parameters: dict = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncio
|
||||
from app.agent.data_analysis import DataAnalysis
|
||||
from app.logger import logger
|
||||
|
||||
|
||||
prefix = "Help me generate charts and save them locally, specifically:"
|
||||
tasks = [
|
||||
{
|
||||
@@ -181,9 +182,9 @@ async def main():
|
||||
logger.info(f"Begin task {index} / {len(tasks)}!")
|
||||
agent = DataAnalysis()
|
||||
await agent.run(
|
||||
f"{prefix},chart_description:{item["prompt"]},Data:{item["data"]}"
|
||||
f"{prefix},chart_description:{item['prompt']},Data:{item['data']}"
|
||||
)
|
||||
logger.info(f"Finish with {item["prompt"]}")
|
||||
logger.info(f"Finish with {item['prompt']}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
|
||||
from app.agent.data_analysis import DataAnalysis
|
||||
|
||||
|
||||
# from app.agent.manus import Manus
|
||||
|
||||
|
||||
|
||||
@@ -10,9 +10,7 @@ class PythonExecute(BaseTool):
|
||||
"""A tool for executing Python code with timeout and safety restrictions."""
|
||||
|
||||
name: str = "python_execute"
|
||||
description: str = (
|
||||
"Executes Python code string. Note: Only print outputs are visible, function return values are not captured. Use print statements to see results."
|
||||
)
|
||||
description: str = "Executes Python code string. Note: Only print outputs are visible, function return values are not captured. Use print statements to see results."
|
||||
parameters: dict = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Reference in New Issue
Block a user