baml

package
v0.202.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0, Apache-2.0 Imports: 15 Imported by: 38

Documentation

Index

Constants

View Source
const (
	StreamStatePending    = shared.StreamStatePending
	StreamStateIncomplete = shared.StreamStateIncomplete
	StreamStateComplete   = shared.StreamStateComplete
)

Variables

This section is empty.

Functions

func Decode

func Decode(holder *cffi.CFFIValueHolder) reflect.Value

func DecodeStreamingState added in v0.200.0

func DecodeStreamingState[T any](holder *cffi.CFFIValueHolder, decodeFunc func(inner *cffi.CFFIValueHolder) T) shared.StreamState[T]

func EncodeClass

func EncodeClass(name func() *cffi.CFFITypeName, fields map[string]any, dynamicFields *map[string]any) (*cffi.CFFIValueHolder, error)

func EncodeEnum

func EncodeEnum(name func() *cffi.CFFITypeName, value string, is_dynamic bool) (*cffi.CFFIValueHolder, error)

func EncodeUnion

func EncodeUnion(name func() *cffi.CFFITypeName, variant string, value any) (*cffi.CFFIValueHolder, error)

func InvokeRuntimeCli

func InvokeRuntimeCli(args []string) int

func SetTypeMap

func SetTypeMap(t serde.TypeMap)

Types

type BamlClientError

type BamlClientError struct {
	BamlError
}

type BamlClientHttpError

type BamlClientHttpError struct {
	BamlClientError
}

type BamlError

type BamlError struct {
	Message string
}

func (BamlError) Error added in v0.85.0

func (e BamlError) Error() string

type BamlFunctionArguments added in v0.86.1

type BamlFunctionArguments struct {
	Kwargs         map[string]any
	ClientRegistry *ClientRegistry
	Env            map[string]string
	Collectors     []Collector
}

func (*BamlFunctionArguments) Encode added in v0.202.0

func (args *BamlFunctionArguments) Encode() ([]byte, error)

type BamlRuntime

type BamlRuntime struct {
	// contains filtered or unexported fields
}

func CreateRuntime

func CreateRuntime(
	root_path string,
	src_files map[string]string,
	env_vars map[string]string,
) (BamlRuntime, error)

func (*BamlRuntime) CallFunction

func (r *BamlRuntime) CallFunction(ctx context.Context, functionName string, encoded_args []byte, onTick OnTickCallbackData) (*ResultCallback, error)

func (*BamlRuntime) CallFunctionStream

func (r *BamlRuntime) CallFunctionStream(ctx context.Context, functionName string, encoded_args []byte, onTick OnTickCallbackData) (<-chan ResultCallback, error)

type CallbackData

type CallbackData struct {
	// contains filtered or unexported fields
}

type Checked

type Checked[T any] = shared.Checked[T]

type ClientRegistry added in v0.89.0

type ClientRegistry struct {
	// contains filtered or unexported fields
}

func NewClientRegistry added in v0.89.0

func NewClientRegistry() *ClientRegistry

func (ClientRegistry) AddLlmClient added in v0.89.0

func (c ClientRegistry) AddLlmClient(name string, provider string, options map[string]any)

func (*ClientRegistry) SetPrimaryClient added in v0.89.0

func (c *ClientRegistry) SetPrimaryClient(name string)

type Collector added in v0.200.0

type Collector interface {
	raw_objects.RawPointer
	// Usage gathers the Usage object but keeps the underlying C collector alive
	// until the Usage is done.
	Usage() (Usage, error)
	// Name returns the collector name
	Name() (string, error)
	// Logs returns all function logs
	Logs() ([]FunctionLog, error)
	// Last returns the most recent function log
	Last() (FunctionLog, error)
	// ID looks up a function log by ID
	Id(functionId string) (FunctionLog, error)
	// Clear removes all logs and frees memory
	Clear() (int64, error)
}

func NewCollector added in v0.200.0

func NewCollector(name string) (Collector, error)

type FunctionLog added in v0.202.0

type FunctionLog interface {
	raw_objects.RawPointer
	// ID returns the function log ID
	Id() (string, error)
	// FunctionName returns the function name
	FunctionName() (string, error)
	// LogType returns the log type
	LogType() (string, error)
	// Timing returns the timing information
	Timing() (Timing, error)
	// Usage returns the usage information
	Usage() (Usage, error)
	// RawLLMResponse returns the raw LLM response
	RawLLMResponse() (string, error)
	// Calls returns all LLM calls made during this function execution (can be LLMCall or LLMStreamCall)
	Calls() ([]LLMCall, error)
	// SelectedCall returns the call that was selected for parsing (can be LLMCall or LLMStreamCall)
	SelectedCall() (LLMCall, error)
	// Tags returns any user-provided metadata
	Tags() (map[string]any, error)
}

