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 FewShotTemplate
- func (p *FewShotTemplate) Format(values map[string]any) (string, error)
- func (p *FewShotTemplate) FormatPrompt(values map[string]any) (schema.PromptValue, error)
- func (p *FewShotTemplate) InputVariables() []string
- func (p *FewShotTemplate) OutputParser() (schema.OutputParser[any], bool)
- func (p *FewShotTemplate) Partial(values map[string]any) schema.PromptTemplate
- type FewShotTemplateOptions
- type Formatter
- type FormatterOptions
- type HumanMessageTemplate
- type MessageTemplate
- 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 map[string]any) schema.PromptTemplate
- 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)
func (*AIMessageTemplate) InputVariables ¶ added in v0.0.59
func (pt *AIMessageTemplate) InputVariables() []string
InputVariables returns the input variables used in the AI message template.
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) InputVariables() []string }
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 FewShotTemplate ¶ added in v0.0.69
type FewShotTemplate struct {
// contains filtered or unexported fields
}
FewShotTemplate is a template that combines examples with a main template.
func NewFewShotTemplate ¶ added in v0.0.69
func NewFewShotTemplate(template string, examples []map[string]any, exampleTemplate *Template, optFns ...func(o *FewShotTemplateOptions)) *FewShotTemplate
NewFewShotTemplate creates a new FewShotTemplate with the provided template, examples, and options.
func (*FewShotTemplate) Format ¶ added in v0.0.69
func (p *FewShotTemplate) Format(values map[string]any) (string, error)
Format applies values to the template and returns the formatted result.
func (*FewShotTemplate) FormatPrompt ¶ added in v0.0.69
func (p *FewShotTemplate) FormatPrompt(values map[string]any) (schema.PromptValue, error)
FormatPrompt applies values to the template and returns a PromptValue representation of the formatted result.
func (*FewShotTemplate) InputVariables ¶ added in v0.0.69
func (p *FewShotTemplate) InputVariables() []string
InputVariables returns the input variables used in the template.
func (*FewShotTemplate) OutputParser ¶ added in v0.0.69
func (p *FewShotTemplate) OutputParser() (schema.OutputParser[any], bool)
OutputParser returns the output parser function and a boolean indicating if an output parser is defined.
func (*FewShotTemplate) Partial ¶ added in v0.0.69
func (p *FewShotTemplate) Partial(values map[string]any) schema.PromptTemplate
Partial creates a new FewShotTemplate with partial values.
type FewShotTemplateOptions ¶ added in v0.0.69
type FewShotTemplateOptions struct { // Prefix to be added before the template. Prefix string // Separator between examples and the template. Separator string // OutputParser to parse the response. OutputParser schema.OutputParser[any] // PartialValues to be used in the template. PartialValues map[string]any // IgnoreMissingKeys allows ignoring missing keys in the template. IgnoreMissingKeys bool }
FewShotTemplateOptions represents options for configuring a FewShotTemplate.
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
func NewFormatter ¶
func NewFormatter(text string, optFns ...func(o *FormatterOptions)) *Formatter
type FormatterOptions ¶ added in v0.0.66
type FormatterOptions struct {
IgnoreMissingKeys bool
}
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)
func (*HumanMessageTemplate) InputVariables ¶ added in v0.0.59
func (pt *HumanMessageTemplate) InputVariables() []string
InputVariables returns the input variables used in the human message template.
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) InputVariables() []string }
MessageTemplate represents a chat message template.
type StringPromptValue ¶
type StringPromptValue string
StringPromptValue represents a string value that satisfies the PromptValue interface.
func (StringPromptValue) Messages ¶
func (v StringPromptValue) Messages() schema.ChatMessages
Messages returns a ChatMessages slice containing a single HumanChatMessage with the string value.
func (StringPromptValue) String ¶
func (v StringPromptValue) String() string
String returns the string representation of the StringPromptValue.
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)
func (*SystemMessageTemplate) InputVariables ¶ added in v0.0.59
func (pt *SystemMessageTemplate) InputVariables() []string
InputVariables returns the input variables used in the system message template.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template represents a template that can be formatted with dynamic values.
func NewTemplate ¶
func NewTemplate(template string, optFns ...func(o *TemplateOptions)) *Template
NewTemplate creates a new Template with the provided template and options.
func (*Template) FormatPrompt ¶
FormatPrompt applies values to the template and returns a PromptValue representation of the formatted result.
func (*Template) InputVariables ¶ added in v0.0.2
InputVariables returns the input variables used in the template.
func (*Template) OutputParser ¶ added in v0.0.3
func (p *Template) OutputParser() (schema.OutputParser[any], bool)
OutputParser returns the output parser function and a boolean indicating if an output parser is defined.
type TemplateOptions ¶
type TemplateOptions struct { PartialValues map[string]any Language string OutputParser schema.OutputParser[any] TransformPythonTemplate bool IgnoreMissingKeys bool }
TemplateOptions defines the options for configuring a Template.