Implementation:Hiyouga LLaMA Factory WebUI Chatbot
| Knowledge Sources | |
|---|---|
| Domains | WebUI, Chat, Gradio Components |
| Last Updated | 2026-02-06 19:00 GMT |
Overview
Gradio chatbot UI component that provides an interactive chat interface with multimodal support for the LLaMA Factory WebUI.
Description
The chatbot.py module defines the chat box component used within both the Inference tab and the standalone Web Demo mode. It creates a Gradio chatbot display with message state management, a role selector (user or observation), system prompt input, tools JSON schema input, multimodal upload tabs (image, video, audio), and generation parameter sliders (max_new_tokens, top_p, temperature). The module also includes a check_json_schema helper that validates tool definitions entered by the user. Submit and clear button events are wired to the engine's chatter for streaming responses.
Usage
Use this component when building a chat interface within the WebUI. It is called by create_infer_tab in the inference component and by create_web_demo in the interface module to embed an interactive chat box.
Code Reference
Source Location
- Repository: Hiyouga_LLaMA_Factory
- File: src/llamafactory/webui/components/chatbot.py
- Lines: 1-143
Signature
def check_json_schema(text: str, lang: str) -> None: ...
def create_chat_box(
engine: "Engine", visible: bool = False
) -> tuple["Component", "Component", dict[str, "Component"]]: ...
Import
from llamafactory.webui.components.chatbot import check_json_schema, create_chat_box
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| engine | Engine | Yes | The WebUI engine instance providing access to the Manager and WebChatModel |
| visible | bool | No | Whether the chat box is initially visible (default: False) |
Outputs
| Name | Type | Description |
|---|---|---|
| chatbot | gr.Chatbot | The Gradio chatbot display component (type="messages") |
| messages | gr.State | Stateful list holding the conversation message history |
| elem_dict | dict[str, Component] | Dictionary of all named sub-components (chat_box, role, system, tools, mm_box, image, video, audio, query, submit_btn, max_new_tokens, top_p, temperature, skip_special_tokens, escape_html, enable_thinking, clear_btn) |
Usage Examples
# Embedding a chat box in the inference tab
from llamafactory.webui.components.chatbot import create_chat_box
chatbot, messages, chat_elems = create_chat_box(engine, visible=False)
elem_dict.update(chat_elems)
# Validating tool JSON schema input
from llamafactory.webui.components.chatbot import check_json_schema
check_json_schema('[{"name": "search", "description": "Search the web"}]', "en")
Related Pages
- Hiyouga_LLaMA_Factory_WebUI_Infer_Component - Inference tab that embeds this chat box
- Hiyouga_LLaMA_Factory_WebUI_Interface - Interface module that uses create_chat_box for web demo mode
- Hiyouga_LLaMA_Factory_WebUI_Engine - Engine class providing the chatter and manager instances