DataAnalyzr(
    analysis_type: Literal["sql", "ml", "skip"],
    api_key: Optional[str] = None,
    class_params: Optional[dict] = None,
    generator_llm: Optional[LiteLLM] = None,
    analysis_llm: Optional[LiteLLM] = None,
    context: Optional[str] = None,
    log_params: Optional[dict] = None,
) -> DataAnalyzr

Constructor method for initializing a DataAnalyzr object.

Parameters

analysis_type
Literal['sql', 'ml', 'skip']
required

The type of analysis to be performed.

analysis_type = "sql"
api_key
string

API key for accessing LLM services. May also be set as an environment variable.

api_key = "sk-apikey"
class_params
dictionary

Dictionary of class parameters. Accepts max_retries, time_limit, and auto_train.

class_params = {
    "max_retries": 5, # int
    "time_limit": 60, # int
    "auto_train": True, # bool
}
generator_llm
LiteLLM

LLM instance for generating analysis. Default LLM used is GPT-4o.

from lyzr.base import LyzrLLMFactory
generator_llm = LyzrLLMFactory.from_defaults(model="gpt-4-turbo")

For details on configuring the LLM, see the Large Language Models guide.

analysis_llm
LiteLLM

LLM instance for performing analysis. Default LLM used is GPT-4o.

from lyzr.base import LyzrLLMFactory
analysis_llm = LyzrLLMFactory.from_defaults(model="gpt-4o")

For details on configuring the LLM, see the Large Language Models guide.

context
string or dictionary

Context for analysis and response generation. Default is an empty string.

  • This context is used in the analysis, insights, recommendations, and tasks methods.
  • When passed as a string, the same context is applied to all sections - analysis, insights, recommendations, and tasks.
  • When passed as a dictionary, it should have keys analysis, visualisation, insights, recommendations, and tasks.
  • To override the class context for a specific query, pass the context to the ask method.
context = "Sales data analysis for Q1 2023"
# or
context = {
    "analysis": "Sales data analysis for Q1 2023",
    "visualisation": "Distribution plot for sales data",
    "insights": "Key trends in sales data",
    "recommendations": "Improve sales performance",
    "tasks": "Analyze sales data",
}
log_params
dictionary

Dictionary of logging parameters. Accepts log_filename, log_level, and print_log.

log_params = {
    "log_filename": "dataanalyzr.csv", # str
    "log_level": "INFO", # str
    "print_log": False, # bool
}

Returns

data_analyzr
DataAnalyzr

DataAnalyzr object for performing conversational data analysis.

Example usage

from lyzr.base import LyzrLLMFactory
from lyzr.data_analyzr.data_analyzr import DataAnalyzr

analysis_type = "sql"
log_params = {
    "log_filename": "dataanalyzr.log",
    "log_level": "DEBUG",
    "print_log": True,
}
class_params = {
    "max_retries": 5,
    "time_limit": 60,
    "auto_train": True,
}
generator_llm = LyzrLLMFactory.from_defaults(model="gpt-4-turbo")
analysis_llm = LyzrLLMFactory.from_defaults(model="gpt-4o")
context = "Sales data analysis for Q1 2023"

data_analyzr = DataAnalyzr(
    analysis_type=analysis_type,
    api_key=api_key,
    class_params=class_params,
    generator_llm=generator_llm,
    analysis_llm=analysis_llm,
    context=context,
    log_params=log_params,
)