Chat Message
ChatMessage draws one message of a chat, and returns the container its content goes in. Any component can go in it.
API
Interface
func ChatMessage(c *tgframe.Container, role string, conf ...*ChatMessageConf) *tgframe.Container
Parameters
c: Parent container.role: Who sent the message."user"and"human"are drawn as the user,"assistant"and"ai"as the assistant, each with an icon of its own. Any other role is drawn by its first letter.conf: Optional configuration, at most one.
// ChatMessageConf is the configuration for the ChatMessage component.
type ChatMessageConf struct {
tgframe.Base // ID
// Avatar is an emoji, or an image URL: http, https, data:image or a path
// starting with / or ./. Default is an icon for the user and the
// assistant, and the role's first letter for any other role.
Avatar string
}
Example
tgcomp.Markdown(tgcomp.ChatMessage(p.Main, "user"), "What can ChatMessage hold?")
reply := tgcomp.ChatMessage(p.Main, "assistant")
tgcomp.Markdown(reply, "Any component, for example a **metric**:")
tgcomp.Metric(reply, "Tokens", "1,024")
tgcomp.Text(tgcomp.ChatMessage(p.Main, "tool",
&tgcomp.ChatMessageConf{Avatar: "🔧"}), "search(\"toolgui\") -> 3 results")
A reply streamed with WriteStream:
if tgcomp.Button(p.Main, "Ask") {
tgcomp.Text(tgcomp.ChatMessage(p.Main, "user"), "Tell me about WriteStream.")
reply := tgcomp.ChatMessage(p.Main, "assistant")
if _, err := tgcomp.WriteStream(reply, fakeReply(p.Context)); err != nil {
return err
}
}