Does Langchain’s `create_csv_agent` and `create_pandas_dataframe_agent` functions work with non-OpenAl LLMs – Langchain

by
Maya Patel
langchain large-language-model llama-cpp-python openai-api python

Quick Fix: To use non-OpenAI LLMs with Langchain’s create_csv_agent and create_pandas_dataframe_agent functions, you can load models from the HuggingFace hub and then set the model in the agent accordingly.

The Problem:

Langchain provides create_csv_agent and create_pandas_dataframe_agent functions for integrating non-OpenAI LLMs with its platform. However, the documentation only showcases examples using OpenAI APIs. Determine if these functions can work with non-OpenAI LLM models like Llama2 and Vicuna and provide guidance on how to use them with these alternative models.

The Solutions:

Solution 1: Using HuggingFace Hub to Load Non-OpenAl LLMs and Integrate with Langchain’s Agents

To use non-OpenAl Large Language Models (LLMs) with Langchain’s `create_csv_agent` and `create_pandas_dataframe_agent` functions, follow these steps:

  1. Load the Non-OpenAl LLM from HuggingFace Hub:

    • Refer to this link for guidance on loading models from the HuggingFace Hub:
      HuggingFace Hub Integration
    • Obtain the repository ID (repo_id) of the desired non-OpenAl LLM model from the HuggingFace Hub.
  2. Create the HuggingFaceHub LLM Object:

    • Import the necessary modules and set the HUGGINGFACEHUB_API_TOKEN environment variable with your API token.
    • Instantiate the HuggingFaceHub class with the repo_id and any desired model configuration options, such as temperature and max length.
  3. Integrate the Non-OpenAl LLM with Langchain’s Agents:

    • Create a Langchain agent using the create_csv_agent or create_pandas_dataframe_agent function, specifying the HuggingFaceHub LLM object as the argument for the llm parameter.
    • Configure other optional parameters as needed, such as verbose, max_iterations, include_df_in_prompt, and so on.

By following these steps, you can seamlessly integrate non-OpenAl LLMs with Langchain’s agents to perform various natural language processing tasks using your preferred LLM model.

Q&A

Can Langchain’s CSV and Pandas agents use non-OpenAl models like Llama 2 and Vicuna?

Yes, you can use HuggingFace Hub to load these models and integrate them with Langchain agents.

How do I load a non-OpenAl model from HuggingFace Hub?

Refer to the Langchain documentation on HuggingFace Hub integration for instructions.

How do I use a loaded model with Langchain’s CSV or Pandas agents?

Once you have loaded the model, you can pass it as an argument when creating the agent.

Video Explanation:

The following video, titled "”LangChain", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

”Colab

(https://drp.li/m1mbM) Load HuggingFace models locally so that you can use models you can’t use …”]