DataAnalyzr.ask(
    user_input: str = None,
    outputs: list = None,
    plot_path: str = None,
    recommendations_params: dict = None,
    counts: dict = None,
    context: dict = None,
    **kwargs,
) -> dict

This method orchestrates the analysis process and generates visualization, insights, recommendations, and tasks based on the specified inputs and parameters. It is the recommended method to use for generating visualization, insights, recommendations, and tasks.

  1. The method coordinates the analysis process and generates visualisation, insights, recommendations, and tasks based on the specified parameters.
  2. Uses the analysis, visualisation, insights, recommendations, and tasks methods internally.
  3. It allows for customization of outputs, analysis rerun, insights usage, recommendations format, output type, and counts.
  4. The generated outputs are returned as a dictionary.

Parameters

user_input
string
required

The input string provided by the user for generating outputs.

user_input = "What are the insights for the dataset?"
outputs
list

List of outputs to generate. Possible values are visualisation, insights, recommendations, and tasks. Defaults to ["visualisation", "insights", "recommendations", "tasks"].

outputs = ["insights", "recommendations"]
plot_path
string

Path to save the generated plot. Only relevant when outputs includes visualisation. Defaults to generated_plots/<random-plot-name>.png.

plot_path = "path/to/save/plot.png"
recommendations_params
dictionary

Parameters for generating recommendations. Includes from_insights, output_type and json_format.

recommendations_params = {
    "from_insights": True,
    "output_type": "json",
    "json_format": {
        "Recommendation": "Recommendation text",
        "Reason": "Reason for the recommendation",
        "Impact": "Impact of the recommendation",
    },
}
counts
dictionary

Dictionary containing the counts of insights, recommendations, and tasks to generate.

counts = {
    "insights": 3,
    "recommendations": 3,
    "tasks": 5,
}
context
dictionary

Context dictionary for the analysis. Includes analysis, visualisation, insights, recommendations, and tasks.

context = {
    "analysis": "Analyze sales data",
    "visualisation": "Context for visualisation",
    "insights": "Context for insights",
    "recommendations": "Improve sales performance",
    "tasks": "Analyze sales data",
}
rerun_analysis
boolean

Whether to rerun the analysis before generating outputs. Default is True.

rerun_analysis = True
max_retries
integer

Maximum number of retries for generating outputs. Default is 10.

max_retries = 5
time_limit
integer

Time limit in seconds for generating outputs. Default is 45 for analysis and 60 for visualization.

time_limit = 60
auto_train
boolean

Whether to automatically add questions with their SQL query or Python code to the vector store. Default is True.

auto_train = True

Returns

response
dictionary

Dictionary containing the generated outputs. Includes visualisation, insights, recommendations, and tasks.

response = {
    "visualisation": "path/to/plot.png",
    "insights": "-Insight 1\n-Insight 2\n-Insight 3",
    "recommendations": "Recommendation 1\nRecommendation 2\nRecommendation 3",
    "tasks": "Task 1\nTask 2\nTask 3\nTask 4\nTask 5",
}

Example usage

# Ask for visualisation, insights, recommendations, and tasks
response = data_analyzr.ask(
    user_input="What are the insights for the dataset?",
    outputs=["visualisation", "insights", "recommendations", "tasks"],
    plot_path="path/to/plot.png",
    recommendations_params={
        "from_insights": True,
        "output_type": "json",
        "json_format": {
            "Recommendation": "Recommendation text",
            "Reason": "Reason for the recommendation",
            "Impact": "Impact of the recommendation",
        },
    },
    counts={
        "insights": 3,
        "recommendations": 3,
        "tasks": 5,
    },
    context={
        "analysis": "Analyze sales data",
        "visualisation": "Context for visualisation",
        "insights": "Context for insights",
        "recommendations": "Improve sales performance",
        "tasks": "Analyze sales data",
    },
    rerun_analysis=True,
    max_retries=5,
    time_limit=60,
    auto_train=True,
)

# Display the visualisation
from PIL import Image
Image.open(response["visualisation"]).show()

# Print insights
print(response["insights"])

# Print recommendations
print(response["recommendations"])

# Print tasks
print(response["tasks"])