Skip to content
skyl

Text

A run of plain text.

Text is the simplest Part, and the one that appears in almost every message.

Reference#

type Text struct { Text string }

Caveats

  • Mapped on every adapter, on user and assistant messages.
  • On a tool role message it is rejected by the OpenAI-format adapters"tool messages may only contain tool results". Anthropic and Gemini turn it into user content instead.
  • Message.Text() and Response.Text() concatenate every Text part and ignore the others.
  • An empty Text is structurally valid; only a message with no parts at all is rejected.

Usage#

The usual way

goCompiles
skyl.UserText("Explain Go channels.")
skyl.UserText("Explain Go channels.")

Directly, when building mixed content

skyl.Message{
	Role: skyl.RoleUser,
	Parts: []skyl.Part{
		skyl.Text{Text: "Compare these two charts:"},
		skyl.Image{MediaType: "image/png", Data: before},
		skyl.Image{MediaType: "image/png", Data: after},
	},
}
skyl.Message{
	Role: skyl.RoleUser,
	Parts: []skyl.Part{
		skyl.Text{Text: "Compare these two charts:"},
		skyl.Image{MediaType: "image/png", Data: before},
		skyl.Image{MediaType: "image/png", Data: after},
	},
}

Troubleshooting#

ErrUnsupported on a tool message containing text

You put a Text part on a RoleTool message and are on OpenAI or openaicompat, which allow only tool results there. Put the prose in the ToolResult.Content instead — which is also where it is most useful, since that is what the model reads.

Edit this page on GitHub