internal

package
v0.0.0-...-35a7e6d Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastProviderOptions

func CastProviderOptions[T ProviderRequestOptions](opts ProviderRequestOptions) T

func GenerateSchema

func GenerateSchema[S any]() jsonschema.Schema

func MaybeF64ToF32

func MaybeF64ToF32(f *float64) *float32

func MaybeIntToInt32

func MaybeIntToInt32(i *int) *int32

Types

type Adapter

type Adapter interface {
	// DefaultModel returns the default model name configured for the adapter.
	DefaultModel() string
	// HttpClient returns the *http.Client instance used for making HTTP requests.
	HttpClient() *http.Client
}

Adapter defines the interface for internal configuration and utility methods that LLM providers can access from the main llmberjack.

type FunctionBody

type FunctionBody struct {
	Inner any
}

FunctionBody is a wrapper around the tool function pointer.

It is private so the only way to create it is through the llmberjack.Function[A]() function, which ensures the argument is of the shape `func(a) (string, error)`.

type ProviderRequestOptions

type ProviderRequestOptions interface {
	// ProviderOptions is a dummy method used to satisfy the interface.
	// It has no functional purpose other than to mark a struct as containing
	// provider-specific request options.
	ProviderRequestOptions()
}

ProviderRequestOptions is a marker interface that all provider-specific request options structs must implement. This allows for type assertion and reflection to extract provider-specific options from a generic request.

type Schema

type Schema struct {
	Name        string
	Description string
	Schema      jsonschema.Schema
}

type Tool

type Tool struct {
	Name        string
	Description string
	Parameters  jsonschema.Schema
	// contains filtered or unexported fields
}

Tool is a tool function definition.

This type, as well as this whole file, is in the internal package so its internals cannot be manually crafted, and we can guarantee a semblance of type safety.

func NewTool

func NewTool[A any](name, description string, fn FunctionBody) Tool

NewTool is only called by the public-facing NewTool function.

func (Tool) Call

func (t Tool) Call(paramsJson []byte) (string, error)

call resolves the tool function and executes it.

It does some reflection dark magic from the recorded type-erased values on Tool[A] to deserialize the JSON-encoded arguments from the provider into A, retrieve the function pointer, check its shape (number and types of arguments and return values), and call it.

We are being a bit overly cautious here, some of the checks are on supposed invariants, but better safe than sorry.

Jump to

Keyboard shortcuts

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