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.MessageContent) uint64
- func CountResponseContentSize(resp *llms.ContentResponse) uint64
- func EnsureEndsWithNewline(s string) string
- func ExtractTag(input string, tagPrefix string) string
- func FindLastUserQuestion(messages []llms.MessageContent) 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 PrintChatMessages(w io.Writer, msgs []llms.ChatMessage, filter ...llms.ChatMessageType)
- func PrintMessageContents(w io.Writer, msgs []llms.MessageContent)
- 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 ¶
func CountMessagesContentSize(msgs []llms.MessageContent) 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 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 FindLastUserQuestion(messages []llms.MessageContent) string
func JSONIndent ¶
func MergeInputs ¶
func NewContentResponse ¶
func NewContentResponse(val any) *llms.ContentResponse
func PrintChatMessages ¶
func PrintChatMessages(w io.Writer, msgs []llms.ChatMessage, filter ...llms.ChatMessageType)
func PrintMessageContents ¶
func PrintMessageContents(w io.Writer, msgs []llms.MessageContent)
PrintMessageContents is a debugging helper for MessageContent.
func RemoveAllComments ¶
RemoveAllComments removes all <!-- --> comments from the LLM output
func StripComments ¶
StripComments removes <!-- --> comments from the LLM output