Skip to main content
In this guide, we go through several examples of how to use gr.ChatInterface with popular LLM libraries and API providers. We will cover the following libraries and API providers:
  • Llama Index
  • LangChain
  • OpenAI
  • Hugging Face transformers
  • SambaNova
  • Hyperbolic
  • Anthropic’s Claude
For many LLM libraries and providers, there exist community-maintained integration libraries that make it even easier to spin up Gradio apps. We reference these libraries in the appropriate sections below.

Llama Index

Let’s start by using llama-index on top of openai to build a RAG chatbot on any text or PDF files that you can demo and share in less than 30 lines of code. You’ll need to have an OpenAI key for this example (keep reading for the free, open-source equivalent!):

LangChain

Here’s an example using langchain on top of openai to build a general-purpose chatbot. As before, you’ll need to have an OpenAI key for this example:
For quick prototyping, the community-maintained langchain-gradio repo makes it even easier to build chatbots on top of LangChain.

OpenAI

Of course, we could also use the openai library directly. Here’s a similar example to the LangChain one, but this time with streaming as well:
For quick prototyping, the openai-gradio library makes it even easier to build chatbots on top of OpenAI models.

Hugging Face transformers

Of course, in many cases you want to run a chatbot locally. Here’s the equivalent example using the SmolLM2-135M-Instruct model using the Hugging Face transformers library:

SambaNova

The SambaNova Cloud API provides access to full-precision open-source models, such as the Llama family. Here’s an example of how to build a Gradio app around the SambaNova API:
For quick prototyping, the sambanova-gradio library makes it even easier to build chatbots on top of SambaNova models.

Hyperbolic

The Hyperbolic AI API provides access to many open-source models, such as the Llama family. Here’s an example of how to build a Gradio app around the Hyperbolic API:
For quick prototyping, the hyperbolic-gradio library makes it even easier to build chatbots on top of Hyperbolic models.

Anthropic’s Claude

Anthropic’s Claude model can also be used via API. Here’s a simple 20 questions-style game built on top of the Anthropic API:
These examples demonstrate how easy it is to integrate various LLM providers with Gradio’s ChatInterface. You can mix and match different providers and customize the chat function to suit your specific needs.