sdkutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlushInterval  = 256 * time.Millisecond
	FlushChunkSize = 1024
)

Variables

This section is empty.

Functions

func BuildToolChoiceNameMapping

func BuildToolChoiceNameMapping(
	tools []spec.ToolChoice,
) (toolNames []toolName, toolNameMap map[string]spec.ToolChoice)

BuildToolChoiceNameMapping assigns short, human‑readable function names to tools.

Rules:

  • base name is the sanitized tool slug (lower‑cased, [a‑z0‑9_-] only)
  • first tool with a given slug gets "<slug>"
  • subsequent tools with the same slug get "<slug>_2", "<slug>_3", ...
  • names are truncated to 64 characters (OpenAI function-tool limit)

Returns:

  • ordered: same cardinality/order as input tools, but with the derived function name for each tool.
  • nameToTool: map[functionName] => FetchCompletionToolChoice; used to translate tool calls back to the original identity.

func FilterMessagesByTokenCount

func FilterMessagesByTokenCount(
	messages []spec.InputUnion,
	maxTokenCount int,
) []spec.InputUnion

func IsInputUnionEmpty

func IsInputUnionEmpty(in spec.InputUnion) bool

IsInputUnionEmpty reports whether an InputUnion has nothing "worth sending". Metadata-only messages (e.g. only IDs/roles with no actual content) are treated as empty. Adjust the helpers below if your semantics differ.

func NewBufferedStreamer

func NewBufferedStreamer(
	onDataFlush func(string) error,
	flushInterval time.Duration,
	maxSize int,
) (write func(string) error, flush func())

NewBufferedStreamer returns two functions:

  • write(chunk) -> use this instead of onDataFlush
  • flush() -> call once when streaming is finished

func Recover

func Recover(msg string, fields ...any)

Recover logs a panic (if any) at error level and prevents it from bringing down the goroutine's caller. It does not modify any returned error.

func SafeCallStreamHandler

func SafeCallStreamHandler(handler spec.StreamHandler, event spec.StreamEvent) (err error)

SafeCallStreamHandler invokes the provided StreamHandler and converts any panic into an error while logging the panic details. This prevents user callbacks from crashing the streaming loop.

func ToolDescription

func ToolDescription(ct spec.ToolChoice) string

Types

type ResolvedStreamConfig

type ResolvedStreamConfig struct {
	FlushInterval  time.Duration
	FlushChunkSize int
}

ResolvedStreamConfig is the fully-specified streaming configuration used by providers after applying sensible defaults.

func ResolveStreamConfig

func ResolveStreamConfig(opts *spec.FetchCompletionOptions) ResolvedStreamConfig

ResolveStreamConfig converts optional FetchCompletionOptions into a concrete ResolvedStreamConfig, falling back to library defaults as needed.

Jump to

Keyboard shortcuts

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