prompt

package
v0.9.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 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 AgenticCallbackInput added in v0.9.0

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

AgenticCallbackInput is the input for the callback.

func ConvAgenticCallbackInput added in v0.9.0

func ConvAgenticCallbackInput(src callbacks.CallbackInput) *AgenticCallbackInput

ConvAgenticCallbackInput converts the callback input to the agentic prompt callback input.

type AgenticCallbackOutput added in v0.9.0

type AgenticCallbackOutput struct {
	// Result is the agentic result for the callback.
	Result []*schema.AgenticMessage
	// Templates is the agentic templates for the callback.
	Templates []schema.AgenticMessagesTemplate
	// Extra is the extra information for the callback.
	Extra map[string]any
}

AgenticCallbackOutput is the output for the callback.

func ConvAgenticCallbackOutput added in v0.9.0

func ConvAgenticCallbackOutput(src callbacks.CallbackOutput) *AgenticCallbackOutput

ConvAgenticCallbackOutput converts the callback output to the agentic prompt callback output.

type AgenticChatTemplate added in v0.9.0

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

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

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 DefaultAgenticChatTemplate added in v0.9.0

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

func FromAgenticMessages added in v0.9.0

func FromAgenticMessages(formatType schema.FormatType, templates ...schema.AgenticMessagesTemplate) *DefaultAgenticChatTemplate

FromAgenticMessages creates a new DefaultAgenticChatTemplate from the given templates and format type. eg.

template := prompt.FromAgenticMessages(schema.FString, &schema.AgenticMessage{})
// in chain, or graph
chain := compose.NewChain[map[string]any, []*schema.AgenticMessage]()
chain.AppendAgenticChatTemplate(template)

func (*DefaultAgenticChatTemplate) Format added in v0.9.0

func (t *DefaultAgenticChatTemplate) Format(ctx context.Context, vs map[string]any, opts ...Option) (result []*schema.AgenticMessage, err error)

func (*DefaultAgenticChatTemplate) GetType added in v0.9.0

func (t *DefaultAgenticChatTemplate) GetType() string

GetType returns the type of the agentic template (DefaultAgentic).

func (*DefaultAgenticChatTemplate) IsCallbacksEnabled added in v0.9.0

func (t *DefaultAgenticChatTemplate) IsCallbacksEnabled() bool

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

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