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

Additional guidance on configuring the pandasai.json file in the LLM setup process. #1407

Closed
Muhammad-Adam1 opened this issue Oct 24, 2024 · 10 comments
Labels
documentation Improvements or additions to documentation

Comments

@Muhammad-Adam1
Copy link
Contributor

Path: /llms

Copy link

dosubot bot commented Oct 24, 2024

To configure the pandasai.json file in the LLM setup process, you can use the following JSON structure:

{
  "save_logs": true,
  "verbose": false,
  "enforce_privacy": false,
  "enable_cache": true,
  "use_error_correction_framework": true,
  "max_retries": 3,
  "open_charts": true,
  "save_charts": false,
  "save_charts_path": "exports/charts",
  "custom_whitelisted_dependencies": [],
  "llm": "BambooLLM",
  "llm_options": null
}

This configuration includes options such as enabling logs, setting verbosity, enforcing privacy, enabling cache, using an error correction framework, setting the maximum number of retries, and configuring chart options. You can adjust these settings according to your requirements [1].

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the documentation Improvements or additions to documentation label Oct 24, 2024
@Muhammad-Adam1
Copy link
Contributor Author

@dosu and how can i use this file in the code and can I use it for every LLM or just for Bamboo LLM.

Copy link

dosubot bot commented Oct 24, 2024

The pandasai.json file can be used to specify the LLM (Large Language Model) and its options, such as API keys, for use with PandasAI. It is not limited to Bamboo LLM; you can specify other supported LLMs in the pandasai.json file as well. Here is an example of how you might configure it for Bamboo LLM:

{
  "llm": "BambooLLM",
  "llm_options": {
    "api_key": "API_KEY_GOES_HERE"
  }
}

This configuration file allows you to specify the LLM and any necessary parameters, making it applicable for any LLM supported by PandasAI, not just Bamboo LLM. The load_config_from_json function in the PandasAI codebase attempts to load the configuration from the pandasai.json file and will default to using Bamboo LLM if no LLM is specified and no override configuration is provided [1][2].

To continue talking to Dosu, mention @dosu.

@Muhammad-Adam1
Copy link
Contributor Author

@dosu can you provide example code and explain each and every aspect in this code

Copy link

dosubot bot commented Oct 24, 2024

Here's an example of how you can use the pandasai.json configuration file in your code with PandasAI, along with an explanation of each aspect:

import pandas as pd
from pandasai import SmartDataframe
from pandasai.config import load_config_from_json

# Load configuration from pandasai.json
config = load_config_from_json()

# Create a sample pandas DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'City': ['New York', 'Los Angeles', 'Chicago']
}
df = pd.DataFrame(data)

# Initialize a SmartDataframe with the loaded configuration
smart_df = SmartDataframe(df, config=config)

# Example query using natural language
response = smart_df.chat("What is the average age?")

# Print the response
print(response)

Explanation:

  1. Import Statements:

    • import pandas as pd: Imports the pandas library, which is used for data manipulation and analysis.
    • from pandasai import SmartDataframe: Imports the SmartDataframe class from PandasAI, which allows you to interact with dataframes using natural language.
    • from pandasai.config import load_config_from_json: Imports the load_config_from_json function to load configuration settings from the pandasai.json file.
  2. Load Configuration:

    • config = load_config_from_json(): Loads the configuration settings from the pandasai.json file. This configuration can include settings for the LLM, logging, privacy, and more.
  3. Create a DataFrame:

    • A sample pandas DataFrame df is created with columns Name, Age, and City. This is the data you will interact with using PandasAI.
  4. Initialize SmartDataframe:

    • smart_df = SmartDataframe(df, config=config): Initializes a SmartDataframe object with the pandas DataFrame df and the loaded configuration. This allows you to use natural language queries on the DataFrame.
  5. Natural Language Query:

    • response = smart_df.chat("What is the average age?"): Uses the chat method of SmartDataframe to ask a natural language question about the data. The LLM processes the query and returns the result.
  6. Print the Response:

    • print(response): Outputs the result of the query, which in this case would be the average age of the individuals in the DataFrame.

