prompt

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package prompt provides utilities for managing and optimizing prompts.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPartialVariableType = errors.New("invalid partial variable type")
)

Functions

func ListTemplateFields

func ListTemplateFields(t *template.Template) []string

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

func NewFormatter(text string) *Formatter

func (*Formatter) Fields

func (pt *Formatter) Fields() []string

func (*Formatter) Render

func (pt *Formatter) Render(values map[string]any) (string, error)

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 PartialValues map[string]any

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) Format

func (p *Template) Format(values map[string]any) (string, error)

func (*Template) FormatPrompt

func (p *Template) FormatPrompt(values map[string]any) (schema.PromptValue, error)

func (*Template) InputVariables added in v0.0.2

func (p *Template) InputVariables() []string

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
}

Jump to

Keyboard shortcuts

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