utils

package
v0.0.0-...-849288d Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	PrintWidthL1 = 110
	PrintWidthL2 = 96
)

Variables

View Source
var (
	StyConclusion    = CreateStyle("╔", "╗", "╚", "╝", "║", "═", "🎉🎉 ", "", 0)
	StyTalk          = CreateStyle("╔", "╗", "╚", "╝", "║", "═", "🚗 ", "", 0)
	StyNoFuncResult  = CreateStyle("┌", "┐", "└", "┘", "│", "─", "🌲 ", "", 1)
	StyFunctionStack = CreateStyle("┌", "┐", "└", "┘", "│", "─", "🔍 ", "", 1)
	StyMsgCard       = CreateStyle("┌", "┐", "└", "┘", "│", "─", "✉ ", "", 2)
)

预定义的样式

View Source
var LogDir = "./logs"

Functions

func CountTokens

func CountTokens(text string) int

func ExtractAgentID

func ExtractAgentID(ctx context.Context) (string, bool)

ExtractAgentID 从 context 中获取 bot 的 id

func ExtractAgentLogKey

func ExtractAgentLogKey(ctx context.Context) (string, bool)

ExtractAgentLogKey 从 context 中获取 bot 的 prefabName

func InjectAgentID

func InjectAgentID(ctx context.Context, id string) context.Context

InjectAgentID 将 bot 的 prefabName 注入到 context 中

func InjectAgentLogKey

func InjectAgentLogKey(ctx context.Context, logKey string) context.Context

InjectAgentLogKey 将 bot 的 prefabName 注入到 context 中

func MustInitLogger

func MustInitLogger()

func SPrintWithCallStack

func SPrintWithCallStack(title, content string, maxWidth int) string

SPrintWithCallStack 打印函数调用栈

func SPrintWithFrameCard

func SPrintWithFrameCard(title, content string, maxWidth int, style FrameStyle) string

SPrintWithFrameCard 打印带框架的卡片

func SPrintWithMsgCard

func SPrintWithMsgCard(title, content string, maxWidth int) string

SPrintWithMsgCard 打印 msg 栈中的单个消息

func TakeSentences

func TakeSentences(lst []string, maxToken int) (paragraph []rune, left []string)

TakeSentences 从句子列表中取出一段话,并返回剩余的句子列表 lst 为句子列表, 由原始文本分割得到 (比如根据 \n 分隔) maxToken 为每段话的最大 token 数

func Unmarshal2

func Unmarshal2[T any](str string) (ret T, err error)

Types

type CtxKey

type CtxKey string
const (
	CtxKeyAgentLog      CtxKey = "agent_log"
	CtxKeyAgentIdentity CtxKey = "agent_id"
)

type EnvKey

type EnvKey string

func (EnvKey) Read

func (ek EnvKey) Read(or ...string) string

type FrameStyle

type FrameStyle struct {
	TopLeft     string
	TopRight    string
	BottomLeft  string
	BottomRight string
	Horizontal  string
	Vertical    string
	TitlePrefix string
	LinePrefix  string

	LiteLevel uint8
}

FrameStyle 定义框架样式

func CreateStyle

func CreateStyle(lt, rt, lb, rb, v, h, titlePrefix, linePrefix string, level uint8) FrameStyle

Jump to

Keyboard shortcuts

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