baml

package
v0.201.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BAMLTESTINGONLY_InternalEncode added in v0.201.0

func BAMLTESTINGONLY_InternalEncode(value any) (*cffi.CFFIValueHolder, error)

This is only used for testing, do not use in production

func Decode

func Decode(holder *cffi.CFFIValueHolder) any

func DecodeList

func DecodeList[T any](valueHolder *cffi.CFFIValueHolder, decodeFunc func(*cffi.CFFIValueHolder) T) []T

func DecodeMap

func DecodeMap[T any](valueHolder *cffi.CFFIValueHolder, decodeFunc func(*cffi.CFFIValueHolder) T) map[string]T

func DecodeOptional

func DecodeOptional[T any](valueHolder *cffi.CFFIValueHolder, decodeFunc func(*cffi.CFFIValueHolder) T) *T

func EncodeArgs added in v0.200.0

func EncodeArgs(args BamlFunctionArguments) ([]byte, error)

func EncodeClass

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

implment BamlSerializer for anything that implements BamlClassSerializer, BamlEnumSerializer, or BamlUnionSerializer

func EncodeEnum

func EncodeEnum(nameEncoder func() *cffi.CFFITypeName, value string, isDynamic bool) (*cffi.CFFIValueHolder, error)

func EncodeUnion

func EncodeUnion(nameEncoder func() *cffi.CFFITypeName, variantName string, value any) (*cffi.CFFIValueHolder, error)

func InvokeRuntimeCli

func InvokeRuntimeCli(args []string) int

func SetTypeMap

func SetTypeMap(t TypeMap)

Types

type BamlClassDeserializer

type BamlClassDeserializer interface {
	Decode(holder *cffi.CFFIValueClass)
}

type BamlClientError

type BamlClientError struct {
	BamlError
}

type BamlClientHttpError

type BamlClientHttpError struct {
	BamlClientError
}

type BamlDecoder

type BamlDecoder interface {
	BamlDecode(decodedMap map[string]any)
}

type BamlEnumDeserializer

type BamlEnumDeserializer interface {
	Decode(holder *cffi.CFFIValueEnum)
}

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
}

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) (*ResultCallback, error)

func (*BamlRuntime) CallFunctionStream

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

type BamlSerializer

type BamlSerializer interface {
	Encode() (*cffi.CFFIValueHolder, error)
	BamlTypeName() string
	BamlEncodeName() *cffi.CFFITypeName
}

BamlSerializer interface for custom class encoding

type BamlUnionDeserializer

type BamlUnionDeserializer interface {
	Decode(holder *cffi.CFFIValueUnionVariant)
}

type CallbackData

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

type Check

type Check struct {
	Name       string `json:"name"`
	Expression string `json:"expression"`
	Status     string `json:"status"`
}

Check corresponds to the Python Check model.

type Checked

type Checked[T any] struct {
	Value  T                `json:"value"`
	Checks map[string]Check `json:"checks"`
}

Checked is a generic struct that contains a value of any type T and a map of checks, where the key type CN has an underlying type string.

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 {
	// Usage gathers the Usage object but keeps the underlying C collector alive
	// until the Usage is done.
	Usage() (*Usage, error)
	// contains filtered or unexported methods
}

func NewCollector added in v0.200.0

func NewCollector() Collector

type DynamicClass

type DynamicClass struct {
	Name   string
	Fields map[string]any
}

func (*DynamicClass) Decode

func (d *DynamicClass) Decode(holder *cffi.CFFIValueClass)

type DynamicEnum

type DynamicEnum struct {
	Name  string
	Value string
}

func (*DynamicEnum) Decode

func (d *DynamicEnum) Decode(holder *cffi.CFFIValueEnum)

type ResultCallback

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

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] struct {
	Value T               `json:"value"`
	State StreamStateType `json:"state"`
}

func DecodeStreamingState added in v0.200.0

func DecodeStreamingState[T any](valueHolder *cffi.CFFIValueHolder, decodeFunc func(*cffi.CFFIValueHolder) T) StreamState[T]

type StreamStateType

type StreamStateType string
const (
	StreamStatePending    StreamStateType = "Pending"
	StreamStateIncomplete StreamStateType = "Incomplete"
	StreamStateComplete   StreamStateType = "Complete"
)

func (StreamStateType) IsValid

func (e StreamStateType) IsValid() bool

IsValid checks whether the given AliasedEnum value is valid.

func (StreamStateType) MarshalJSON

func (e StreamStateType) MarshalJSON() ([]byte, error)

MarshalJSON customizes JSON marshaling for AliasedEnum.

func (*StreamStateType) UnmarshalJSON

func (e *StreamStateType) UnmarshalJSON(data []byte) error

UnmarshalJSON customizes JSON unmarshaling for AliasedEnum.

func (StreamStateType) Values

func (StreamStateType) Values() []StreamStateType

Values returns all allowed values for the AliasedEnum type.

type TypeMap

type TypeMap map[string]reflect.Type

type Usage added in v0.200.0

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

func (*Usage) InputTokens added in v0.200.0

func (u *Usage) InputTokens() (int, error)

func (*Usage) OutputTokens added in v0.200.0

func (u *Usage) OutputTokens() (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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