This example demonstrates how to set up and use PandasAI with a configuration file to perform data analysis using natural language queries. The pandasai.json file allows you to specify the LLM and its options, making it flexible for different use cases and models.

To continue talking to Dosu, mention @dosu.

@Muhammad-Adam1
Copy link
Contributor Author

Muhammad-Adam1 commented Oct 28, 2024

@dosu
can you provide me code as an example that how to use the diff configurations within the pandasai.json file, and elaborate each config, that for what purpose it is used for .
Also tell me what's the structure of the pandasai.json file will be

Copy link

dosubot bot commented Oct 28, 2024

Here's an example of how you can use the pandasai.json configuration file in your code with PandasAI, along with an explanation of each configuration option:

import pandas as pd
from pandasai import SmartDataframe
from pandasai.config import load_config_from_json

# Load configuration from pandasai.json
config = load_config_from_json()

# Create a sample pandas DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'City': ['New York', 'Los Angeles', 'Chicago']
}
df = pd.DataFrame(data)

# Initialize a SmartDataframe with the loaded configuration
smart_df = SmartDataframe(df, config=config)

# Example query using natural language
response = smart_df.chat("What is the average age?")

# Print the response
print(response)

Explanation of Configurations:

  1. save_logs: Determines if log messages are saved to a file. If True, logs are saved to "pandasai.log" [1].

  2. verbose: Controls the verbosity of the output. If True, more detailed logs are shown.

  3. enforce_privacy: Enables privacy measures during data analysis. If True, privacy is enforced [2].

  4. enable_cache: Improves performance by caching query results in a SQLite database, reducing API calls and response time [3].

  5. use_error_correction_framework: Intended to handle errors during execution, though specific details are not provided in the repository.

  6. max_retries: Sets the number of retry attempts for code execution in case of errors. Default is 3 retries [4].

  7. open_charts: Automatically opens charts when generated if set to True [5].

  8. save_charts: Determines if charts are saved automatically. If True, charts are saved to the specified path.

  9. save_charts_path: Specifies the directory path where charts are saved if save_charts is True.

  10. custom_whitelisted_dependencies: Allows adding custom modules to the whitelist for code execution, enhancing flexibility while maintaining security [6].

  11. llm: Specifies the Large Language Model to use. Options include BambooLLM, OpenAI, Google PaLM, and others [7].

  12. llm_options: Contains specific options for the LLM, such as API keys.

These configurations allow you to customize the behavior of PandasAI to suit your needs, from logging and privacy to performance and model selection.

To continue talking to Dosu, mention @dosu.

@Muhammad-Adam1
Copy link
Contributor Author

Also tell me what's the structure of the pandasai.json file will be
including these options
{
"llm": "AzureOpenAI",
"llm_options": {
"api_token" : "MY_API_TOKEN",
"azure_endpoint" : "https://jljkjko",
"api_version": "MY_API_VERSION",
"deployment_name": "CUSTOM_NAME"
}
}
@dosu

Copy link

dosubot bot commented Oct 28, 2024

The structure of the pandasai.json file with the specified options for using AzureOpenAI would look like this:

{
    "llm": "AzureOpenAI",
    "llm_options": {
        "api_token": "MY_API_TOKEN",
        "azure_endpoint": "https://YOUR_RESOURCE_NAME.openai.azure.com/",
        "api_version": "MY_API_VERSION",
        "deployment_name": "CUSTOM_NAME"
    }
}

Explanation of Each Option:

  • llm: Specifies the Large Language Model to use, in this case, AzureOpenAI.

  • llm_options: Contains specific options required for AzureOpenAI:

    • api_token: Your Azure OpenAI API token, necessary for authentication.
    • azure_endpoint: The endpoint URL for your Azure OpenAI resource.
    • api_version: The version of the Azure OpenAI API you are using.
    • deployment_name: The custom name of the deployed model, which identifies the specific model configuration to use [1].

To continue talking to Dosu, mention @dosu.

@gdcsinaptik
Copy link
Collaborator

@Muhammad-Adam1 here you find further examples on llm usage: https://docs.pandas-ai.com/llms. If you run into issues, be more specific and consider using github discussions or our discord channel for QA and learning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants