llmutils

package
v0.14.108 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package llmutils provides utility functions and helpers for LLM operations, including prompt formatting, message handling, and other agentic utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddComment

func AddComment(role, name, typ, content string) string

func BackticksJSON

func BackticksJSON(js string) string

func BackticksYAM

func BackticksYAM(js string) string

func BytesTrimBackticks

func BytesTrimBackticks(bs []byte) []byte

BytesTrimBackticks removes ```json or ```

func CleanJSON

func CleanJSON(bs []byte) []byte

CleanJSON returns JSON by trimming prefixes and postfixes, this is more useful than TrimBackticks, ass LLM can reply like, `Here you go: {json}`

func CountMessagesContentSize

func CountMessagesContentSize(msgs []llms.Message) uint64

CountMessagesContentSize counts the size of the content in the messages

func CountResponseContentSize

func CountResponseContentSize(resp *llms.ContentResponse) uint64

CountResponseContentSize counts the size of the content in the content response

func CountTokens added in v0.10.61

func CountTokens(resp *llms.ContentResponse) (in, out, total int64)

func DownloadImageData added in v0.9.52

func DownloadImageData(url string) (string, []byte, error)

downloadImageData downloads the content from the given URL and returns the image type and data. The image type is the second part of the response's MIME (e.g. "png" from "image/png").

func EnsureEndsWithNewline added in v0.6.30

func EnsureEndsWithNewline(s string) string

EnsureEndsWithNewline ensures the message ends with a newline, it also removes any extra leading and trailing spaces.

func ExtractTag

func ExtractTag(input string, tagPrefix string) string

ExtractTag extracts the content of a specific tag from the input string. The tag prefix can be # or @, and the content is extracted until the next space or newline.

func FindLastUserQuestion

func FindLastUserQuestion(messages []llms.Message) string

func JSONIndent

func JSONIndent(body string) string

func MergeInputs

func MergeInputs(configInputs map[string]any, userInputs map[string]any) map[string]any

func NewContentResponse

func NewContentResponse(val any) *llms.ContentResponse

func PrintMessages added in v0.11.64

func PrintMessages(w io.Writer, msgs []llms.Message)

PrintMessages is a debugging helper for Messages.

func RemoveAllComments

func RemoveAllComments(input string) string

RemoveAllComments removes all <!-- --> comments from the LLM output

func Stringify

func Stringify(s any) string

func StripComments

func StripComments(text string) string

StripComments removes <!-- --> comments from the LLM output

func ToJSON

func ToJSON(val any) string

func ToJSONIndent

func ToJSONIndent(val any) string

func ToYAML

func ToYAML(val any) string

func TrimBackticks

func TrimBackticks(text string) string

TrimBackticks removes ```json or ```

Types

type Stringer

type Stringer interface {
	String() string
}

Jump to

Keyboard shortcuts

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