Documentation ¶
Overview ¶
Package prompt provides utilities for managing and optimizing prompts.
Index ¶
- Variables
- func ListTemplateFields(t *template.Template) []string
- type AIMessageTemplate
- type ChatPromptValue
- type ChatTemplate
- type Formatter
- type HumanMessageTemplate
- type MessageTemplate
- type PartialValues
- type StringPromptValue
- type SystemMessageTemplate
- type Template
- func (p *Template) Format(values map[string]any) (string, error)
- func (p *Template) FormatPrompt(values map[string]any) (schema.PromptValue, error)
- func (p *Template) InputVariables() []string
- func (p *Template) OutputParser() (schema.OutputParser[any], bool)
- func (p *Template) Partial(values PartialValues) *Template
- type TemplateOptions
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidPartialVariableType = errors.New("invalid partial variable type")
)
Functions ¶
func ListTemplateFields ¶
Types ¶
type AIMessageTemplate ¶ added in v0.0.26
type AIMessageTemplate struct {
// contains filtered or unexported fields
}
AIMessageTemplate represents an AI message template.
func NewAIMessageTemplate ¶ added in v0.0.26
func NewAIMessageTemplate(template string) *AIMessageTemplate
NewAIMessageTemplate creates a new AIMessageTemplate with the given template.
func (*AIMessageTemplate) Format ¶ added in v0.0.26
func (pt *AIMessageTemplate) Format(values map[string]any) (schema.ChatMessage, error)
Format formats the message using the provided values and returns an AIChatMessage.
func (*AIMessageTemplate) FormatPrompt ¶ added in v0.0.42
func (mt *AIMessageTemplate) FormatPrompt(values map[string]any) (*ChatPromptValue, error)
type ChatPromptValue ¶
type ChatPromptValue struct {
// contains filtered or unexported fields
}
ChatPromptValue represents a chat prompt value containing chat messages.
func NewChatPromptValue ¶ added in v0.0.29
func NewChatPromptValue(messages schema.ChatMessages) *ChatPromptValue
NewChatPromptValue creates a new ChatPromptValue with the given chat messages.
func (ChatPromptValue) Messages ¶ added in v0.0.29
func (v ChatPromptValue) Messages() schema.ChatMessages
Messages returns the chat messages contained in the ChatPromptValue.
func (ChatPromptValue) String ¶ added in v0.0.29
func (v ChatPromptValue) String() string
String returns a string representation of the ChatPromptValue.
type ChatTemplate ¶
type ChatTemplate interface { FormatPrompt(values map[string]any) (*ChatPromptValue, error) Format(values map[string]any) (schema.ChatMessages, error) }
ChatTemplate represents a chat template.
func NewChatTemplate ¶ added in v0.0.29
func NewChatTemplate(messageTemplates []MessageTemplate) ChatTemplate
NewChatTemplate creates a new ChatTemplate with the given message templates.
func NewChatTemplateWrapper ¶ added in v0.0.29
func NewChatTemplateWrapper(chatTemplates ...ChatTemplate) ChatTemplate
NewChatTemplateWrapper creates a new ChatTemplate that wraps multiple ChatTemplates.
func NewMessagesPlaceholder ¶ added in v0.0.29
func NewMessagesPlaceholder(inputKey string) ChatTemplate
NewMessagesPlaceholder creates a new ChatTemplate placeholder for chat messages.
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
func NewFormatter ¶
type HumanMessageTemplate ¶
type HumanMessageTemplate struct {
// contains filtered or unexported fields
}
HumanMessageTemplate represents a human message template.
func NewHumanMessageTemplate ¶ added in v0.0.26
func NewHumanMessageTemplate(template string) *HumanMessageTemplate
NewHumanMessageTemplate creates a new HumanMessageTemplate with the given template.
func (*HumanMessageTemplate) Format ¶
func (pt *HumanMessageTemplate) Format(values map[string]any) (schema.ChatMessage, error)
Format formats the message using the provided values and returns a HumanChatMessage.
func (*HumanMessageTemplate) FormatPrompt ¶ added in v0.0.42
func (mt *HumanMessageTemplate) FormatPrompt(values map[string]any) (*ChatPromptValue, error)
type MessageTemplate ¶ added in v0.0.29
type MessageTemplate interface { Format(values map[string]any) (schema.ChatMessage, error) FormatPrompt(values map[string]any) (*ChatPromptValue, error) }
MessageTemplate represents a chat message template.
type PartialValues ¶
type StringPromptValue ¶
type StringPromptValue string
func (StringPromptValue) Messages ¶
func (v StringPromptValue) Messages() schema.ChatMessages
func (StringPromptValue) String ¶
func (v StringPromptValue) String() string
type SystemMessageTemplate ¶
type SystemMessageTemplate struct {
// contains filtered or unexported fields
}
SystemMessageTemplate represents a system message template.
func NewSystemMessageTemplate ¶
func NewSystemMessageTemplate(template string) *SystemMessageTemplate
NewSystemMessageTemplate creates a new SystemMessageTemplate with the given template.
func (*SystemMessageTemplate) Format ¶
func (pt *SystemMessageTemplate) Format(values map[string]any) (schema.ChatMessage, error)
Format formats the message using the provided values and returns a SystemChatMessage.
func (*SystemMessageTemplate) FormatPrompt ¶ added in v0.0.42
func (mt *SystemMessageTemplate) FormatPrompt(values map[string]any) (*ChatPromptValue, error)
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
func NewTemplate ¶
func NewTemplate(template string, optFns ...func(o *TemplateOptions)) *Template
func (*Template) FormatPrompt ¶
func (*Template) InputVariables ¶ added in v0.0.2
func (*Template) OutputParser ¶ added in v0.0.3
func (p *Template) OutputParser() (schema.OutputParser[any], bool)
func (*Template) Partial ¶
func (p *Template) Partial(values PartialValues) *Template
type TemplateOptions ¶
type TemplateOptions struct { PartialValues PartialValues Language string OutputParser schema.OutputParser[any] TransformPythonTemplate bool }