3.1 KiB
Using Popular LLM libraries and APIs
Tags: LLM, CHATBOT, API
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
- MiniMax
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!)
$code_llm_llamaindex
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.
$code_llm_langchain
Tip: 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 directy. Here a similar example to the LangChain , but this time with streaming as well:
Tip: 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.
$code_llm_hf_transformers
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
$code_llm_sambanova
Tip: 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
$code_llm_hyperbolic
Tip: 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:
$code_llm_claude
MiniMax
The MiniMax API exposes the M-series models through an OpenAI-compatible endpoint, so the standard openai client works out of the box. Here's an example of how to build a Gradio app around MiniMax:
$code_llm_minimax