util

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToString

func ByteToString(b [][]byte) []string

Cast an array of byte arrays to an array of strings

func ChunkFile

func ChunkFile(
	fs afero.Fs,
	path string,
	chunkSize int,
	maxChunks int,
	callback func(int, []byte) error) error

Read a file, break into chunks of a given number of bytes, up to a maximum number of chunks, and call the callback for each chunk

func ChunkFromReader

func ChunkFromReader(
	reader io.Reader,
	chunkSize int,
	maxChunks int,
	callback func(int, []byte) error) error

func ForEachSubdir

func ForEachSubdir(fs afero.Fs, path string,
	callback func(path string) error) error

Call a callback for each subdirectory in a given path

func GetChunks

func GetChunks(reader io.Reader, chunkSize int, maxChunks int) ([][]byte, error)

func GetFileChunks

func GetFileChunks(ctx context.Context, fs afero.Fs, path string,
	chunkSize int, maxChunks int) ([][]byte, error)

Given a filesystem, a path, a chunk size, and maximum number of chunks, return a list of chunks of the file at the given path

func HistoryBlocksToString added in v0.0.20

func HistoryBlocksToString(blocks []HistoryBlock) string

func IsPipedStdin

func IsPipedStdin() bool

Returns true if there is piped stdin data that can be read

func Min

func Min(a, b int) int

func MultilineLipglossRender

func MultilineLipglossRender(style lipgloss.Style, str string) string

Lipgloss is a little tricky - if you render a string with newlines it turns it into a "block", i.e. each line will be padding to be the same length. This is not what we want, so we split on newlines and render each line separately.

Types

type CacheWriter

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

A io.Writer that caches bytes written and forwards writes to another writer

func NewCacheWriter

func NewCacheWriter(forward io.Writer) *CacheWriter

func (*CacheWriter) GetCache

func (this *CacheWriter) GetCache() []byte

func (*CacheWriter) GetLastN

func (this *CacheWriter) GetLastN(n int) []byte

func (*CacheWriter) Write

func (this *CacheWriter) Write(p []byte) (n int, err error)

type ColorWriter added in v0.0.27

type ColorWriter struct {
	Color  string
	Writer io.Writer
}

func NewColorWriter added in v0.0.27

func NewColorWriter(writer io.Writer, color string) *ColorWriter

func (*ColorWriter) Write added in v0.0.27

func (this *ColorWriter) Write(p []byte) (n int, err error)

type CompletionRequest

type CompletionRequest struct {
	Ctx           context.Context
	Prompt        string
	Model         string
	MaxTokens     int
	Temperature   float32
	HistoryBlocks []HistoryBlock
	SystemMessage string
	Functions     []FunctionDefinition
	Verbose       bool
}

We define types for calling LLM APIs here because I don't want the internal interfaces to depend on OpenAI-specific types.

type CompletionResponse added in v0.1.4

type CompletionResponse struct {
	Completion         string
	FunctionName       string
	FunctionParameters string
}

type FunctionDefinition added in v0.1.4

type FunctionDefinition struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Parameters  any    `json:"parameters"`
}

type HistoryBlock added in v0.0.20

type HistoryBlock struct {
	Type           int
	Content        string
	FunctionName   string
	FunctionParams string
}

func (HistoryBlock) String added in v0.0.20

func (this HistoryBlock) String() string

type ReplaceWriter added in v0.0.20

type ReplaceWriter struct {
	Writer io.Writer
	From   string
	To     string
}

A Writer implementation that allows you to string replace the content flowing through

func NewReplaceWriter added in v0.0.20

func NewReplaceWriter(writer io.Writer, from string, to string) *ReplaceWriter

func (*ReplaceWriter) Write added in v0.0.20

func (this *ReplaceWriter) Write(p []byte) (n int, err error)

type StyledWriter

type StyledWriter struct {
	Writer io.Writer
	Style  lipgloss.Style
	// contains filtered or unexported fields
}

An implementation of io.Writer that renders output with a lipgloss style and filters out the special token "NOOP". This is specially handled - we seem to get "NO" as a separate token from GPT.

func NewStyledWriter

func NewStyledWriter(writer io.Writer, style lipgloss.Style) *StyledWriter

func (*StyledWriter) Write

func (this *StyledWriter) Write(input []byte) (int, error)

Writer for StyledWriter This is a bit insane but it's a dumb way to filter out NOOP split into two tokens, should probably be rewritten

Jump to

Keyboard shortcuts

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