Highlights
Support message format in chatbot 💬 (#8422 4221290
)
gr.Chatbot
and gr.ChatInterface
now support the Messages API, which is fully compatible with LLM API providers such as Hugging Face Text Generation Inference, OpenAI's chat completions API, and Llama.cpp server.
Building Gradio applications around these LLM solutions is now even easier!
gr.Chatbot
and gr.ChatInterface
now have a type
parameter that can accept two values - 'tuples'
and 'messages'
. If set to 'tuples'
, the default chatbot data format is expected. If set to 'messages'
, a list of dictionaries with content
and role
keys is expected. See below -
def chat_greeter(msg, history):
history.append({"role": "assistant", "content": "Hello!"})
return history
Additionally, gradio now exposes a gr.ChatMessage
dataclass you can use for IDE type hints and auto completion.
Tool use in Chatbot 🛠️
The Gradio Chatbot can now natively display tool usage and intermediate thoughts common in Agent and chain-of-thought workflows!
If you are using the new "messages" format, simply add a metadata
key with a dictionary containing a title
key and value
. This will display the assistant message in an expandable message box to show the result of a tool or intermediate step.
import gradio as gr
from gradio import ChatMessage
import time
def generate_response(history):
history.append(ChatMessage(role="user", content="What is the weather in San Francisco right now?"))
yield history
time.sleep(0.25)
history.append(ChatMessage(role="assistant",
content="In order to find the current weather in San Francisco, I will need to use my weather tool.")
)
yield history
time.sleep(0.25)
history.append(ChatMessage(role="assistant",
content="API Error when connecting to weather service.",
metadata={"title": "💥 Error using tool 'Weather'"})
)
yield history
time.sleep(0.25)
history.append(ChatMessage(role="assistant",
content="I will try again",
))
yield history
time.sleep(0.25)
history.append(ChatMessage(role="assistant",
content="Weather 72 degrees Fahrenheit with 20% chance of rain.",
metadata={"title": "🛠️ Used tool 'Weather'"}
))
yield history
time.sleep(0.25)
history.append(ChatMessage(role="assistant",
content="Now that the API succeeded I can complete my task.",
))
yield history
time.sleep(0.25)
history.append(ChatMessage(role="assistant",
content="It's a sunny day in San Francisco with a current temperature of 72 degrees Fahrenheit and a 20% chance of rain. Enjoy the weather!",
))
yield history
with gr.Blocks() as demo:
chatbot = gr.Chatbot(type="messages")
button = gr.Button("Get San Francisco Weather")
button.click(generate_response, chatbot, chatbot)
if __name__ == "__main__":
demo.launch()
Thanks @freddyaboulton!
Features
- #8683
a92c3e8
- Warn against Falsy credentials. Thanks @Paillat-dev! - #8743
ee497d5
- Perform CORS validation when the request has a cookie. Thanks @abidlabs! - #8744
b736c8d
- Refactorgr.ParamViewer
to use HTML<details>
and other tweaks. Thanks @abidlabs! - #8665
3b8238c
- Add c/cpp code support. Thanks @ginazhouhuiwu! - #8713
e3c7079
- Time range component. Thanks @aliabid94! - #8705
280a3f4
- GRADIO_ALLOWED_PATHS & GRADIO_BLOCKED_PATHS comma separated environme…. Thanks @cocktailpeanut! - #8733
fb0daf3
- Improvements togr.Examples
: adds events as attributes and documents, them, addssample_labels
, andvisible
properties. Thanks @abidlabs! - #8750
5e36144
- Add guides for msg format and llm agents. Thanks @freddyaboulton! - #8687
bc1d45d
- Model3D point cloud and wireframe display modes. Thanks @dawoodkhan82!
Fixes
- #8699
012da05
- Ensure JS clientstatus_callback
functionality works and improve status messages. Thanks @hannahblair! - #8763
c1ecfde
- 8394 df hidden items. Thanks @pngwn! - #8505
2943d6d
- Add Timer component. Thanks @aliabid94! - #8715
a6b3c6c
- Ensure@gradio/client
'ssubmit
iterator releases as expected. Thanks @pngwn! - #8758
26cdd0f
- Revert chatbot styling. Thanks @pngwn! - #8658
0482453
- Chatbot LaTeX Crash Fix. Thanks @dawoodkhan82! - #8716
e834d30
- ensure@gradio/client
always returns the correct data. Thanks @pngwn! - #8737
31a876d
- FixShare to community
button for images. Thanks @hannahblair! - #8719
d15ada9
- Fix multimodal textbox custom components. Thanks @freddyaboulton! - #8714
1b5b5b0
- Bindfetch
andstream
in JS client. Thanks @hannahblair! - #8677
c946c6f
- Allow supplying customgr.Chatbot
with events togr.ChatInterface
. Thanks @abidlabs! - #8748
a9307c6
- Chatbot generating scroll and click fix. Thanks @freddyaboulton! - #8720
936c713
- Documents auth in the guides, in the view API page, and also types the Blocks.config object. Thanks @abidlabs!