Documentation
¶
Overview ¶
Package llmutils provides utility functions and helpers for LLM operations, including prompt formatting, message handling, and other agentic utilities.
Index ¶
- func AddComment(role, name, typ, content string) string
- func BackticksJSON(js string) string
- func BackticksYAM(js string) string
- func BytesTrimBackticks(bs []byte) []byte
- func CleanJSON(bs []byte) []byte
- func CountMessagesContentSize(msgs []llms.Message) uint64
- func CountResponseContentSize(resp *llms.ContentResponse) uint64
- func CountTokens(resp *llms.ContentResponse) (in, out, total int64)
- func DownloadImageData(url string) (string, []byte, error)
- func EnsureEndsWithNewline(s string) string
- func ExtractTag(input string, tagPrefix string) string
- func FindLastUserQuestion(messages []llms.Message) string
- func JSONIndent(body string) string
- func MergeInputs(configInputs map[string]any, userInputs map[string]any) map[string]any
- func NewContentResponse(val any) *llms.ContentResponse
- func PrintMessages(w io.Writer, msgs []llms.Message)
- func RemoveAllComments(input string) string
- func Stringify(s any) string
- func StripComments(text string) string
- func ToJSON(val any) string
- func ToJSONIndent(val any) string
- func ToYAML(val any) string
- func TrimBackticks(text string) string
- type Stringer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddComment ¶
func BackticksJSON ¶
func BackticksYAM ¶
func BytesTrimBackticks ¶
BytesTrimBackticks removes ```json or ```
func CleanJSON ¶
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 ¶
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
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
EnsureEndsWithNewline ensures the message ends with a newline, it also removes any extra leading and trailing spaces.
func ExtractTag ¶
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 JSONIndent ¶
func MergeInputs ¶
func NewContentResponse ¶
func NewContentResponse(val any) *llms.ContentResponse
func PrintMessages ¶ added in v0.11.64
PrintMessages is a debugging helper for Messages.
func RemoveAllComments ¶
RemoveAllComments removes all <!-- --> comments from the LLM output
func StripComments ¶
StripComments removes <!-- --> comments from the LLM output