utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Blue = lipgloss.NewStyle().TabWidth(2).Foreground(lipgloss.Color("#6E95F7")).Render
View Source
var Dark = lipgloss.NewStyle().TabWidth(2).Foreground(lipgloss.Color("#666666")).Render
View Source
var Green = lipgloss.NewStyle().TabWidth(2).Foreground(lipgloss.Color("#06C26F")).Render
View Source
var Highlight = lipgloss.NewStyle().TabWidth(2).Foreground(lipgloss.Color("#EEEEEE")).Render
View Source
var Muted = lipgloss.NewStyle().TabWidth(2).Foreground(lipgloss.Color("#999999")).Render
View Source
var Red = lipgloss.NewStyle().TabWidth(2).Foreground(lipgloss.Color("#F7746D")).Render
View Source
var Yellow = lipgloss.NewStyle().TabWidth(2).Foreground(lipgloss.Color("#F7B96D")).Render

Functions

func BoolPtr

func BoolPtr(b bool) *bool

func ExtractCodeBlocks

func ExtractCodeBlocks(s string) map[string][]string

ExtractCodeBlocks parses markdown-style code blocks from a string. Returns a map where keys are language identifiers and values are slices of code blocks for that language.

func ExtractJSONBlocks

func ExtractJSONBlocks(s string) []map[string]interface{}

ExtractJSONBlocks finds and parses JSON objects from a string. It specifically looks for JSON content within markdown-style code blocks that are marked with the 'json' language identifier. This is particularly useful when processing structured outputs from AI tools.

func GenerateSchema

func GenerateSchema[T any]() interface{}

GenerateSchema creates a JSON schema for any type that implements jsonschema struct tags. It uses the jsonschema reflector to generate a complete schema, with additional properties disabled and direct type definitions (no references).

func Indent

func Indent(content string, indent int) string

Indent adds a specified number of spaces to the beginning of a string. This is useful for formatting output, especially when dealing with structured data that needs to be visually separated.

func JoinWith

func JoinWith(delim string, args ...string) string

JoinWith concatenates strings with a specified delimiter. It's a convenience wrapper around strings.Join that provides a more readable interface.

func NewID

func NewID() string

NewID generates a new UUID string. It uses Google's UUID implementation to ensure uniqueness.

func NewName

func NewName() string

NewName generates a unique, readable name. It maintains a list of previously generated names to ensure uniqueness within the current session.

func ParseJSON

func ParseJSON(s string) map[string]interface{}

ParseJSON safely converts a JSON string into a map. Returns nil if the input is not valid JSON, making it safe for parsing potentially invalid input.

func QuickWrap

func QuickWrap(tag, content string, indent int) string

QuickWrap encapsulates content in XML-style tags for better context separation. This is particularly useful when preparing content for LLM processing, as it helps maintain clear boundaries between different content sections.

func QuickWrapWithAttributes

func QuickWrapWithAttributes(tag, content string, indent int, attributes map[string]string) string

QuickWrapWithAttributes is a variant of QuickWrap that allows for additional attributes to be added to the tag.

func Reflow

func Reflow(message string) (reflowed string)

Reflow restructures the sentences in the message, so that each sentence ends with a newline, and each paragraph is separated by an empty line. It also tries to keep each sentence under 80 characters, and if it's longer, it will split it into multiple sentences, using a smart algorithm, to make sure we do not end up with just one or two words on the new line, but a somewhat balanced distribution of words.

func ReplaceWith

func ReplaceWith(template string, args [][]string) string

ReplaceWith performs template-style string replacement using {placeholder} syntax. Each replacement is defined by a pair of strings where the first element is the placeholder name and the second is its replacement value.

func SplitIntoParagraphs

func SplitIntoParagraphs(content string) []string

SplitIntoParagraphs breaks text into logical paragraphs based on blank lines. It trims whitespace and removes empty paragraphs from the result.

func SplitIntoSentences

func SplitIntoSentences(para string) []string

SplitIntoSentences divides text into individual sentences while preserving punctuation. It uses the neurosnap/sentences package which implements the Punkt algorithm for unsupervised multilingual sentence boundary detection.

func StripXML

func StripXML(message string) string

StripXML strips all XML tags the agent might have added to the message. It uses a regex to find all the tags and remove them.

func Substitute

func Substitute(message string, fragments map[string]string, indent int) string

Substitute replaces all the placeholders in the message with the actual values.

func WrapText

func WrapText(text string, width int) []string

WrapText formats text to fit within a specified character width. It preserves whole words where possible and handles cases where individual words exceed the specified width by breaking them.

Types

This section is empty.

Jump to

Keyboard shortcuts

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