
Langchain is an Artificial Intelligence (AI) framework that simplifies coding when creating apps that implement external data sources and Large Language Models(LLMs).
You can use the framework to create personal assistants, chatbots, Q&A applications, and more. Langchain ships with different libraries that allow you to interact with various data sources like PDFs, spreadsheets, and databases (For instance, Chroma, Pinecone, Milvus, and Weaviate).
Chroma is an open-source embedding database that accelerates building LLM apps that require storing vector data and performing semantic searches.
In this guide, you'll implement the Langchain framework to orchestrate LLMs with a Chroma database.
Before you begin:
Deploy a new Ubuntu 22.04 A100 Vultr Cloud GPU Server with at least:
Create a non-root user with sudo rights and switch to the account.
You need to install the following Python libraries. Later on this guide, you'll run some Python scripts that use the libraries to work:
This guide requires Llama 2 model API. You'll expose the API by running the Hugging Face text generation inference Docker container. Follow the steps below:
Initialize the Docker container variables. Replace $HF_TOKEN with your correct Hugging Face token.
Run the Hugging Face text generation Docker container.
Wait for the container to download and load. Then, check the logs to ensure the container listens for incoming connections.
Ensure you get the following output.
Follow the steps below to create a sample Langchain application to generate a query based on a prompt:
Create a new langchain-llama.py file using a text editor like nano.
Enter the following information into the langchain-llama.py file.
Save and close the file.
Run the file.
Output:
The Langchain framework accepts LLM prompts. Incorporate the prompt in your Python code by following the steps below:
Open a new langchain-llama-prompt.py file.
Enter the following information into the langchain-llama-prompt.py file.
Save and close the file.
Run the file
Output:
In this step, you'll use a sample speech from Steve Jobs and integrate Langchain with a Chroma database. Follow the steps below:
Download the sample PDF file using the Linux wget command:
Open a new langchain_chroma.py file.
Enter the following information into the langchain_chroma.py file.
Save and close the file.
Run the file.
Output:
Langchain has a built-in library for creating professional-looking user interfaces for chats. Follow the steps below to create a Web interface for your application:
Create a new chatbot.py file.
Enter the following information into the chatbot.py file.
Save and close the file.
Run the file.
Output:
Access the web interface by navigating to the public URL mentioned in the output.
In this guide, you have implemented the Langchain framework to orchestrate LLMs with the Chroma vector database. You've also created a chatbot using Chroma that exposes the functionalities of the Llama 2 model in a web interface.
0 Comments
Be the first to comment and share your perspective with the community.