baml

package
v0.84.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(holder *cffi.CFFIValueHolder, typeMap TypeMap) any

func DecodeList

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

func DecodeMap

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

func DecodeOptional

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

func Encode

func Encode(builder *flatbuffers.Builder, value any, typeMap TypeMap) (flatbuffers.UOffsetT, error)

Encode now accepts and passes TypeMap. Encode takes a builder and a Go value, encodes the value, wraps it in a CFFIValueHolder, and returns the offset of the holder.

func EncodeClass

func EncodeClass(builder *flatbuffers.Builder, typeMap TypeMap,
	name string, fields map[string]any, dynamicFields *map[string]any) (valueType cffi.CFFIValueUnion, offset flatbuffers.UOffsetT, err error)

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

func EncodeEnum

func EncodeEnum(builder *flatbuffers.Builder, name string, value string, isDynamic bool) (cffi.CFFIValueUnion, flatbuffers.UOffsetT, error)

encodeEnum doesn't need TypeMap internally, but the interface provides it

func EncodeRoot

func EncodeRoot(value any, typeMap TypeMap) ([]byte, error)

EncodeRoot now accepts a TypeMap. Encode takes a Go value and returns the FlatBuffers encoded bytes for a CFFIValueHolder. It creates a new builder internally.

func EncodeUnion

func EncodeUnion(builder *flatbuffers.Builder, typeMap TypeMap, variantName string, value any) (cffi.CFFIValueUnion, flatbuffers.UOffsetT, error)

encodeUnion now accepts and passes TypeMap

func InvokeRuntimeCli

func InvokeRuntimeCli(args []string) int

func SetTypeMap

func SetTypeMap(t TypeMap)

Types

type BamlClassDeserializer

type BamlClassDeserializer interface {
	Decode(holder cffi.CFFIValueClass, typeMap TypeMap)
}

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, typeMap TypeMap)
}

type BamlError

type BamlError struct {
	Message string
}

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 {
	// EncodeBamlClass returns the class name and a map of field names to values.
	// The TypeMap is provided in case the implementation needs it for nested types.
	Encode(builder *flatbuffers.Builder, typeMap TypeMap) (cffi.CFFIValueUnion, flatbuffers.UOffsetT, error)
}

BamlSerializer interface for custom class encoding

type BamlUnionDeserializer

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

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 DynamicClass

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

func (*DynamicClass) Decode

func (d *DynamicClass) Decode(holder cffi.CFFIValueClass, typeMap TypeMap)

type DynamicEnum

type DynamicEnum struct {
	Name  string
	Value string
}

func (*DynamicEnum) Decode

func (d *DynamicEnum) Decode(holder cffi.CFFIValueEnum, typeMap TypeMap)

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"`
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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