Documentation
¶
Overview ¶
Package prompt provides message conversion utilities. This mirrors the ai-sdk prompt module. Source: ai-sdk/packages/ai/src/prompt/convert-to-language-model-prompt.ts
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConvertOptions ¶
type ConvertOptions struct {
// Prompt is the standardized prompt to convert.
Prompt StandardizedPrompt
// SupportedURLs maps media types to patterns of supported URLs.
SupportedURLs SupportedURLs
// Download is the function to download assets.
// If nil, defaults to DefaultDownload.
Download DownloadFunc
}
ConvertOptions are options for ConvertToLanguageModelPrompt.
type DownloadFunc ¶
type DownloadFunc func(ctx context.Context, plans []DownloadPlan) []*DownloadedAsset
DownloadFunc is a function that downloads files. It returns nil for entries that couldn't be downloaded.
type DownloadPlan ¶
DownloadPlan represents a planned download.
type DownloadedAsset ¶
DownloadedAsset represents a downloaded file/image.
func DefaultDownload ¶
func DefaultDownload(ctx context.Context, plans []DownloadPlan) []*DownloadedAsset
DefaultDownload is the default download function.
type LanguageModelMessage ¶
type LanguageModelMessage struct {
Role string
Content any // string or []LanguageModelPart
ProviderOptions map[string]any
}
LanguageModelMessage is a message in language model format. This is the format providers expect.
func ConvertToLanguageModelPrompt ¶
func ConvertToLanguageModelPrompt(ctx context.Context, opts ConvertOptions) ([]LanguageModelMessage, error)
ConvertToLanguageModelPrompt converts a standardized prompt to language model format. This handles: - Downloading images/files from URLs when the model doesn't support them - Combining consecutive tool messages - Validating all tool calls have matching results
type LanguageModelPart ¶
type LanguageModelPart struct {
Type string
// For text parts
Text string
// For file parts
Data any // []byte | string (base64) | *url.URL
MediaType string
Filename string
// For tool-call parts
ToolCallID string
ToolName string
Input any
ProviderExecuted bool
// For tool-result parts
// ToolCallID and ToolName are reused
Output any
// For tool-approval-response parts
ApprovalID string
Approved bool
Reason string
// Provider options
ProviderOptions map[string]any
}
LanguageModelPart is a part of a language model message.
type StandardizedPrompt ¶
type StandardizedPrompt struct {
// System is the system message(s).
System any // string | SystemMessage | []SystemMessage
// Messages are the conversation messages.
Messages []message.Message
}
StandardizedPrompt represents a validated and standardized prompt. Source: ai-sdk/packages/ai/src/prompt/standardize-prompt.ts
type SupportedURLs ¶
SupportedURLs maps media types to patterns of supported URLs. Use "*" as key for all media types.
type SystemMessage ¶
SystemMessage represents a system message with provider options.