internal

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const LogLevelNaked = slog.Level(-1)

LogLevelNaked represents a logging level that is not associated with any predefined severity, allowing for custom handling in logging operations. It is used to indicate a log entry that should not be adorned with a standard level icon or prefix when processed by a custom log handler such as PrettyLogger.

Variables

This section is empty.

Functions

func Columns added in v0.0.4

func Columns(str string, maxLen int) []string

Columns breaks a string into lines with a maximum given length, ensuring that words are not split across lines and excess whitespace is removed, and returns the resulting slice of strings.

func Drain

func Drain[T any](vals <-chan T, errs <-chan error) ([]T, error)

Drain collects values from a channel of a specified type until the channel is closed, while also listening for an error on a separate error channel. It returns a slice containing all the collected values and an error if encountered. If the error channel is closed without any errors sent, it returns the collected values and a nil error. If an error is received, it returns the values collected up to that point along with the received error.

func JoinStrings added in v0.0.4

func JoinStrings[E ~string](elems []E, sep string) E

JoinStrings concatenates the elements of a slice of strings, using the provided separator between adjacent elements, and returns the resulting string. If the slice is empty, it returns an empty string. If the slice has only one element, it returns that element without the separator.

func Map added in v0.0.4

func Map[In, Out any](in <-chan In, fn func(In) Out) <-chan Out

Map applies a provided function to each element received from a channel and returns a new channel that emits the results.

func NopLogger

func NopLogger() *slog.Logger

NopLogger returns a new logger instance that will ignore all log events, effectively performing no operations when handling logs. It provides a *slog.Logger that can be used where logging is necessary but not desired to have any output or effect.

func OpenAITokenizer added in v0.1.1

func OpenAITokenizer(model string) (tokenizer.Codec, error)

OpenAITokenizer initializes and returns a tokenizer codec based on the specified model. If the model is not supported, it falls back to the default CL100kBase tokenizer. It may return an error if initializing the tokenizer fails for reasons other than an unsupported model. The returned codec can be used to tokenize or detokenize text according to the OpenAI specifications associated with the model.

func PrettyLogger added in v0.0.4

func PrettyLogger(h slog.Handler) slog.Handler

PrettyLogger wraps a given slog.Handler to enhance logging output with visually distinct icons based on the log level and formats attributes for improved readability. It returns a slog.Handler that can be used to handle log records in a more user-friendly manner.

func RemoveColumns added in v0.0.9

func RemoveColumns(str string) string

RemoveColumns cleans up paragraph text by removing newline characters within paragraphs and normalizing the spacing between words. It returns the resulting clean text.

func Stream added in v0.0.4

func Stream[T any](values ...T) <-chan T

Stream initiates a streaming of the provided values through a channel of the same type, allowing for concurrent processing of the values in a non-blocking manner. It returns a receive-only channel from which the streamed values can be read.

func Walk

func Walk[T any](vals <-chan T, errs <-chan error, fn func(T) error) error

Walk applies a provided function to each element received from a channel, halting on and returning the first error encountered. It consumes two channels: one for values of type T and another for errors.

Types

This section is empty.

Directories

Path Synopsis
git

Jump to

Keyboard shortcuts

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