baml

package
v0.215.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0, Apache-2.0 Imports: 16 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 BAMLTESTINGONLY_InternalEncode added in v0.201.0

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

func Decode

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

func EncodeClass

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

func EncodeEnum

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

func EncodeValue added in v0.215.0

func EncodeValue(value any) (*cffi.HostValue, error)

func InvokeRuntimeCli

func InvokeRuntimeCli(args []string) int

func SetTypeMap

func SetTypeMap(t serde.TypeMap)

Types

type ASTNodeSource added in v0.204.0

type ASTNodeSource string
const (
	ASTNodeSource_Unknown     ASTNodeSource = "unknown"
	ASTNodeSource_Baml        ASTNodeSource = "baml_file"
	ASTNodeSource_TypeBuilder ASTNodeSource = "type_builder"
)

type Audio added in v0.203.0

type Audio interface {
	// contains filtered or unexported methods
}

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
	TypeBuilder    TypeBuilder
	Tags           map[string]string
}

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) CallFunctionParse added in v0.204.0

func (r *BamlRuntime) CallFunctionParse(ctx context.Context, functionName string, encoded_args []byte) (any, error)

func (*BamlRuntime) CallFunctionStream

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

func (*BamlRuntime) NewAudioFromBase64 added in v0.203.0

func (r *BamlRuntime) NewAudioFromBase64(base64 string, mimeType *string) (Audio, error)

func (*BamlRuntime) NewAudioFromUrl added in v0.203.0

func (r *BamlRuntime) NewAudioFromUrl(url string, mimeType *string) (Audio, error)

func (*BamlRuntime) NewCollector added in v0.203.0

func (r *BamlRuntime) NewCollector(name string) (Collector, error)

/ Construct Collector

func (*BamlRuntime) NewImageFromBase64 added in v0.203.0

func (r *BamlRuntime) NewImageFromBase64(base64 string, mimeType *string) (Image, error)

func (*BamlRuntime) NewImageFromUrl added in v0.203.0

func (r *BamlRuntime) NewImageFromUrl(url string, mimeType *string) (Image, error)

func (*BamlRuntime) NewPDFFromBase64 added in v0.203.0

func (r *BamlRuntime) NewPDFFromBase64(base64 string, mimeType *string) (PDF, error)

func (*BamlRuntime) NewPDFFromUrl added in v0.203.0

func (r *BamlRuntime) NewPDFFromUrl(url string, mimeType *string) (PDF, error)

func (*BamlRuntime) NewTypeBuilder added in v0.204.0

func (r *BamlRuntime) NewTypeBuilder() (TypeBuilder, error)

func (*BamlRuntime) NewVideoFromBase64 added in v0.203.0

func (r *BamlRuntime) NewVideoFromBase64(base64 string, mimeType *string) (Video, error)

func (*BamlRuntime) NewVideoFromUrl added in v0.203.0

func (r *BamlRuntime) NewVideoFromUrl(url string, mimeType *string) (Video, error)

type CallbackData

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

type Checked

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

type ClassBuilder added in v0.204.0

type ClassBuilder interface {
	raw_objects.RawPointer

	// Get the type definition for this class
	Type() (Type, error)
	// List all properties in the class
	ListProperties() ([]ClassPropertyBuilder, error)
	// Add a new property to the class
	AddProperty(name string, fieldType Type) (ClassPropertyBuilder, error)
	// Get a specific property from the class
	Property(name string) (ClassPropertyBuilder, error)
	// contains filtered or unexported methods
}

type ClassPropertyBuilder added in v0.204.0

type ClassPropertyBuilder interface {
	raw_objects.RawPointer

	// Set the type for the property
	SetType(fieldType Type) error
	// Get the type for the property
	Type() (Type, error)
	// contains filtered or unexported methods
}

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)
}

type EnumBuilder added in v0.204.0

type EnumBuilder interface {
	raw_objects.RawPointer

	// Add a new value to the enum
	AddValue(value string) (EnumValueBuilder, error)
	// Get the type definition for this enum
	Type() (Type, error)
	// List all values in the enum
	ListValues() ([]EnumValueBuilder, error)
	// Get a specific value from the enum
	Value(name string) (EnumValueBuilder, error)
	// contains filtered or unexported methods
}

type EnumValueBuilder added in v0.204.0

type EnumValueBuilder interface {
	raw_objects.RawPointer

	// Mark the enum value to be skipped
	SetSkip(skip bool) error
	// Get the skip value
	Skip() (bool, error)
	// contains filtered or unexported methods
}

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 Image added in v0.203.0

type Image interface {
	// contains filtered or unexported methods
}

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 MediaType added in v0.203.0

type MediaType string
const (
	MediaType_Image MediaType = "Image"
	MediaType_Audio MediaType = "Audio"
	MediaType_PDF   MediaType = "PDF"
	MediaType_Video MediaType = "Video"
)

type OnTickCallbackData added in v0.202.0

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

type PDF added in v0.203.0

type PDF interface {
	// contains filtered or unexported methods
}

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 Type added in v0.204.0

type Type interface {
	raw_objects.RawPointer
	serde.InternalBamlSerializer
	// Type extensions
	List() (Type, error)
	Optional() (Type, error)
	Print() string
}

type TypeBuilder added in v0.204.0

type TypeBuilder interface {
	raw_objects.RawPointer
	// Basic types
	String() (Type, error)
	Int() (Type, error)
	Float() (Type, error)
	Bool() (Type, error)
	Null() (Type, error)
	// Literal types
	LiteralString(value string) (Type, error)
	LiteralInt(value int64) (Type, error)
	LiteralBool(value bool) (Type, error)
	// Composite types
	Map(key Type, value Type) (Type, error)
	List(inner Type) (Type, error)
	Optional(inner Type) (Type, error)
	Union(types []Type) (Type, error)
	// BAML schema operations
	AddBaml(baml string) error
	// Enum operations
	AddEnum(name string) (EnumBuilder, error)
	Enum(name string) (EnumBuilder, error)
	ListEnums() ([]EnumBuilder, error)
	// Class operations
	AddClass(name string) (ClassBuilder, error)
	Class(name string) (ClassBuilder, error)
	ListClasses() ([]ClassBuilder, error)

	// Display the type builder
	Print() string
}

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)
	// CachedInputTokens returns the number of cached input tokens
	CachedInputTokens() (int64, error)
}

type Video added in v0.203.0

type Video interface {
	// contains filtered or unexported methods
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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