Help us shape the future of Go! Take the 2026 Go Developer Survey

prompt

package
v0.7.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 4 Imported by: 85

Documentation

Overview

Package prompt defines callback payloads for prompt components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImplSpecificOptions

func GetImplSpecificOptions[T any](base *T, opts ...Option) *T

GetImplSpecificOptions extracts the implementation specific options from Option list, optionally providing a base options with default values.

Types

type CallbackInput

type CallbackInput struct {
	// Variables is the variables for the callback.
	Variables map[string]any
	// Templates is the templates for the callback.
	Templates []schema.MessagesTemplate
	// Extra is the extra information for the callback.
	Extra map[string]any
}

CallbackInput is the input for the callback.

func ConvCallbackInput

func ConvCallbackInput(src callbacks.CallbackInput) *CallbackInput

ConvCallbackInput converts the callback input to the prompt callback input.

type CallbackOutput

type CallbackOutput struct {
	// Result is the result for the callback.
	Result []*schema.Message
	// Templates is the templates for the callback.
	Templates []schema.MessagesTemplate
	// Extra is the extra information for the callback.
	Extra map[string]any
}

CallbackOutput is the output for the callback.

func ConvCallbackOutput

func ConvCallbackOutput(src callbacks.CallbackOutput) *CallbackOutput

ConvCallbackOutput converts the callback output to the prompt callback output.

type ChatTemplate

type ChatTemplate interface {
	Format(ctx context.Context, vs map[string]any, opts ...Option) ([]*schema.Message, error)
}

ChatTemplate formats variables into a list of messages according to a prompt schema.

type DefaultChatTemplate

type DefaultChatTemplate struct {
	// contains filtered or unexported fields
}

DefaultChatTemplate is the default chat template implementation.

func FromMessages

func FromMessages(formatType schema.FormatType, templates ...schema.MessagesTemplate) *DefaultChatTemplate

FromMessages creates a new DefaultChatTemplate from the given templates and format type. eg.

template := prompt.FromMessages(schema.FString, &schema.Message{Content: "Hello, {name}!"}, &schema.Message{Content: "how are you?"})
// in chain, or graph
chain := compose.NewChain[map[string]any, []*schema.Message]()
chain.AppendChatTemplate(template)

func (*DefaultChatTemplate) Format

func (t *DefaultChatTemplate) Format(ctx context.Context,
	vs map[string]any, _ ...Option) (result []*schema.Message, err error)

Format formats the chat template with the given context and variables.

func (*DefaultChatTemplate) GetType

func (t *DefaultChatTemplate) GetType() string

GetType returns the type of the chat template (Default).

func (*DefaultChatTemplate) IsCallbacksEnabled

func (t *DefaultChatTemplate) IsCallbacksEnabled() bool

IsCallbacksEnabled checks if the callbacks are enabled for the chat template.

type Option

type Option struct {
	// contains filtered or unexported fields
}

Option is the call option for ChatTemplate component.

func WrapImplSpecificOptFn

func WrapImplSpecificOptFn[T any](optFn func(*T)) Option

WrapImplSpecificOptFn wraps the implementation specific option function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL