Serving LLM with Langchain and vLLM or OpenLLM – Langchain

by
Alexei Petrov
chromadb langchain openai-api

Quick Fix: Utilize FastAPI, a powerful and popular Python framework, to create a REST API. This framework offers many advantages, including an intuitive interface, strong documentation, and a large community of supporters. With FastAPI, you can easily set up endpoints and handle requests from the Langchain server, ensuring the smooth integration of your LLM application.

The Problem:

I want to build a Large Language Model (LLM) capable of understanding and responding to questions about Portable Document Format (PDF) files. The LLM should be accessible through an application programming interface (API) so that an external chatbot can interact with it. I am considering leveraging the capabilities of Langchain, vLLM, or OpenLLM to achieve this, but I’m facing challenges integrating these components and making the LLM available via an API. Can you provide guidance on how to proceed with this task?

The Solutions:

Solution 1: Serving LLM with Langchain and vLLM or OpenLLM

  1. Create a FastAPI application. This will allow you to easily create a REST API that can be accessed by your external chatbot.

  2. In your FastAPI application, define a route that will process PDF documents and return the results of the LLM query.

  3. In the route handler, load the PDF document using the PyPDFLoader.

  4. Split the PDF document into pages using the CharacterTextSplitter.

  5. Use the OpenAIEmbeddings class to generate embeddings for each page of the PDF document.

  6. Use the Chroma class to create a vector store from the embeddings.

  7. Initialize an OpenAI or vLLM LLM model.

  8. Create a VectorDBQA object using the LLM model and the vector store.

  9. Use the VectorDBQA object to run a query on the PDF document.

  10. Return the results of the query to the external chatbot.

By following these steps, you can create an LLM that can be used on PDFs and that can be accessed via an API.

Q&A

How can I make the LLM available via an API?

Create a FastAPI application to process PDF documents.

what’s needs to be installed for FastAPI application?

Install uvicorn using pip: pip install uvicorn.

How to run a FastAPI application?

Run the app using the command: uvicorn main:app –reload.

Video Explanation:

The following video, titled "LangChain + Falcon-40-B-Instruct, #1 Open LLM on RunPod with ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Discover how to run the best open Large Language Model (LLM) - Falcon-40B ... Go Production: ⚡️ Super FAST LLM (API) Serving with vLLM !!!