提示
阅读构建一个基本的LLM聊天应用教程,学习如何使用st.chat_message和st.chat_input来构建基于聊天的应用。
| 函数签名[source] | |
|---|---|
st.chat_message(name, *, avatar=None) | |
| 参数 | |
name ("user", "assistant", "ai", "human", or str) | 消息作者的名字。可以是"human"/"user"或"ai"/"assistant",以启用预设的样式和头像。 目前,名字不会在用户界面中显示,但会设置为无障碍标签。出于无障碍考虑,不应使用空字符串。 |
avatar (Anything supported by st.image (except list), str, or None) | The avatar shown next to the message. If avatar is None (default), the icon will be determined from name as follows:
In addition to the types supported by st.image (except list), the following strings are valid:
|
| 返回 | |
(Container) | 一个可以容纳多个元素的单一容器。 |
示例
你可以使用with符号将任何元素插入到扩展器中
import streamlit as st import numpy as np with st.chat_message("user"): st.write("Hello 👋") st.line_chart(np.random.randn(30, 3))或者你可以直接在返回的对象中调用方法:
import streamlit as st import numpy as np message = st.chat_message("assistant") message.write("Hello human") message.bar_chart(np.random.randn(30, 3))
有关st.chat_message和st.chat_input API的概述,请查看Streamlit的高级开发者倡导者Chanin Nantasenamat(@dataprofessor)提供的视频教程。
还有问题吗?
我们的 论坛 充满了有用的信息和Streamlit专家。