Skip to content

Bubble 对话气泡 ​

AI 对话组件。公开入口:Bubble。

在线演示 ​

本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。

Bubble 对话气泡 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

Bubble 对话气泡

gallery 演示 Bubble 的具名 Render 函数,源码 page_chat.go#L27。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.Bubble ​

go
func Bubble(c *Context, role ChatRole, content string) *BubbleW

Bubble adds a chat message of role with content (Markdown for the assistant, plain text for the user; see Markdown/Plain).

ui.Bubble(c, ui.ChatAssistant, reply).Typing(streaming).Actions(ui.BubbleCopy | ui.BubbleRetry)

返回 *BubbleW,可链式调用的方法见 BubbleW 方法。

BubbleW 方法 ​

ui.BubbleW:BubbleW is one chat message: avatar, optional name, content and actions.

方法说明签名
ActionsActions shows the built-in action buttons under the bubble.Actions(a BubbleAction) *BubbleW
ActionsAlwaysActionsAlways keeps the action buttons visible (the last answer).ActionsAlways() *BubbleW
AvatarAvatar replaces the default avatar with custom content.Avatar(fn func()) *BubbleW
AvatarIconAvatarIcon sets the icon of the default avatar.AvatarIcon(ic *icon.Icon) *BubbleW
AvatarTextAvatarText shows initials in the default avatar.AvatarText(s string) *BubbleW
ClickedLinkClickedLink returns the URL of a Markdown link clicked this frame.ClickedLink() string
CopiedCopied reports that the copy action put the content on the clipboard this frame.Copied() bool
EditedEdited returns the new text when an in-place edit was saved this frame.Edited() (string, bool)
EditingEditing reports whether the in-place editor is open.Editing() bool
ExtraExtra adds content under the bubble (tool cards, thought chains, attachments, custom actions).Extra(fn func()) *BubbleW
IDID returns the message row's ID.ID() ID
LayoutLayout applies layout options to the message row.Layout(opts ...layout.Option) *BubbleW
LoadingLoading shows animated dots while the content is still empty.Loading(on bool) *BubbleW
MarkdownMarkdown renders the content as Markdown (default for the assistant).Markdown() *BubbleW
MetaMeta shows a footer text after the actions (time, model, tokens).Meta(s string) *BubbleW
NameName shows the author's name above the bubble (also its accessible name).Name(s string) *BubbleW
NoAvatarNoAvatar hides the avatar column.NoAvatar() *BubbleW
PlainPlain renders the content as plain text keeping line breaks (default for the user and system).Plain() *BubbleW
RetriedRetried reports a click on the retry action.Retried() bool
TypingTyping marks the content as still streaming: it is revealed at TypingSpeed (catching up quickly when far behind) with a caret at the end.Typing(on bool) *BubbleW
TypingSpeedTypingSpeed sets the reveal speed in characters per second (default 60).TypingSpeed(cps float32) *BubbleW
VariantVariant sets the look (default BubbleAuto).Variant(v BubbleVariant) *BubbleW

相关链接 ​

本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。

以 MIT 许可发布