type FunctionSignal added in v0.202.0

type FunctionSignal interface{}

type HTTPBody added in v0.202.0

type HTTPBody interface {
	raw_objects.RawPointer
	// Text returns the body as a string
	Text() (string, error)
	// JSON returns the body as a JSON object
	JSON() (any, error)
}

type HTTPRequest added in v0.202.0

type HTTPRequest interface {
	raw_objects.RawPointer
	// ID returns the request ID
	RequestId() (string, error)
	// URL returns the request URL
	Url() (string, error)
	// Method returns the HTTP method
	Method() (string, error)
	// Headers returns the request headers
	Headers() (map[string]string, error)
	// Body returns the request body
	Body() (HTTPBody, error)
}

type HTTPResponse added in v0.202.0

type HTTPResponse interface {
	raw_objects.RawPointer
	// ID returns the request ID
	RequestId() (string, error)
	// Status returns the HTTP status code
	Status() (int64, error)
	// Headers returns the response headers
	Headers() (map[string]string, error)
	// Body returns the response body
	Body() (HTTPBody, error)
}

type LLMCall added in v0.202.0

type LLMCall interface {
	raw_objects.RawPointer
	// ID returns the request ID: Not the same as the function log ID
	RequestId() (string, error)
	// ClientName returns the name of the client used
	ClientName() (string, error)
	// Provider returns the provider of the client
	Provider() (string, error)
	// HttpRequest returns the raw HTTP request
	HttpRequest() (HTTPRequest, error)
	// HttpResponse returns the raw HTTP response (nullable for streaming)
	HttpResponse() (HTTPResponse, error)
	// Usage returns the usage information (nullable)
	Usage() (Usage, error)
	// Selected returns whether this call was selected for parsing
	Selected() (bool, error)
	// Timing returns the timing information
	Timing() (Timing, error)
}

type LLMStreamCall added in v0.202.0

type LLMStreamCall interface {
	LLMCall
	// SSEChunks returns the SSE chunks of the response
	SSEChunks() ([]SSEResponse, error)
}

type OnTickCallbackData added in v0.202.0

type OnTickCallbackData interface {
	Collector() Collector
	OnTick() TickCallback
}

type ResultCallback

type ResultCallback struct {
	Error         error
	HasStreamData bool
	HasData       bool
	StreamData    any
	Data          any
}

type SSEResponse added in v0.202.0

type SSEResponse interface {
	raw_objects.RawPointer
	// Text returns the body as a string
	Text() (string, error)
	// JSON returns the body as a JSON object (nullable)
	JSON() (any, error)
}

type StreamResult

type StreamResult[Partial any, Final any] struct {
	// contains filtered or unexported fields
}

func (*StreamResult[Partial, Final]) Error

func (result *StreamResult[Partial, Final]) Error() error

func (*StreamResult[Partial, Final]) Final

func (result *StreamResult[Partial, Final]) Final() Final

func (*StreamResult[Partial, Final]) IsFinal

func (result *StreamResult[Partial, Final]) IsFinal() bool

func (*StreamResult[Partial, Final]) IsPartial

func (result *StreamResult[Partial, Final]) IsPartial() bool

func (*StreamResult[Partial, Final]) Partial

func (result *StreamResult[Partial, Final]) Partial() Partial

type StreamState

type StreamState[T any] = shared.StreamState[T]

type StreamTiming added in v0.202.0

type StreamTiming interface {
	Timing
}

type StreamingStateType added in v0.202.0

type StreamingStateType = shared.StreamStateType

type TickCallback added in v0.202.0

type TickCallback func(ctx context.Context, reason TickReason, log FunctionLog) FunctionSignal

type TickReason added in v0.202.0

type TickReason string
const (
	TickReason_Unknown TickReason = "Unknown"
)

type Timing added in v0.202.0

type Timing interface {
	raw_objects.RawPointer
	// StartTimeUTCMs returns the start time in milliseconds since epoch
	StartTimeUTCMs() (int64, error)
	// DurationMs returns the duration in milliseconds (nullable)
	DurationMs() (*int64, error)
}

type TypeMap

type TypeMap = serde.TypeMap

type Usage added in v0.200.0

type Usage interface {
	raw_objects.RawPointer
	// InputTokens returns the number of input tokens
	InputTokens() (int64, error)
	// OutputTokens returns the number of output tokens
	OutputTokens() (int64, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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