Set up Large Language Model in PandasAI
Release v3 is currently in beta. This documentation reflects the features and functionality in progress and may change before the final release.
PandasAI supports multiple LLMs.
You need to install the corresponding LLM extension.
Once an LLM extension is installed, you can configure it using pai.config.set()
.
Then, every time you use the .chat()
method, it will use the configured LLM.
LiteLLM provides a unified interface to multiple LLM providers including OpenAI, Anthropic, Google, and others.
Install the pandasai-litellm extension:
Then configure it in your code:
Install the pandasai-openai extension:
In order to use OpenAI models, you need to have an OpenAI API key. You can get one here. Once you have an API key, you can use it to instantiate an OpenAI object:
Configure OpenAI:
Install the pandasai-openai extension:
In order to use Azure OpenAI models, you need to have an Azure OpenAI API key. You can get one here. Once you have an API key, you can use it to instantiate an Azure OpenAI object:
Configure Azure OpenAI:
LiteLLM provides a unified interface to interact with 100+ LLM models from various providers including OpenAI, Azure, Anthropic, Google, AWS, Hugging Face, and many more. This makes it easy to switch between different LLM providers without changing your code.
Install the pandasai-litellm extension:
Configure LiteLLM with your chosen model. First, set up your API keys as environment variables:
LiteLLM supports a wide range of models from various providers, including but not limited to:
For a complete list of supported models and providers, visit the LiteLLM documentation.
Determinism in language models refers to the ability to produce the same output consistently given the same input under identical conditions. This characteristic is vital for:
The temperature parameter in language models controls the randomness of the output. A higher temperature increases diversity and creativity in responses, while a lower temperature makes the model more predictable and conservative. Setting temperature=0
essentially turns off randomness, leading the model to choose the most likely next word at each step. This is critical for achieving determinism as it minimizes variance in the model’s output.
The seed parameter is another tool to enhance determinism. It sets the initial state for the random number generator used in the model, ensuring that the same sequence of “random” numbers is used for each run. This parameter, when combined with temperature=0
, offers an even higher degree of predictability.
While the seed parameter is effective with the OpenAI instance in our library, it’s important to note that this functionality is not yet available for AzureOpenAI. Users working with AzureOpenAI can still use temperature=0
to reduce randomness but without the added predictability that seed offers.
As mentioned in the documentation (OpenAI Seed) :
Sometimes, determinism may be impacted due to necessary changes OpenAI makes to model configurations on our end. To help you keep track of these changes, we expose the system_fingerprint field. If this value is different, you may see different outputs due to changes we’ve made on our systems.
For AzureOpenAI Users: Rely on temperature=0
for reducing randomness. Stay tuned for future updates as we work towards integrating seed functionality with AzureOpenAI.
For OpenAI Users: Utilize both temperature=0
and seed for maximum determinism.