Documentation
¶
Index ¶
- Constants
- Variables
- func BuildToolChoiceNameMapping(tools []spec.ToolChoice) (toolNames []toolName, toolNameMap map[string]spec.ToolChoice)
- func ClampIntToInt32(v int) int32
- func CloneBoolPtr(p *bool) *bool
- func CloneFetchCompletionRequest(req *spec.FetchCompletionRequest) (*spec.FetchCompletionRequest, error)
- func CloneFloat64Ptr(in *float64) *float64
- func CloneIntPtr(p *int) *int
- func CloneStringMap(in map[string]string) map[string]string
- func CloneStringPtr(in *string) *string
- func FilterMessagesByTokenCount(messages []spec.InputUnion, maxTokenCount int) []spec.InputUnion
- func IsInputUnionEmpty(in spec.InputUnion) bool
- func NewBufferedStreamer(onDataFlush func(string) error, flushInterval time.Duration, maxSize int) (write func(string) error, flush func())
- func NormalizeRequestForSDK(ctx context.Context, req *spec.FetchCompletionRequest, ...) (cappedReq *spec.FetchCompletionRequest, ...)
- func Recover(msg string, fields ...any)
- func SafeCallStreamHandler(handler spec.StreamHandler, event spec.StreamEvent) (err error)
- func ToolDescription(ct spec.ToolChoice) string
- type CompletionProvider
- type ResolvedAllowedTool
- type ResolvedStreamConfig
Constants ¶
const ( FlushInterval = 32 * time.Millisecond FlushChunkSize = 1024 )
Variables ¶
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 ClampIntToInt32 ¶ added in v0.13.0
func CloneBoolPtr ¶ added in v0.20.0
func CloneFetchCompletionRequest ¶ added in v0.11.0
func CloneFetchCompletionRequest(req *spec.FetchCompletionRequest) (*spec.FetchCompletionRequest, error)
func CloneFloat64Ptr ¶ added in v0.20.0
func CloneIntPtr ¶ added in v0.20.0
func CloneStringPtr ¶ added in v0.20.0
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 NormalizeRequestForSDK ¶ added in v0.9.1
func NormalizeRequestForSDK( ctx context.Context, req *spec.FetchCompletionRequest, opts *spec.FetchCompletionOptions, sdkType spec.ProviderSDKType, providerCapabilities spec.ModelCapabilities, ) (cappedReq *spec.FetchCompletionRequest, effectiveCapabilities *spec.ModelCapabilities, warnings []spec.Warning, err error)
func Recover ¶
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 CompletionProvider ¶ added in v0.9.1
type CompletionProvider interface {
InitLLM(ctx context.Context) error
DeInitLLM(ctx context.Context) error
GetProviderInfo(ctx context.Context) *spec.ProviderParam
IsConfigured(ctx context.Context) bool
SetProviderAPIKey(ctx context.Context, apiKey string) error
GetProviderCapability(ctx context.Context) (spec.ModelCapabilities, error)
FetchCompletion(
ctx context.Context,
fetchCompletionRequest *spec.FetchCompletionRequest,
opts *spec.FetchCompletionOptions,
) (*spec.FetchCompletionResponse, error)
}
type ResolvedAllowedTool ¶ added in v0.7.0
func ResolveAllowedTools ¶ added in v0.7.0
func ResolveAllowedTools( allowed []spec.AllowedTool, toolChoiceNameMap map[string]spec.ToolChoice, ) ([]ResolvedAllowedTool, error)
type ResolvedStreamConfig ¶
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.