Large Language Models
PandasAI supports several large language models (LLMs) that are used to generate code from natural language queries.
The generated code is then executed to produce the result.
You can either choose a LLM by instantiating one and passing it to the SmartDataFrame
or SmartDatalake
constructor,
or you can specify one in the pandasai.json
file.
If the model expects one or more parameters, you can pass them to the constructor or specify them in the pandasai.json
file, in the llm_options
param, as it follows:
BambooLLM
BambooLLM is the state-of-the-art language model developed by PandasAI with data analysis in mind. It is designed to understand and execute natural language queries related to data analysis, data manipulation, and data visualization. You can get your free API key signing up at https://pandabi.ai
As an alternative, you can set the PANDASAI_API_KEY
environment variable and instantiate the BambooLLM
object
without passing the API key:
OpenAI models
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:
As an alternative, you can set the OPENAI_API_KEY
environment variable and instantiate the OpenAI
object without
passing the API key:
If you are behind an explicit proxy, you can specify openai_proxy
when instantiating the OpenAI
object or set
the OPENAI_PROXY
environment variable to pass through.
Count tokens
You can count the number of tokens used by a prompt as follows:
Google PaLM
In order to use Google PaLM models, you need to have a Google Cloud API key. You can get one here.
Once you have an API key, you can use it to instantiate a Google PaLM object:
Google Vertexai
In order to use Google PaLM models through Vertexai api, you need to have
- Google Cloud Project
- Region of Project Set up
- Install optional dependency
google-cloud-aiplatform
- Authentication of
gcloud
Once you have basic setup, you can use it to instantiate a Google PaLM through vertex ai:
Azure OpenAI
In order to use Azure OpenAI models, you need to have an Azure OpenAI API key as well as an Azure OpenAI endpoint. You can get one here.
To instantiate an Azure OpenAI object you also need to specify the name of your deployed model on Azure and the API version:
As an alternative, you can set the AZURE_OPENAI_API_KEY
, OPENAI_API_VERSION
, and AZURE_OPENAI_ENDPOINT
environment
variables and instantiate the Azure OpenAI object without passing them:
If you are behind an explicit proxy, you can specify openai_proxy
when instantiating the AzureOpenAI
object or set
the OPENAI_PROXY
environment variable to pass through.
HuggingFace via Text Generation
In order to use HuggingFace models via text-generation, you need to first serve a supported large language model (LLM). Read text-generation docs for more on how to setup an inference server.
This can be used, for example, to use models like LLaMa2, CodeLLaMa, etc. You can find more information about text-generation here.
The inference_server_url
is the only required parameter to instantiate an HuggingFaceTextGen
model:
LangChain models
PandasAI has also built-in support for LangChain models.
In order to use LangChain models, you need to install the langchain
package:
Once you have installed the langchain
package, you can use it to instantiate a LangChain object:
PandasAI will automatically detect that you are using a LangChain LLM and will convert it to a PandasAI LLM.
Amazon Bedrock models
In order to use Amazon Bedrock models, you need to have an AWS AKSK and gain the model access.
Currently, only Claude 3 Sonnet is supported.
In order to use Bedrock models, you need to install the bedrock
package.
Then you can use the Bedrock models as follows
More ways to create the bedrock_runtime_client can be found here.
More information
For more information about LangChain models, please refer to the LangChain documentation.
IBM watsonx.ai models
In order to use IBM watsonx.ai models, you need to have
- IBM Cloud api key
- Watson Studio project in IBM Cloud
- The service URL associated with the project’s region
The api key can be created in IBM Cloud.
The project ID can determined after a Watson Studio service
is provisioned in IBM Cloud. The ID can
then be found in the
project’s Manage tab (Project -> Manage -> General -> Details
). The service url depends on the region of the
provisioned service instance and can be
found here.
In order to use watsonx.ai models, you need to install the ibm-watsonx-ai
package.
At this time, watsonx.ai does not support the PandasAI agent.
Then you can use the watsonx.ai models as follows
More information
For more information on the watsonx.ai SDK you can read more here.
Local models
PandasAI supports local models, though smaller models typically don’t perform as well. To use local models, first host one on a local inference server that adheres to the OpenAI API. This has been tested to work with Ollama and LM Studio.
Ollama
Ollama’s compatibility is experimental (see docs).
With an Ollama server, you can instantiate an LLM object by specifying the model name:
LM Studio
An LM Studio server only hosts one model, so you can instantiate an LLM object without specifying the model name:
Was this page helpful?