Build an agent with Gradio
Build and deploy smart AI agents with Friendli Serverless Endpoints and Gradio in under 50 lines.
Goals
- Build your own AI agent using Friendli Serverless Endpoints and Gradio less than 50 LoC 🤖
- Use tool calling to make your agent even smarter 🤩
- Share your AI agent with the world and gather feedback 🌎
Gradio is the fastest way to demo your model with a friendly web interface.
Getting Started
- Head to https://suite.friendli.ai, and create an account.
- Grab a FRIENDLI_TOKEN to use Friendli Serverless Endpoints within an agent.
🚀 Step 1. Prerequisite
Install dependencies.
🚀 Step 2. Launch your agent
Build your own AI agent using Friendli Serverless Endpoints and Gradio.
- Gradio provides a
ChatInterface
that implements a chatbot UI running thechat_function
.- More information about the chat_function(message, history)
The input function should accept two parameters: a string input message and list of two-element lists of the form [[user_message, bot_message], …] representing the chat history, and return a string response.
- More information about the chat_function(message, history)
- Implement the
chat_function
using Friendli Serverless Endpoints.- Here, we used the
meta-llama-3.1-70b-instruct
model. - Feel free to explore other available models here.
- Here, we used the
🚀 Step 3. Tool Calling (Advanced)
Use tool calling to make your agent even smarter! We will show you how to make your agent search the web before answer as an example.
- Change the
base_url
tohttps://inference.friendli.ai/serverless/tools/v1
- Add
tools
parameter when calling chat completion API
Here is the available built-in tools (beta) list. Feel free to build your agent using the below tools.
math:calculator
(tool for calculating arithmetic operations)math:statistics
(tool for analyzing statistic data)math:calendar
(tool for handling date-related data)web:search
(tool for retrieving data through the web search)web:url
(tool for extracting data from a given website)code:python-interpreter
(tool for writing and executing python code)file:text
(tool for extracting text data from a given file)
🚀 Step 4. Deploy your agent
For the temporal deployment, change the last line of the code.
For the permanent deployment, you can use HuggingFace Space !
Was this page helpful?