dotprompt

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 9 Imported by: 0

README

DotPrompt

codecov

A port of the dotnet DotPrompt library to Go.

The goal is to provide the same functionality and show how the prompt files can be used across languages. The dotnet version utilises the Fluid library which is a dotnet implementation of the Liquid templating language. This library makes use of the Liquid implementation by Oliver Steele.

Fluid contains some methods which are specific to dotnet (such as format_date) but where Liquid standard methods are used the templates should be compatible.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FewShotPromptPair

type FewShotPromptPair struct {
	User     string `yaml:"user"`
	Response string `yaml:"response"`
}

FewShotPromptPair represents a pair of user prompt and the corresponding response.

type FileStore

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

FileStore represents a file-based storage system for handling prompt files.

func NewFileStore

func NewFileStore() (*FileStore, error)

NewFileStore creates a new FileStore instance using the default file path ("prompts").

func NewFileStoreFromPath

func NewFileStoreFromPath(path string) (*FileStore, error)

NewFileStoreFromPath creates a new FileStore instance from the specified directory path.

func (*FileStore) Load

func (f *FileStore) Load() ([]PromptFile, error)

Load retrieves all prompt files from the specified file path and returns a slice of PromptFile objects or an error.

type FileStoreError

type FileStoreError struct {
	Message string
	Err     error
}

FileStoreError represents an error encountered in file store operations. It contains a message describing the error and an optional underlying error.

func (FileStoreError) Error

func (e FileStoreError) Error() string

Error returns the error message contained in the FileStoreError.

type InputSchema

type InputSchema struct {
	Parameters map[string]string      `yaml:"parameters"`
	Default    map[string]interface{} `yaml:"default"`
}

InputSchema represents the schema for input parameters and their default values.

type Loader

type Loader interface {

	// Load loads prompt files and returns a slice of PromptFile and an error.
	Load() ([]PromptFile, error)
}

Loader defines an interface for loading prompt files.

type Manager

type Manager struct {
	PromptFiles map[string]PromptFile
}

Manager is responsible for managing and storing prompt files, with mapping from their names to PromptFile instances.

func NewManager

func NewManager() (*Manager, error)

NewManager creates a new Manager by loading prompt files from the default file store. Returns a pointer to the Manager instance or an error if the loading process fails.

func NewManagerFromLoader

func NewManagerFromLoader(loader Loader) (*Manager, error)

NewManagerFromLoader initializes and returns a Manager instance by loading prompt files using the provided Loader. It returns a pointer to the Manager and an error if the loading process fails.

func (*Manager) GetPromptFile

func (m *Manager) GetPromptFile(name string) (PromptFile, error)

GetPromptFile retrieves the prompt file with the specified name from the manager's stored prompt files. Returns the PromptFile and a boolean indicating success of the retrieval.

func (*Manager) ListPromptFileNames

func (m *Manager) ListPromptFileNames() []string

ListPromptFileNames returns a list of all prompt file names managed by the Manager.

type OutputFormat

type OutputFormat int

OutputFormat represents the format of output, such as text or JSON.

const (

	// Text represents the plain text output format.
	Text OutputFormat = iota

	// Json represents the JSON output format.
	Json
)

func (*OutputFormat) UnmarshalYAML

func (of *OutputFormat) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML unmarshals a YAML node into an OutputFormat value, supporting "text" and "json". Returns an error if format is invalid.

type PromptConfig

type PromptConfig struct {
	Temperature  *float32     `yaml:"temperature"`
	MaxTokens    *int         `yaml:"maxTokens"`
	OutputFormat OutputFormat `yaml:"outputFormat"`
	Input        InputSchema  `yaml:"input"`
}

PromptConfig represents the configuration options for a prompt, including temperature, max tokens, output format, and input schema.

type PromptError

type PromptError struct {
	Message string
}

PromptError represents an error related to prompt processing.

func (PromptError) Error

func (e PromptError) Error() string

Error returns the error message associated with the PromptError.

type PromptFile

type PromptFile struct {
	Name     string              `yaml:"name"`
	Config   PromptConfig        `yaml:"config"`
	Prompts  Prompts             `yaml:"prompts"`
	FewShots []FewShotPromptPair `yaml:"fewShots"`
}

PromptFile represents the structure of a file containing a prompt configuration and multiple associated prompts.

func NewPromptFile

func NewPromptFile(name string, data []byte) (*PromptFile, error)

NewPromptFile creates a new PromptFile from the provided name and prompt data. It validates the input, configures the prompt file, and returns an error if any issues are encountered.

func NewPromptFileFromFile

func NewPromptFileFromFile(path string) (*PromptFile, error)

NewPromptFileFromFile reads a file from the specified path, processes its content, and returns a PromptFile structure or an error.

func (*PromptFile) GetSystemPrompt

func (pf *PromptFile) GetSystemPrompt(values map[string]interface{}) (string, error)

GetSystemPrompt generates the system prompt string using the provided template values, appending JSON format instructions if required.

func (*PromptFile) GetUserPrompt

func (pf *PromptFile) GetUserPrompt(values map[string]interface{}) (string, error)

GetUserPrompt generates a user prompt string based on a provided template and a set of values. It utilizes the 'Prompts.User' template within the PromptFile and replaces template placeholders with corresponding values from the input map.

type Prompts

type Prompts struct {
	System string `yaml:"system"`
	User   string `yaml:"user"`
}

Prompts represents a set of system and user prompts.

Jump to

Keyboard shortcuts

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