From 64a8d5ba5c8bb38d4fcc93094213f6921740d897 Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Mon, 19 May 2025 19:04:16 -0700 Subject: [PATCH 01/10] Add a first pass at ClientRegistry --- .../src/cffi/cffi_generated.rs | 279 +++ engine/language_client_cffi/src/ctypes.rs | 52 +- engine/language_client_cffi/src/lib.rs | 11 +- engine/language_client_cffi/types/cffi.fbs | 13 + .../src/go/templates/client.go.j2 | 25 +- .../language_client_go/pkg/cffi/CFFIClient.go | 108 + .../pkg/cffi/CFFIClientProperty.go | 108 + .../pkg/cffi/CFFIClientRegistry.go | 86 + .../pkg/cffi/CFFIFunctionArguments.go | 18 +- engine/language_client_go/pkg/encode.go | 53 + engine/language_client_go/pkg/encode_test.go | 28 +- engine/language_client_go/pkg/runtime.go | 34 +- go.mod | 6 +- go.sum | 1 + integ-tests/go/baml_client/client.go | 2208 +++++++++++++++-- integ-tests/go/go.mod | 2 +- integ-tests/go/test.go | 7 +- 17 files changed, 2844 insertions(+), 195 deletions(-) create mode 100644 engine/language_client_go/pkg/cffi/CFFIClient.go create mode 100644 engine/language_client_go/pkg/cffi/CFFIClientProperty.go create mode 100644 engine/language_client_go/pkg/cffi/CFFIClientRegistry.go diff --git a/engine/language_client_cffi/src/cffi/cffi_generated.rs b/engine/language_client_cffi/src/cffi/cffi_generated.rs index 1fff8b8068..2ce7900e05 100644 --- a/engine/language_client_cffi/src/cffi/cffi_generated.rs +++ b/engine/language_client_cffi/src/cffi/cffi_generated.rs @@ -5599,6 +5599,7 @@ impl<'a> flatbuffers::Follow<'a> for CFFIFunctionArguments<'a> { impl<'a> CFFIFunctionArguments<'a> { pub const VT_KWARGS: flatbuffers::VOffsetT = 4; + pub const VT_CLIENT_REGISTRY: flatbuffers::VOffsetT = 6; #[inline] pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { @@ -5610,6 +5611,7 @@ impl<'a> CFFIFunctionArguments<'a> { args: &'args CFFIFunctionArgumentsArgs<'args> ) -> flatbuffers::WIPOffset> { let mut builder = CFFIFunctionArgumentsBuilder::new(_fbb); + if let Some(x) = args.client_registry { builder.add_client_registry(x); } if let Some(x) = args.kwargs { builder.add_kwargs(x); } builder.finish() } @@ -5622,6 +5624,13 @@ impl<'a> CFFIFunctionArguments<'a> { // which contains a valid value in this slot unsafe { self._tab.get::>>>(CFFIFunctionArguments::VT_KWARGS, None)} } + #[inline] + pub fn client_registry(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(CFFIFunctionArguments::VT_CLIENT_REGISTRY, None)} + } } impl flatbuffers::Verifiable for CFFIFunctionArguments<'_> { @@ -5632,18 +5641,21 @@ impl flatbuffers::Verifiable for CFFIFunctionArguments<'_> { use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>>>("kwargs", Self::VT_KWARGS, false)? + .visit_field::>("client_registry", Self::VT_CLIENT_REGISTRY, false)? .finish(); Ok(()) } } pub struct CFFIFunctionArgumentsArgs<'a> { pub kwargs: Option>>>>, + pub client_registry: Option>>, } impl<'a> Default for CFFIFunctionArgumentsArgs<'a> { #[inline] fn default() -> Self { CFFIFunctionArgumentsArgs { kwargs: None, + client_registry: None, } } } @@ -5658,6 +5670,10 @@ impl<'a: 'b, 'b> CFFIFunctionArgumentsBuilder<'a, 'b> { self.fbb_.push_slot_always::>(CFFIFunctionArguments::VT_KWARGS, kwargs); } #[inline] + pub fn add_client_registry(&mut self, client_registry: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(CFFIFunctionArguments::VT_CLIENT_REGISTRY, client_registry); + } + #[inline] pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CFFIFunctionArgumentsBuilder<'a, 'b> { let start = _fbb.start_table(); CFFIFunctionArgumentsBuilder { @@ -5676,6 +5692,269 @@ impl core::fmt::Debug for CFFIFunctionArguments<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("CFFIFunctionArguments"); ds.field("kwargs", &self.kwargs()); + ds.field("client_registry", &self.client_registry()); + ds.finish() + } +} +pub enum CFFIClientRegistryOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct CFFIClientRegistry<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for CFFIClientRegistry<'a> { + type Inner = CFFIClientRegistry<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> CFFIClientRegistry<'a> { + pub const VT_PRIMARY: flatbuffers::VOffsetT = 4; + pub const VT_CLIENTS: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + CFFIClientRegistry { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args CFFIClientRegistryArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = CFFIClientRegistryBuilder::new(_fbb); + if let Some(x) = args.clients { builder.add_clients(x); } + if let Some(x) = args.primary { builder.add_primary(x); } + builder.finish() + } + + + #[inline] + pub fn primary(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(CFFIClientRegistry::VT_PRIMARY, None)} + } + #[inline] + pub fn clients(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(CFFIClientRegistry::VT_CLIENTS, None)} + } +} + +impl flatbuffers::Verifiable for CFFIClientRegistry<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("primary", Self::VT_PRIMARY, false)? + .visit_field::>>>("clients", Self::VT_CLIENTS, false)? + .finish(); + Ok(()) + } +} +pub struct CFFIClientRegistryArgs<'a> { + pub primary: Option>, + pub clients: Option>>>>, +} +impl<'a> Default for CFFIClientRegistryArgs<'a> { + #[inline] + fn default() -> Self { + CFFIClientRegistryArgs { + primary: None, + clients: None, + } + } +} + +pub struct CFFIClientRegistryBuilder<'a: 'b, 'b> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b> CFFIClientRegistryBuilder<'a, 'b> { + #[inline] + pub fn add_primary(&mut self, primary: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(CFFIClientRegistry::VT_PRIMARY, primary); + } + #[inline] + pub fn add_clients(&mut self, clients: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(CFFIClientRegistry::VT_CLIENTS, clients); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CFFIClientRegistryBuilder<'a, 'b> { + let start = _fbb.start_table(); + CFFIClientRegistryBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for CFFIClientRegistry<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("CFFIClientRegistry"); + ds.field("primary", &self.primary()); + ds.field("clients", &self.clients()); + ds.finish() + } +} +pub enum CFFIClientPropertyOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct CFFIClientProperty<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for CFFIClientProperty<'a> { + type Inner = CFFIClientProperty<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> CFFIClientProperty<'a> { + pub const VT_NAME: flatbuffers::VOffsetT = 4; + pub const VT_PROVIDER: flatbuffers::VOffsetT = 6; + pub const VT_RETRY_POLICY: flatbuffers::VOffsetT = 8; + pub const VT_OPTIONS: flatbuffers::VOffsetT = 10; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + CFFIClientProperty { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args CFFIClientPropertyArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = CFFIClientPropertyBuilder::new(_fbb); + if let Some(x) = args.options { builder.add_options(x); } + if let Some(x) = args.retry_policy { builder.add_retry_policy(x); } + if let Some(x) = args.provider { builder.add_provider(x); } + if let Some(x) = args.name { builder.add_name(x); } + builder.finish() + } + + + #[inline] + pub fn name(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(CFFIClientProperty::VT_NAME, None)} + } + #[inline] + pub fn provider(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(CFFIClientProperty::VT_PROVIDER, None)} + } + #[inline] + pub fn retry_policy(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(CFFIClientProperty::VT_RETRY_POLICY, None)} + } + #[inline] + pub fn options(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(CFFIClientProperty::VT_OPTIONS, None)} + } +} + +impl flatbuffers::Verifiable for CFFIClientProperty<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("name", Self::VT_NAME, false)? + .visit_field::>("provider", Self::VT_PROVIDER, false)? + .visit_field::>("retry_policy", Self::VT_RETRY_POLICY, false)? + .visit_field::>>>("options", Self::VT_OPTIONS, false)? + .finish(); + Ok(()) + } +} +pub struct CFFIClientPropertyArgs<'a> { + pub name: Option>, + pub provider: Option>, + pub retry_policy: Option>, + pub options: Option>>>>, +} +impl<'a> Default for CFFIClientPropertyArgs<'a> { + #[inline] + fn default() -> Self { + CFFIClientPropertyArgs { + name: None, + provider: None, + retry_policy: None, + options: None, + } + } +} + +pub struct CFFIClientPropertyBuilder<'a: 'b, 'b> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b> CFFIClientPropertyBuilder<'a, 'b> { + #[inline] + pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(CFFIClientProperty::VT_NAME, name); + } + #[inline] + pub fn add_provider(&mut self, provider: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(CFFIClientProperty::VT_PROVIDER, provider); + } + #[inline] + pub fn add_retry_policy(&mut self, retry_policy: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(CFFIClientProperty::VT_RETRY_POLICY, retry_policy); + } + #[inline] + pub fn add_options(&mut self, options: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(CFFIClientProperty::VT_OPTIONS, options); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CFFIClientPropertyBuilder<'a, 'b> { + let start = _fbb.start_table(); + CFFIClientPropertyBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for CFFIClientProperty<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("CFFIClientProperty"); + ds.field("name", &self.name()); + ds.field("provider", &self.provider()); + ds.field("retry_policy", &self.retry_policy()); + ds.field("options", &self.options()); ds.finish() } } diff --git a/engine/language_client_cffi/src/ctypes.rs b/engine/language_client_cffi/src/ctypes.rs index 6c157e2acc..963afa09fa 100644 --- a/engine/language_client_cffi/src/ctypes.rs +++ b/engine/language_client_cffi/src/ctypes.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use baml_runtime::client_registry::{ClientProperty, ClientProvider, ClientRegistry}; use baml_types::{BamlMedia, BamlValue, BamlValueWithMeta, HasFieldType, ToUnionName}; #[allow(non_snake_case)] @@ -6,6 +7,7 @@ use baml_types::{BamlMedia, BamlValue, BamlValueWithMeta, HasFieldType, ToUnionN mod cffi_generated; use cffi_generated::cffi::*; +use serde::de::Expected; use crate::BamlFunctionArguments; @@ -224,10 +226,58 @@ impl From> for BamlFunctionArguments { .into_iter() .map(|v| v.into()) .collect(); - BamlFunctionArguments { kwargs } + let client_registry = value.client_registry().map(|r| r.into()); + + BamlFunctionArguments { + kwargs, + client_registry, + } + } +} + +impl From> for ClientRegistry { + fn from(value: CFFIClientRegistry) -> Self { + let mut client_registry = ClientRegistry::new(); + value + .primary() + .map(|s| client_registry.set_primary(s.to_string())); + + value + .clients() + .expect("Failed to have CFFIClientRegistry clients") + .into_iter() + .map(|v| v.into()) + .for_each(|client| { + client_registry.add_client(client); + }); + + client_registry } } +impl From> for ClientProperty { + fn from(value: CFFIClientProperty) -> Self { + let name = value + .name() + .expect("Failed to have CFFIClientProperty name") + .to_string(); + let provider = value + .provider() + .expect("Failed to have CFFIClientProperty provider") + .parse::() + .expect("Failed to parse CFFIClientProperty provider"); + + let retry_policy = value.retry_policy().map(|r| r.to_string()); + let options = value + .options() + .expect("Failed to have CFFIClientProperty options") + .into_iter() + .map(|v| v.into()) + .collect(); + + ClientProperty::new(name, provider, retry_policy, options) + } +} impl From> for BamlValue { fn from(_value: CFFIValueChecked) -> Self { unimplemented!("CFFIValueChecked is not supported"); diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index 6d02adcb10..0962b1a389 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -4,6 +4,7 @@ mod ctypes; use std::{collections::HashMap, ffi::CStr, ptr::null, sync::Arc}; use anyhow::Result; +use baml_runtime::client_registry::ClientRegistry; use baml_runtime::{BamlRuntime, FunctionResult}; use once_cell::sync::{Lazy, OnceCell}; @@ -11,6 +12,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION"); struct BamlFunctionArguments { kwargs: baml_types::BamlMap, + client_registry: Option, } #[no_mangle] @@ -198,7 +200,14 @@ fn call_function_from_c_inner( let rt = RUNTIME.clone(); rt.spawn(async move { let (result, _) = runtime - .call_function(func_name, &function_args.kwargs, &ctx, None, None, None) + .call_function( + func_name, + &function_args.kwargs, + &ctx, + None, + function_args.client_registry.as_ref(), + None, + ) .await; safe_trigger_callback(id, true, result); }); diff --git a/engine/language_client_cffi/types/cffi.fbs b/engine/language_client_cffi/types/cffi.fbs index 920e96b772..b0612aa666 100644 --- a/engine/language_client_cffi/types/cffi.fbs +++ b/engine/language_client_cffi/types/cffi.fbs @@ -235,6 +235,19 @@ table CFFIFieldTypeStreamState { table CFFIFunctionArguments { kwargs: [CFFIMapEntry]; + client_registry: CFFIClientRegistry; +} + +table CFFIClientRegistry { + primary: string; + clients: [CFFIClientProperty]; +} + +table CFFIClientProperty { + name: string; + provider: string; + retry_policy: string; + options: [CFFIMapEntry]; } // ----------------------------------------------------------------------------- diff --git a/engine/language_client_codegen/src/go/templates/client.go.j2 b/engine/language_client_codegen/src/go/templates/client.go.j2 index dbdfcb1e2a..52fb972781 100644 --- a/engine/language_client_codegen/src/go/templates/client.go.j2 +++ b/engine/language_client_codegen/src/go/templates/client.go.j2 @@ -37,14 +37,37 @@ func castOptional[T any](result any, castResult func(any) T) *T { return &val } +type callOption struct { + clientRegistry *baml.ClientRegistry +} + +type CallOptionFunc func(*callOption) + +func WithClientRegistry(clientRegistry *baml.ClientRegistry) CallOptionFunc { + return func(o *callOption) { + o.clientRegistry = clientRegistry + } +} + + {% for fn in funcs %} func {{ fn.name }}(ctx context.Context{% for (name, type) in fn.args -%} , {{name}} {{type}} - {%- endfor %}) (*{{ fn.return_type }}, error) { + {%- endfor %}, opts ...CallOptionFunc) (*{{ fn.return_type }}, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{ {% for (name, type) in fn.args -%}"{{name}}": {{name}},{% endfor %} }, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) diff --git a/engine/language_client_go/pkg/cffi/CFFIClient.go b/engine/language_client_go/pkg/cffi/CFFIClient.go new file mode 100644 index 0000000000..8cf0341bd3 --- /dev/null +++ b/engine/language_client_go/pkg/cffi/CFFIClient.go @@ -0,0 +1,108 @@ +// Code generated by the FlatBuffers compiler. DO NOT EDIT. + +package cffi + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) + +type CFFIClient struct { + _tab flatbuffers.Table +} + +func GetRootAsCFFIClient(buf []byte, offset flatbuffers.UOffsetT) *CFFIClient { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &CFFIClient{} + x.Init(buf, n+offset) + return x +} + +func FinishCFFIClientBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) { + builder.Finish(offset) +} + +func GetSizePrefixedRootAsCFFIClient(buf []byte, offset flatbuffers.UOffsetT) *CFFIClient { + n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) + x := &CFFIClient{} + x.Init(buf, n+offset+flatbuffers.SizeUint32) + return x +} + +func FinishSizePrefixedCFFIClientBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) { + builder.FinishSizePrefixed(offset) +} + +func (rcv *CFFIClient) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *CFFIClient) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *CFFIClient) Name() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *CFFIClient) Provider() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *CFFIClient) RetryPolicy() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *CFFIClient) Options(obj *CFFIMapEntry, j int) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + return true + } + return false +} + +func (rcv *CFFIClient) OptionsLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func CFFIClientStart(builder *flatbuffers.Builder) { + builder.StartObject(4) +} +func CFFIClientAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(name), 0) +} +func CFFIClientAddProvider(builder *flatbuffers.Builder, provider flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(provider), 0) +} +func CFFIClientAddRetryPolicy(builder *flatbuffers.Builder, retryPolicy flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(retryPolicy), 0) +} +func CFFIClientAddOptions(builder *flatbuffers.Builder, options flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(3, flatbuffers.UOffsetT(options), 0) +} +func CFFIClientStartOptionsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func CFFIClientEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +} diff --git a/engine/language_client_go/pkg/cffi/CFFIClientProperty.go b/engine/language_client_go/pkg/cffi/CFFIClientProperty.go new file mode 100644 index 0000000000..9c241d0efe --- /dev/null +++ b/engine/language_client_go/pkg/cffi/CFFIClientProperty.go @@ -0,0 +1,108 @@ +// Code generated by the FlatBuffers compiler. DO NOT EDIT. + +package cffi + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) + +type CFFIClientProperty struct { + _tab flatbuffers.Table +} + +func GetRootAsCFFIClientProperty(buf []byte, offset flatbuffers.UOffsetT) *CFFIClientProperty { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &CFFIClientProperty{} + x.Init(buf, n+offset) + return x +} + +func FinishCFFIClientPropertyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) { + builder.Finish(offset) +} + +func GetSizePrefixedRootAsCFFIClientProperty(buf []byte, offset flatbuffers.UOffsetT) *CFFIClientProperty { + n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) + x := &CFFIClientProperty{} + x.Init(buf, n+offset+flatbuffers.SizeUint32) + return x +} + +func FinishSizePrefixedCFFIClientPropertyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) { + builder.FinishSizePrefixed(offset) +} + +func (rcv *CFFIClientProperty) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *CFFIClientProperty) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *CFFIClientProperty) Name() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *CFFIClientProperty) Provider() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *CFFIClientProperty) RetryPolicy() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *CFFIClientProperty) Options(obj *CFFIMapEntry, j int) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + return true + } + return false +} + +func (rcv *CFFIClientProperty) OptionsLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func CFFIClientPropertyStart(builder *flatbuffers.Builder) { + builder.StartObject(4) +} +func CFFIClientPropertyAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(name), 0) +} +func CFFIClientPropertyAddProvider(builder *flatbuffers.Builder, provider flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(provider), 0) +} +func CFFIClientPropertyAddRetryPolicy(builder *flatbuffers.Builder, retryPolicy flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(retryPolicy), 0) +} +func CFFIClientPropertyAddOptions(builder *flatbuffers.Builder, options flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(3, flatbuffers.UOffsetT(options), 0) +} +func CFFIClientPropertyStartOptionsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func CFFIClientPropertyEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +} diff --git a/engine/language_client_go/pkg/cffi/CFFIClientRegistry.go b/engine/language_client_go/pkg/cffi/CFFIClientRegistry.go new file mode 100644 index 0000000000..1236b9178a --- /dev/null +++ b/engine/language_client_go/pkg/cffi/CFFIClientRegistry.go @@ -0,0 +1,86 @@ +// Code generated by the FlatBuffers compiler. DO NOT EDIT. + +package cffi + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) + +type CFFIClientRegistry struct { + _tab flatbuffers.Table +} + +func GetRootAsCFFIClientRegistry(buf []byte, offset flatbuffers.UOffsetT) *CFFIClientRegistry { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &CFFIClientRegistry{} + x.Init(buf, n+offset) + return x +} + +func FinishCFFIClientRegistryBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) { + builder.Finish(offset) +} + +func GetSizePrefixedRootAsCFFIClientRegistry(buf []byte, offset flatbuffers.UOffsetT) *CFFIClientRegistry { + n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) + x := &CFFIClientRegistry{} + x.Init(buf, n+offset+flatbuffers.SizeUint32) + return x +} + +func FinishSizePrefixedCFFIClientRegistryBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) { + builder.FinishSizePrefixed(offset) +} + +func (rcv *CFFIClientRegistry) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *CFFIClientRegistry) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *CFFIClientRegistry) Primary() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *CFFIClientRegistry) Clients(obj *CFFIClientProperty, j int) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + return true + } + return false +} + +func (rcv *CFFIClientRegistry) ClientsLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func CFFIClientRegistryStart(builder *flatbuffers.Builder) { + builder.StartObject(2) +} +func CFFIClientRegistryAddPrimary(builder *flatbuffers.Builder, primary flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(primary), 0) +} +func CFFIClientRegistryAddClients(builder *flatbuffers.Builder, clients flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(clients), 0) +} +func CFFIClientRegistryStartClientsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func CFFIClientRegistryEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +} diff --git a/engine/language_client_go/pkg/cffi/CFFIFunctionArguments.go b/engine/language_client_go/pkg/cffi/CFFIFunctionArguments.go index d454126566..35879fcc59 100644 --- a/engine/language_client_go/pkg/cffi/CFFIFunctionArguments.go +++ b/engine/language_client_go/pkg/cffi/CFFIFunctionArguments.go @@ -61,8 +61,21 @@ func (rcv *CFFIFunctionArguments) KwargsLength() int { return 0 } +func (rcv *CFFIFunctionArguments) ClientRegistry(obj *CFFIClientRegistry) *CFFIClientRegistry { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + x := rcv._tab.Indirect(o + rcv._tab.Pos) + if obj == nil { + obj = new(CFFIClientRegistry) + } + obj.Init(rcv._tab.Bytes, x) + return obj + } + return nil +} + func CFFIFunctionArgumentsStart(builder *flatbuffers.Builder) { - builder.StartObject(1) + builder.StartObject(2) } func CFFIFunctionArgumentsAddKwargs(builder *flatbuffers.Builder, kwargs flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(kwargs), 0) @@ -70,6 +83,9 @@ func CFFIFunctionArgumentsAddKwargs(builder *flatbuffers.Builder, kwargs flatbuf func CFFIFunctionArgumentsStartKwargsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(4, numElems, 4) } +func CFFIFunctionArgumentsAddClientRegistry(builder *flatbuffers.Builder, clientRegistry flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(clientRegistry), 0) +} func CFFIFunctionArgumentsEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } diff --git a/engine/language_client_go/pkg/encode.go b/engine/language_client_go/pkg/encode.go index 0402bfeec4..592b09cd97 100644 --- a/engine/language_client_go/pkg/encode.go +++ b/engine/language_client_go/pkg/encode.go @@ -396,11 +396,64 @@ func encodeFunctionArguments(builder *flatbuffers.Builder, functionArgumentsVal return 0, fmt.Errorf("encoding function arguments: %w", err) } + var clientRegistryOffset flatbuffers.UOffsetT + if functionArgumentsVal.ClientRegistry != nil { + clientRegistryOffset, err = encodeClientRegistry(builder, functionArgumentsVal.ClientRegistry) + if err != nil { + return 0, fmt.Errorf("encoding client registry: %w", err) + } + } + cffi.CFFIFunctionArgumentsStart(builder) cffi.CFFIFunctionArgumentsAddKwargs(builder, kwargsOffset) + if clientRegistryOffset > 0 { + cffi.CFFIFunctionArgumentsAddClientRegistry(builder, clientRegistryOffset) + } + return cffi.CFFIFunctionArgumentsEnd(builder), nil } +func encodeClientRegistry(builder *flatbuffers.Builder, clientRegistryVal *ClientRegistry) (flatbuffers.UOffsetT, error) { + var primaryClientOffset flatbuffers.UOffsetT + if clientRegistryVal.primary != nil { + primaryClientOffset = builder.CreateString(*clientRegistryVal.primary) + } + + clientOffsets := make([]flatbuffers.UOffsetT, 0, len(clientRegistryVal.clients)) + if len(clientRegistryVal.clients) > 0 { + for name, client := range clientRegistryVal.clients { + nameOffset := builder.CreateString(name) + providerOffset := builder.CreateString(client.provider) + optionsOffset, err := encodeMapEntries(builder, client.options, "client options") + if err != nil { + return 0, fmt.Errorf("encoding client options: %w", err) + } + + cffi.CFFIClientPropertyStart(builder) + cffi.CFFIClientPropertyAddName(builder, nameOffset) + cffi.CFFIClientPropertyAddProvider(builder, providerOffset) + cffi.CFFIClientPropertyAddOptions(builder, optionsOffset) + clientOffset := cffi.CFFIClientPropertyEnd(builder) + clientOffsets = append(clientOffsets, clientOffset) + } + } + + cffi.CFFIClientRegistryStartClientsVector(builder, len(clientOffsets)) + for i := len(clientOffsets) - 1; i >= 0; i-- { + builder.PrependUOffsetT(clientOffsets[i]) + } + clientsVectorOffset := builder.EndVector(len(clientOffsets)) + + cffi.CFFIClientRegistryStart(builder) + if primaryClientOffset > 0 { + cffi.CFFIClientRegistryAddPrimary(builder, primaryClientOffset) + } + if clientsVectorOffset > 0 { + cffi.CFFIClientRegistryAddClients(builder, clientsVectorOffset) + } + return cffi.CFFIClientRegistryEnd(builder), nil +} + func encodeFieldType(builder *flatbuffers.Builder, fieldType reflect.Type) flatbuffers.UOffsetT { var fieldTypeOffset flatbuffers.UOffsetT var fieldTypeUnion cffi.CFFIFieldTypeUnion diff --git a/engine/language_client_go/pkg/encode_test.go b/engine/language_client_go/pkg/encode_test.go index 6e2b0d8d89..ef7803abba 100644 --- a/engine/language_client_go/pkg/encode_test.go +++ b/engine/language_client_go/pkg/encode_test.go @@ -1,13 +1,35 @@ package baml import ( + "fmt" "testing" "github.com/ghetzel/testify/require" ) func TestEncodeFunctionArguments(t *testing.T) { - args := BamlFunctionArguments{Kwargs: map[string]any{"a": "b", "c": 1, "d": 2.2, "e": true}} - _, err := EncodeRoot(args) - require.NoError(t, err) + tests := []BamlFunctionArguments{ + { + Kwargs: map[string]any{"a": "b", "c": 1, "d": 2.2, "e": true}, + }, + { + Kwargs: map[string]any{"a": "b", "c": 1, "d": 2.2, "e": true}, + ClientRegistry: &ClientRegistry{ + primary: &[]string{"a"}[0], + clients: ClientRegistryMap{ + "a": clientProperty{ + provider: "b", + options: map[string]any{"a": "b", "c": 1, "d": 2.2, "e": true}, + }, + }, + }, + }, + } + + for _, test := range tests { + t.Run(fmt.Sprintf("EncodeFunctionArguments(%v)", test), func(t *testing.T) { + _, err := EncodeRoot(test) + require.NoError(t, err) + }) + } } diff --git a/engine/language_client_go/pkg/runtime.go b/engine/language_client_go/pkg/runtime.go index a1fd1f66d9..80c747287b 100644 --- a/engine/language_client_go/pkg/runtime.go +++ b/engine/language_client_go/pkg/runtime.go @@ -24,7 +24,39 @@ type BamlRuntime struct { } type BamlFunctionArguments struct { - Kwargs map[string]any + Kwargs map[string]any + ClientRegistry *ClientRegistry +} + +type ClientRegistry struct { + primary *string + clients ClientRegistryMap +} + +type clientProperty struct { + provider string + retryPolicy string + options map[string]any +} + +type ClientRegistryMap map[string]clientProperty + +func NewClientRegistry() *ClientRegistry { + return &ClientRegistry{ + primary: nil, + clients: ClientRegistryMap{}, + } +} + +func (c *ClientRegistry) AddLlmClient(name string, provider string, options map[string]any) { + c.clients[name] = clientProperty{ + provider: provider, + options: options, + } +} + +func (c *ClientRegistry) SetPrimaryClient(name string) { + c.primary = &name } var instance *BamlRuntime diff --git a/go.mod b/go.mod index 4f0c97dd30..d7fded7f60 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,13 @@ module github.com/boundaryml/baml go 1.24.0 -require github.com/google/flatbuffers v25.2.10+incompatible +require ( + github.com/ghetzel/testify v1.4.1 + github.com/google/flatbuffers v25.2.10+incompatible +) require ( github.com/davecgh/go-spew v1.1.0 // indirect - github.com/ghetzel/testify v1.4.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v2 v2.2.2 // indirect ) diff --git a/go.sum b/go.sum index c491188fe2..b191f81e54 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,7 @@ github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZat github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/integ-tests/go/baml_client/client.go b/integ-tests/go/baml_client/client.go index c33af92ff2..2b1d92e2d6 100644 --- a/integ-tests/go/baml_client/client.go +++ b/integ-tests/go/baml_client/client.go @@ -47,10 +47,32 @@ func castOptional[T any](result any, castResult func(any) T) *T { return &val } -func AaaSamOutputFormat(ctx context.Context, recipe string) (*types.Recipe, error) { +type callOption struct { + clientRegistry *baml.ClientRegistry +} + +type CallOptionFunc func(*callOption) + +func WithClientRegistry(clientRegistry *baml.ClientRegistry) CallOptionFunc { + return func(o *callOption) { + o.clientRegistry = clientRegistry + } +} + +func AaaSamOutputFormat(ctx context.Context, recipe string, opts ...CallOptionFunc) (*types.Recipe, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"recipe": recipe}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -109,10 +131,20 @@ func (*stream) AaaSamOutputFormat(ctx context.Context, recipe string) <-chan typ return channel } -func AliasThatPointsToRecursiveType(ctx context.Context, data types.LinkedListAliasNode) (*types.LinkedListAliasNode, error) { +func AliasThatPointsToRecursiveType(ctx context.Context, data types.LinkedListAliasNode, opts ...CallOptionFunc) (*types.LinkedListAliasNode, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"data": data}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -171,10 +203,20 @@ func (*stream) AliasThatPointsToRecursiveType(ctx context.Context, data types.Li return channel } -func AliasWithMultipleAttrs(ctx context.Context, money int64) (*types.Checked[int64], error) { +func AliasWithMultipleAttrs(ctx context.Context, money int64, opts ...CallOptionFunc) (*types.Checked[int64], error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"money": money}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -233,10 +275,20 @@ func (*stream) AliasWithMultipleAttrs(ctx context.Context, money int64) <-chan t return channel } -func AliasedInputClass(ctx context.Context, input types.InputClass) (*string, error) { +func AliasedInputClass(ctx context.Context, input types.InputClass, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -295,10 +347,20 @@ func (*stream) AliasedInputClass(ctx context.Context, input types.InputClass) <- return channel } -func AliasedInputClass2(ctx context.Context, input types.InputClass) (*string, error) { +func AliasedInputClass2(ctx context.Context, input types.InputClass, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -357,10 +419,20 @@ func (*stream) AliasedInputClass2(ctx context.Context, input types.InputClass) < return channel } -func AliasedInputClassNested(ctx context.Context, input types.InputClassNested) (*string, error) { +func AliasedInputClassNested(ctx context.Context, input types.InputClassNested, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -419,10 +491,20 @@ func (*stream) AliasedInputClassNested(ctx context.Context, input types.InputCla return channel } -func AliasedInputEnum(ctx context.Context, input types.AliasedEnum) (*string, error) { +func AliasedInputEnum(ctx context.Context, input types.AliasedEnum, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -481,10 +563,20 @@ func (*stream) AliasedInputEnum(ctx context.Context, input types.AliasedEnum) <- return channel } -func AliasedInputList(ctx context.Context, input []types.AliasedEnum) (*string, error) { +func AliasedInputList(ctx context.Context, input []types.AliasedEnum, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -543,10 +635,20 @@ func (*stream) AliasedInputList(ctx context.Context, input []types.AliasedEnum) return channel } -func AllowedOptionals(ctx context.Context, optionals types.OptionalListAndMap) (*types.OptionalListAndMap, error) { +func AllowedOptionals(ctx context.Context, optionals types.OptionalListAndMap, opts ...CallOptionFunc) (*types.OptionalListAndMap, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"optionals": optionals}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -605,10 +707,20 @@ func (*stream) AllowedOptionals(ctx context.Context, optionals types.OptionalLis return channel } -func AssertFn(ctx context.Context, a int64) (*int64, error) { +func AssertFn(ctx context.Context, a int64, opts ...CallOptionFunc) (*int64, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"a": a}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -667,10 +779,20 @@ func (*stream) AssertFn(ctx context.Context, a int64) <-chan int64 { return channel } -func AudioInput(ctx context.Context, aud any) (*string, error) { +func AudioInput(ctx context.Context, aud any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"aud": aud}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -729,10 +851,20 @@ func (*stream) AudioInput(ctx context.Context, aud any) <-chan string { return channel } -func AudioInputOpenai(ctx context.Context, aud any, prompt string) (*string, error) { +func AudioInputOpenai(ctx context.Context, aud any, prompt string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"aud": aud, "prompt": prompt}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -791,10 +923,20 @@ func (*stream) AudioInputOpenai(ctx context.Context, aud any, prompt string) <-c return channel } -func BuildLinkedList(ctx context.Context, input []int64) (*types.LinkedList, error) { +func BuildLinkedList(ctx context.Context, input []int64, opts ...CallOptionFunc) (*types.LinkedList, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -853,10 +995,20 @@ func (*stream) BuildLinkedList(ctx context.Context, input []int64) <-chan types. return channel } -func BuildTree(ctx context.Context, input types.BinaryNode) (*types.Tree, error) { +func BuildTree(ctx context.Context, input types.BinaryNode, opts ...CallOptionFunc) (*types.Tree, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -915,10 +1067,20 @@ func (*stream) BuildTree(ctx context.Context, input types.BinaryNode) <-chan typ return channel } -func ClassThatPointsToRecursiveClassThroughAlias(ctx context.Context, cls types.ClassToRecAlias) (*types.ClassToRecAlias, error) { +func ClassThatPointsToRecursiveClassThroughAlias(ctx context.Context, cls types.ClassToRecAlias, opts ...CallOptionFunc) (*types.ClassToRecAlias, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"cls": cls}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -977,10 +1139,20 @@ func (*stream) ClassThatPointsToRecursiveClassThroughAlias(ctx context.Context, return channel } -func ClassifyDynEnumTwo(ctx context.Context, input string) (*types.DynEnumTwo, error) { +func ClassifyDynEnumTwo(ctx context.Context, input string, opts ...CallOptionFunc) (*types.DynEnumTwo, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1039,10 +1211,20 @@ func (*stream) ClassifyDynEnumTwo(ctx context.Context, input string) <-chan type return channel } -func ClassifyMessage(ctx context.Context, input string) (*types.Category, error) { +func ClassifyMessage(ctx context.Context, input string, opts ...CallOptionFunc) (*types.Category, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1101,10 +1283,20 @@ func (*stream) ClassifyMessage(ctx context.Context, input string) <-chan types.C return channel } -func ClassifyMessage2(ctx context.Context, input string) (*types.Category, error) { +func ClassifyMessage2(ctx context.Context, input string, opts ...CallOptionFunc) (*types.Category, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1163,10 +1355,20 @@ func (*stream) ClassifyMessage2(ctx context.Context, input string) <-chan types. return channel } -func ClassifyMessage3(ctx context.Context, input string) (*types.Category, error) { +func ClassifyMessage3(ctx context.Context, input string, opts ...CallOptionFunc) (*types.Category, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1225,10 +1427,20 @@ func (*stream) ClassifyMessage3(ctx context.Context, input string) <-chan types. return channel } -func Completion(ctx context.Context, prefix string, suffix string, language string) (*string, error) { +func Completion(ctx context.Context, prefix string, suffix string, language string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"prefix": prefix, "suffix": suffix, "language": language}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1287,10 +1499,20 @@ func (*stream) Completion(ctx context.Context, prefix string, suffix string, lan return channel } -func CustomTask(ctx context.Context, input string) (*types.Union__BookOrder__FlightConfirmation__GroceryReceipt, error) { +func CustomTask(ctx context.Context, input string, opts ...CallOptionFunc) (*types.Union__BookOrder__FlightConfirmation__GroceryReceipt, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1349,10 +1571,20 @@ func (*stream) CustomTask(ctx context.Context, input string) <-chan types.Union_ return channel } -func DescribeImage(ctx context.Context, img any) (*string, error) { +func DescribeImage(ctx context.Context, img any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"img": img}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1411,10 +1643,20 @@ func (*stream) DescribeImage(ctx context.Context, img any) <-chan string { return channel } -func DescribeImage2(ctx context.Context, classWithImage types.ClassWithImage, img2 any) (*string, error) { +func DescribeImage2(ctx context.Context, classWithImage types.ClassWithImage, img2 any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"classWithImage": classWithImage, "img2": img2}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1473,10 +1715,20 @@ func (*stream) DescribeImage2(ctx context.Context, classWithImage types.ClassWit return channel } -func DescribeImage3(ctx context.Context, classWithImage types.ClassWithImage, img2 any) (*string, error) { +func DescribeImage3(ctx context.Context, classWithImage types.ClassWithImage, img2 any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"classWithImage": classWithImage, "img2": img2}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1535,10 +1787,20 @@ func (*stream) DescribeImage3(ctx context.Context, classWithImage types.ClassWit return channel } -func DescribeImage4(ctx context.Context, classWithImage types.ClassWithImage, img2 any) (*string, error) { +func DescribeImage4(ctx context.Context, classWithImage types.ClassWithImage, img2 any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"classWithImage": classWithImage, "img2": img2}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1597,10 +1859,20 @@ func (*stream) DescribeImage4(ctx context.Context, classWithImage types.ClassWit return channel } -func DescribeMedia1599(ctx context.Context, img any, client_sector string, client_name string) (*string, error) { +func DescribeMedia1599(ctx context.Context, img any, client_sector string, client_name string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"img": img, "client_sector": client_sector, "client_name": client_name}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1659,10 +1931,20 @@ func (*stream) DescribeMedia1599(ctx context.Context, img any, client_sector str return channel } -func DifferentiateUnions(ctx context.Context) (*types.Union__OriginalA__OriginalB, error) { +func DifferentiateUnions(ctx context.Context, opts ...CallOptionFunc) (*types.Union__OriginalA__OriginalB, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1721,10 +2003,20 @@ func (*stream) DifferentiateUnions(ctx context.Context) <-chan types.Union__Orig return channel } -func DummyOutputFunction(ctx context.Context, input string) (*types.DummyOutput, error) { +func DummyOutputFunction(ctx context.Context, input string, opts ...CallOptionFunc) (*types.DummyOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1783,10 +2075,20 @@ func (*stream) DummyOutputFunction(ctx context.Context, input string) <-chan typ return channel } -func DynamicFunc(ctx context.Context, input types.DynamicClassOne) (*types.DynamicClassTwo, error) { +func DynamicFunc(ctx context.Context, input types.DynamicClassOne, opts ...CallOptionFunc) (*types.DynamicClassTwo, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1845,10 +2147,20 @@ func (*stream) DynamicFunc(ctx context.Context, input types.DynamicClassOne) <-c return channel } -func DynamicInputOutput(ctx context.Context, input types.DynInputOutput) (*types.DynInputOutput, error) { +func DynamicInputOutput(ctx context.Context, input types.DynInputOutput, opts ...CallOptionFunc) (*types.DynInputOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1907,10 +2219,20 @@ func (*stream) DynamicInputOutput(ctx context.Context, input types.DynInputOutpu return channel } -func DynamicListInputOutput(ctx context.Context, input []types.DynInputOutput) (*[]types.DynInputOutput, error) { +func DynamicListInputOutput(ctx context.Context, input []types.DynInputOutput, opts ...CallOptionFunc) (*[]types.DynInputOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -1969,10 +2291,20 @@ func (*stream) DynamicListInputOutput(ctx context.Context, input []types.DynInpu return channel } -func ExpectFailure(ctx context.Context) (*string, error) { +func ExpectFailure(ctx context.Context, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2031,10 +2363,20 @@ func (*stream) ExpectFailure(ctx context.Context) <-chan string { return channel } -func ExtractContactInfo(ctx context.Context, document string) (*types.ContactInfo, error) { +func ExtractContactInfo(ctx context.Context, document string, opts ...CallOptionFunc) (*types.ContactInfo, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"document": document}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2093,10 +2435,20 @@ func (*stream) ExtractContactInfo(ctx context.Context, document string) <-chan t return channel } -func ExtractEntities(ctx context.Context, text string) (*types.DynamicSchema, error) { +func ExtractEntities(ctx context.Context, text string, opts ...CallOptionFunc) (*types.DynamicSchema, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"text": text}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2155,10 +2507,20 @@ func (*stream) ExtractEntities(ctx context.Context, text string) <-chan types.Dy return channel } -func ExtractHobby(ctx context.Context, text string) (*[]types.Hobby, error) { +func ExtractHobby(ctx context.Context, text string, opts ...CallOptionFunc) (*[]types.Hobby, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"text": text}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2217,10 +2579,20 @@ func (*stream) ExtractHobby(ctx context.Context, text string) <-chan []types.Hob return channel } -func ExtractNames(ctx context.Context, input string) (*[]string, error) { +func ExtractNames(ctx context.Context, input string, opts ...CallOptionFunc) (*[]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2279,10 +2651,20 @@ func (*stream) ExtractNames(ctx context.Context, input string) <-chan []string { return channel } -func ExtractPeople(ctx context.Context, text string) (*[]types.Person, error) { +func ExtractPeople(ctx context.Context, text string, opts ...CallOptionFunc) (*[]types.Person, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"text": text}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2341,10 +2723,20 @@ func (*stream) ExtractPeople(ctx context.Context, text string) <-chan []types.Pe return channel } -func ExtractReceiptInfo(ctx context.Context, email string, reason types.Union__string_curiosity__string_personal_finance) (*types.ReceiptInfo, error) { +func ExtractReceiptInfo(ctx context.Context, email string, reason types.Union__string_curiosity__string_personal_finance, opts ...CallOptionFunc) (*types.ReceiptInfo, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"email": email, "reason": reason}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2403,10 +2795,20 @@ func (*stream) ExtractReceiptInfo(ctx context.Context, email string, reason type return channel } -func ExtractResume(ctx context.Context, resume string, img *any) (*types.Resume, error) { +func ExtractResume(ctx context.Context, resume string, img *any, opts ...CallOptionFunc) (*types.Resume, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"resume": resume, "img": img}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2465,10 +2867,20 @@ func (*stream) ExtractResume(ctx context.Context, resume string, img *any) <-cha return channel } -func ExtractResume2(ctx context.Context, resume string) (*types.Resume, error) { +func ExtractResume2(ctx context.Context, resume string, opts ...CallOptionFunc) (*types.Resume, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"resume": resume}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2527,10 +2939,20 @@ func (*stream) ExtractResume2(ctx context.Context, resume string) <-chan types.R return channel } -func FnClassOptionalOutput(ctx context.Context, input string) (**types.ClassOptionalOutput, error) { +func FnClassOptionalOutput(ctx context.Context, input string, opts ...CallOptionFunc) (**types.ClassOptionalOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2591,10 +3013,20 @@ func (*stream) FnClassOptionalOutput(ctx context.Context, input string) <-chan * return channel } -func FnClassOptionalOutput2(ctx context.Context, input string) (**types.ClassOptionalOutput2, error) { +func FnClassOptionalOutput2(ctx context.Context, input string, opts ...CallOptionFunc) (**types.ClassOptionalOutput2, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2655,10 +3087,20 @@ func (*stream) FnClassOptionalOutput2(ctx context.Context, input string) <-chan return channel } -func FnEnumListOutput(ctx context.Context, input string) (*[]types.EnumOutput, error) { +func FnEnumListOutput(ctx context.Context, input string, opts ...CallOptionFunc) (*[]types.EnumOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2717,10 +3159,20 @@ func (*stream) FnEnumListOutput(ctx context.Context, input string) <-chan []type return channel } -func FnEnumOutput(ctx context.Context, input string) (*types.EnumOutput, error) { +func FnEnumOutput(ctx context.Context, input string, opts ...CallOptionFunc) (*types.EnumOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2779,10 +3231,20 @@ func (*stream) FnEnumOutput(ctx context.Context, input string) <-chan types.Enum return channel } -func FnLiteralClassInputOutput(ctx context.Context, input types.LiteralClassHello) (*types.LiteralClassHello, error) { +func FnLiteralClassInputOutput(ctx context.Context, input types.LiteralClassHello, opts ...CallOptionFunc) (*types.LiteralClassHello, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2841,10 +3303,20 @@ func (*stream) FnLiteralClassInputOutput(ctx context.Context, input types.Litera return channel } -func FnLiteralUnionClassInputOutput(ctx context.Context, input types.Union__LiteralClassOne__LiteralClassTwo) (*types.Union__LiteralClassOne__LiteralClassTwo, error) { +func FnLiteralUnionClassInputOutput(ctx context.Context, input types.Union__LiteralClassOne__LiteralClassTwo, opts ...CallOptionFunc) (*types.Union__LiteralClassOne__LiteralClassTwo, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2903,10 +3375,20 @@ func (*stream) FnLiteralUnionClassInputOutput(ctx context.Context, input types.U return channel } -func FnNamedArgsSingleStringOptional(ctx context.Context, myString *string) (*string, error) { +func FnNamedArgsSingleStringOptional(ctx context.Context, myString *string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myString": myString}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -2965,10 +3447,20 @@ func (*stream) FnNamedArgsSingleStringOptional(ctx context.Context, myString *st return channel } -func FnOutputBool(ctx context.Context, input string) (*bool, error) { +func FnOutputBool(ctx context.Context, input string, opts ...CallOptionFunc) (*bool, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3027,10 +3519,20 @@ func (*stream) FnOutputBool(ctx context.Context, input string) <-chan bool { return channel } -func FnOutputClass(ctx context.Context, input string) (*types.TestOutputClass, error) { +func FnOutputClass(ctx context.Context, input string, opts ...CallOptionFunc) (*types.TestOutputClass, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3089,10 +3591,20 @@ func (*stream) FnOutputClass(ctx context.Context, input string) <-chan types.Tes return channel } -func FnOutputClassList(ctx context.Context, input string) (*[]types.TestOutputClass, error) { +func FnOutputClassList(ctx context.Context, input string, opts ...CallOptionFunc) (*[]types.TestOutputClass, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3151,10 +3663,20 @@ func (*stream) FnOutputClassList(ctx context.Context, input string) <-chan []typ return channel } -func FnOutputClassNested(ctx context.Context, input string) (*types.TestClassNested, error) { +func FnOutputClassNested(ctx context.Context, input string, opts ...CallOptionFunc) (*types.TestClassNested, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3213,10 +3735,20 @@ func (*stream) FnOutputClassNested(ctx context.Context, input string) <-chan typ return channel } -func FnOutputClassWithEnum(ctx context.Context, input string) (*types.TestClassWithEnum, error) { +func FnOutputClassWithEnum(ctx context.Context, input string, opts ...CallOptionFunc) (*types.TestClassWithEnum, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3275,10 +3807,20 @@ func (*stream) FnOutputClassWithEnum(ctx context.Context, input string) <-chan t return channel } -func FnOutputInt(ctx context.Context, input string) (*int64, error) { +func FnOutputInt(ctx context.Context, input string, opts ...CallOptionFunc) (*int64, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3337,10 +3879,20 @@ func (*stream) FnOutputInt(ctx context.Context, input string) <-chan int64 { return channel } -func FnOutputLiteralBool(ctx context.Context, input string) (*bool, error) { +func FnOutputLiteralBool(ctx context.Context, input string, opts ...CallOptionFunc) (*bool, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3399,10 +3951,20 @@ func (*stream) FnOutputLiteralBool(ctx context.Context, input string) <-chan boo return channel } -func FnOutputLiteralInt(ctx context.Context, input string) (*int, error) { +func FnOutputLiteralInt(ctx context.Context, input string, opts ...CallOptionFunc) (*int, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3461,10 +4023,20 @@ func (*stream) FnOutputLiteralInt(ctx context.Context, input string) <-chan int return channel } -func FnOutputLiteralString(ctx context.Context, input string) (*string, error) { +func FnOutputLiteralString(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3523,10 +4095,20 @@ func (*stream) FnOutputLiteralString(ctx context.Context, input string) <-chan s return channel } -func FnOutputStringList(ctx context.Context, input string) (*[]string, error) { +func FnOutputStringList(ctx context.Context, input string, opts ...CallOptionFunc) (*[]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3585,10 +4167,20 @@ func (*stream) FnOutputStringList(ctx context.Context, input string) <-chan []st return channel } -func FnTestAliasedEnumOutput(ctx context.Context, input string) (*types.TestEnum, error) { +func FnTestAliasedEnumOutput(ctx context.Context, input string, opts ...CallOptionFunc) (*types.TestEnum, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3647,10 +4239,20 @@ func (*stream) FnTestAliasedEnumOutput(ctx context.Context, input string) <-chan return channel } -func FnTestClassAlias(ctx context.Context, input string) (*types.TestClassAlias, error) { +func FnTestClassAlias(ctx context.Context, input string, opts ...CallOptionFunc) (*types.TestClassAlias, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3709,10 +4311,20 @@ func (*stream) FnTestClassAlias(ctx context.Context, input string) <-chan types. return channel } -func FnTestNamedArgsSingleEnum(ctx context.Context, myArg types.NamedArgsSingleEnum) (*string, error) { +func FnTestNamedArgsSingleEnum(ctx context.Context, myArg types.NamedArgsSingleEnum, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myArg": myArg}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3771,10 +4383,20 @@ func (*stream) FnTestNamedArgsSingleEnum(ctx context.Context, myArg types.NamedA return channel } -func GetDataType(ctx context.Context, text string) (*types.RaysData, error) { +func GetDataType(ctx context.Context, text string, opts ...CallOptionFunc) (*types.RaysData, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"text": text}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3833,10 +4455,20 @@ func (*stream) GetDataType(ctx context.Context, text string) <-chan types.RaysDa return channel } -func GetOrderInfo(ctx context.Context, email types.Email) (*types.OrderInfo, error) { +func GetOrderInfo(ctx context.Context, email types.Email, opts ...CallOptionFunc) (*types.OrderInfo, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"email": email}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3895,10 +4527,20 @@ func (*stream) GetOrderInfo(ctx context.Context, email types.Email) <-chan types return channel } -func GetQuery(ctx context.Context, query string) (*types.SearchParams, error) { +func GetQuery(ctx context.Context, query string, opts ...CallOptionFunc) (*types.SearchParams, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"query": query}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -3957,10 +4599,20 @@ func (*stream) GetQuery(ctx context.Context, query string) <-chan types.SearchPa return channel } -func InOutEnumMapKey(ctx context.Context, i1 map[types.MapKey]string, i2 map[types.MapKey]string) (*map[types.MapKey]string, error) { +func InOutEnumMapKey(ctx context.Context, i1 map[types.MapKey]string, i2 map[types.MapKey]string, opts ...CallOptionFunc) (*map[types.MapKey]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"i1": i1, "i2": i2}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4019,10 +4671,20 @@ func (*stream) InOutEnumMapKey(ctx context.Context, i1 map[types.MapKey]string, return channel } -func InOutLiteralStringUnionMapKey(ctx context.Context, i1 map[types.Union__string_one__string_two__string_three__string_four]string, i2 map[types.Union__string_one__string_two__string_three__string_four]string) (*map[types.Union__string_one__string_two__string_three__string_four]string, error) { +func InOutLiteralStringUnionMapKey(ctx context.Context, i1 map[types.Union__string_one__string_two__string_three__string_four]string, i2 map[types.Union__string_one__string_two__string_three__string_four]string, opts ...CallOptionFunc) (*map[types.Union__string_one__string_two__string_three__string_four]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"i1": i1, "i2": i2}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4081,10 +4743,20 @@ func (*stream) InOutLiteralStringUnionMapKey(ctx context.Context, i1 map[types.U return channel } -func InOutSingleLiteralStringMapKey(ctx context.Context, m map[string]string) (*map[string]string, error) { +func InOutSingleLiteralStringMapKey(ctx context.Context, m map[string]string, opts ...CallOptionFunc) (*map[string]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"m": m}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4143,10 +4815,20 @@ func (*stream) InOutSingleLiteralStringMapKey(ctx context.Context, m map[string] return channel } -func JsonTypeAliasCycle(ctx context.Context, input types.JsonValue) (*types.JsonValue, error) { +func JsonTypeAliasCycle(ctx context.Context, input types.JsonValue, opts ...CallOptionFunc) (*types.JsonValue, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4205,10 +4887,20 @@ func (*stream) JsonTypeAliasCycle(ctx context.Context, input types.JsonValue) <- return channel } -func LLMEcho(ctx context.Context, input string) (*string, error) { +func LLMEcho(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4267,10 +4959,20 @@ func (*stream) LLMEcho(ctx context.Context, input string) <-chan string { return channel } -func LiteralUnionsTest(ctx context.Context, input string) (*types.Union__int_1__bool_true__string_string_output, error) { +func LiteralUnionsTest(ctx context.Context, input string, opts ...CallOptionFunc) (*types.Union__int_1__bool_true__string_string_output, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4329,10 +5031,20 @@ func (*stream) LiteralUnionsTest(ctx context.Context, input string) <-chan types return channel } -func MakeBlockConstraint(ctx context.Context) (*types.Checked[types.BlockConstraint], error) { +func MakeBlockConstraint(ctx context.Context, opts ...CallOptionFunc) (*types.Checked[types.BlockConstraint], error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4391,10 +5103,20 @@ func (*stream) MakeBlockConstraint(ctx context.Context) <-chan types.Checked[typ return channel } -func MakeClassWithBlockDone(ctx context.Context) (*types.ClassWithBlockDone, error) { +func MakeClassWithBlockDone(ctx context.Context, opts ...CallOptionFunc) (*types.ClassWithBlockDone, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4453,10 +5175,20 @@ func (*stream) MakeClassWithBlockDone(ctx context.Context) <-chan types.ClassWit return channel } -func MakeClassWithExternalDone(ctx context.Context) (*types.ClassWithoutDone, error) { +func MakeClassWithExternalDone(ctx context.Context, opts ...CallOptionFunc) (*types.ClassWithoutDone, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4515,10 +5247,20 @@ func (*stream) MakeClassWithExternalDone(ctx context.Context) <-chan types.Class return channel } -func MakeNestedBlockConstraint(ctx context.Context) (*types.NestedBlockConstraint, error) { +func MakeNestedBlockConstraint(ctx context.Context, opts ...CallOptionFunc) (*types.NestedBlockConstraint, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4577,10 +5319,20 @@ func (*stream) MakeNestedBlockConstraint(ctx context.Context) <-chan types.Neste return channel } -func MakeSemanticContainer(ctx context.Context) (*types.SemanticContainer, error) { +func MakeSemanticContainer(ctx context.Context, opts ...CallOptionFunc) (*types.SemanticContainer, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4639,10 +5391,20 @@ func (*stream) MakeSemanticContainer(ctx context.Context) <-chan types.SemanticC return channel } -func MapAlias(ctx context.Context, m map[string][]string) (*map[string][]string, error) { +func MapAlias(ctx context.Context, m map[string][]string, opts ...CallOptionFunc) (*map[string][]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"m": m}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4701,10 +5463,20 @@ func (*stream) MapAlias(ctx context.Context, m map[string][]string) <-chan map[s return channel } -func MergeAliasAttributes(ctx context.Context, money int64) (*types.MergeAttrs, error) { +func MergeAliasAttributes(ctx context.Context, money int64, opts ...CallOptionFunc) (*types.MergeAttrs, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"money": money}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4763,10 +5535,20 @@ func (*stream) MergeAliasAttributes(ctx context.Context, money int64) <-chan typ return channel } -func MyFunc(ctx context.Context, input string) (*types.DynamicOutput, error) { +func MyFunc(ctx context.Context, input string, opts ...CallOptionFunc) (*types.DynamicOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4825,10 +5607,20 @@ func (*stream) MyFunc(ctx context.Context, input string) <-chan types.DynamicOut return channel } -func NestedAlias(ctx context.Context, c types.Union__int__string__bool__float__List__string__Map__string_List__string) (*types.Union__int__string__bool__float__List__string__Map__string_List__string, error) { +func NestedAlias(ctx context.Context, c types.Union__int__string__bool__float__List__string__Map__string_List__string, opts ...CallOptionFunc) (*types.Union__int__string__bool__float__List__string__Map__string_List__string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"c": c}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4887,10 +5679,20 @@ func (*stream) NestedAlias(ctx context.Context, c types.Union__int__string__bool return channel } -func NullLiteralClassHello(ctx context.Context, s string) (*types.ClassForNullLiteral, error) { +func NullLiteralClassHello(ctx context.Context, s string, opts ...CallOptionFunc) (*types.ClassForNullLiteral, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"s": s}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -4949,10 +5751,20 @@ func (*stream) NullLiteralClassHello(ctx context.Context, s string) <-chan types return channel } -func OpenAIWithAnthropicResponseHello(ctx context.Context, s string) (*string, error) { +func OpenAIWithAnthropicResponseHello(ctx context.Context, s string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"s": s}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5011,10 +5823,20 @@ func (*stream) OpenAIWithAnthropicResponseHello(ctx context.Context, s string) < return channel } -func OptionalTest_Function(ctx context.Context, input string) (*[]*types.OptionalTest_ReturnType, error) { +func OptionalTest_Function(ctx context.Context, input string, opts ...CallOptionFunc) (*[]*types.OptionalTest_ReturnType, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5073,10 +5895,20 @@ func (*stream) OptionalTest_Function(ctx context.Context, input string) <-chan [ return channel } -func PredictAge(ctx context.Context, name string) (*types.FooAny, error) { +func PredictAge(ctx context.Context, name string, opts ...CallOptionFunc) (*types.FooAny, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"name": name}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5135,10 +5967,20 @@ func (*stream) PredictAge(ctx context.Context, name string) <-chan types.FooAny return channel } -func PredictAgeBare(ctx context.Context, inp string) (*types.Checked[int64], error) { +func PredictAgeBare(ctx context.Context, inp string, opts ...CallOptionFunc) (*types.Checked[int64], error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"inp": inp}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5197,10 +6039,20 @@ func (*stream) PredictAgeBare(ctx context.Context, inp string) <-chan types.Chec return channel } -func PrimitiveAlias(ctx context.Context, p types.Union__int__string__bool__float) (*types.Union__int__string__bool__float, error) { +func PrimitiveAlias(ctx context.Context, p types.Union__int__string__bool__float, opts ...CallOptionFunc) (*types.Union__int__string__bool__float, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"p": p}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5259,10 +6111,20 @@ func (*stream) PrimitiveAlias(ctx context.Context, p types.Union__int__string__b return channel } -func PromptTestClaude(ctx context.Context, input string) (*string, error) { +func PromptTestClaude(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5321,10 +6183,20 @@ func (*stream) PromptTestClaude(ctx context.Context, input string) <-chan string return channel } -func PromptTestClaudeChat(ctx context.Context, input string) (*string, error) { +func PromptTestClaudeChat(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5383,10 +6255,20 @@ func (*stream) PromptTestClaudeChat(ctx context.Context, input string) <-chan st return channel } -func PromptTestClaudeChatNoSystem(ctx context.Context, input string) (*string, error) { +func PromptTestClaudeChatNoSystem(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5445,10 +6327,20 @@ func (*stream) PromptTestClaudeChatNoSystem(ctx context.Context, input string) < return channel } -func PromptTestOpenAI(ctx context.Context, input string) (*string, error) { +func PromptTestOpenAI(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5507,10 +6399,20 @@ func (*stream) PromptTestOpenAI(ctx context.Context, input string) <-chan string return channel } -func PromptTestOpenAIChat(ctx context.Context, input string) (*string, error) { +func PromptTestOpenAIChat(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5569,10 +6471,20 @@ func (*stream) PromptTestOpenAIChat(ctx context.Context, input string) <-chan st return channel } -func PromptTestOpenAIChatNoSystem(ctx context.Context, input string) (*string, error) { +func PromptTestOpenAIChatNoSystem(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5631,10 +6543,20 @@ func (*stream) PromptTestOpenAIChatNoSystem(ctx context.Context, input string) < return channel } -func PromptTestStreaming(ctx context.Context, input string) (*string, error) { +func PromptTestStreaming(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5693,10 +6615,20 @@ func (*stream) PromptTestStreaming(ctx context.Context, input string) <-chan str return channel } -func RecursiveAliasCycle(ctx context.Context, input types.RecAliasOne) (*types.RecAliasOne, error) { +func RecursiveAliasCycle(ctx context.Context, input types.RecAliasOne, opts ...CallOptionFunc) (*types.RecAliasOne, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5755,10 +6687,20 @@ func (*stream) RecursiveAliasCycle(ctx context.Context, input types.RecAliasOne) return channel } -func RecursiveClassWithAliasIndirection(ctx context.Context, cls types.NodeWithAliasIndirection) (*types.NodeWithAliasIndirection, error) { +func RecursiveClassWithAliasIndirection(ctx context.Context, cls types.NodeWithAliasIndirection, opts ...CallOptionFunc) (*types.NodeWithAliasIndirection, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"cls": cls}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5817,10 +6759,20 @@ func (*stream) RecursiveClassWithAliasIndirection(ctx context.Context, cls types return channel } -func RecursiveUnionTest(ctx context.Context, input types.RecursiveUnion) (*types.RecursiveUnion, error) { +func RecursiveUnionTest(ctx context.Context, input types.RecursiveUnion, opts ...CallOptionFunc) (*types.RecursiveUnion, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5879,10 +6831,20 @@ func (*stream) RecursiveUnionTest(ctx context.Context, input types.RecursiveUnio return channel } -func ReturnAliasWithMergedAttributes(ctx context.Context, money int64) (*types.Checked[int64], error) { +func ReturnAliasWithMergedAttributes(ctx context.Context, money int64, opts ...CallOptionFunc) (*types.Checked[int64], error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"money": money}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -5941,10 +6903,20 @@ func (*stream) ReturnAliasWithMergedAttributes(ctx context.Context, money int64) return channel } -func ReturnFailingAssert(ctx context.Context, inp int64) (*int64, error) { +func ReturnFailingAssert(ctx context.Context, inp int64, opts ...CallOptionFunc) (*int64, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"inp": inp}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6003,10 +6975,20 @@ func (*stream) ReturnFailingAssert(ctx context.Context, inp int64) <-chan int64 return channel } -func ReturnJsonEntry(ctx context.Context, s string) (*types.JsonTemplate, error) { +func ReturnJsonEntry(ctx context.Context, s string, opts ...CallOptionFunc) (*types.JsonTemplate, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"s": s}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6065,10 +7047,20 @@ func (*stream) ReturnJsonEntry(ctx context.Context, s string) <-chan types.JsonT return channel } -func ReturnMalformedConstraints(ctx context.Context, a int64) (*types.MalformedConstraints, error) { +func ReturnMalformedConstraints(ctx context.Context, a int64, opts ...CallOptionFunc) (*types.MalformedConstraints, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"a": a}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6127,10 +7119,20 @@ func (*stream) ReturnMalformedConstraints(ctx context.Context, a int64) <-chan t return channel } -func SchemaDescriptions(ctx context.Context, input string) (*types.Schema, error) { +func SchemaDescriptions(ctx context.Context, input string, opts ...CallOptionFunc) (*types.Schema, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6189,10 +7191,20 @@ func (*stream) SchemaDescriptions(ctx context.Context, input string) <-chan type return channel } -func SimpleRecursiveListAlias(ctx context.Context, input types.RecursiveListAlias) (*types.RecursiveListAlias, error) { +func SimpleRecursiveListAlias(ctx context.Context, input types.RecursiveListAlias, opts ...CallOptionFunc) (*types.RecursiveListAlias, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6251,10 +7263,20 @@ func (*stream) SimpleRecursiveListAlias(ctx context.Context, input types.Recursi return channel } -func SimpleRecursiveMapAlias(ctx context.Context, input types.RecursiveMapAlias) (*types.RecursiveMapAlias, error) { +func SimpleRecursiveMapAlias(ctx context.Context, input types.RecursiveMapAlias, opts ...CallOptionFunc) (*types.RecursiveMapAlias, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6313,10 +7335,20 @@ func (*stream) SimpleRecursiveMapAlias(ctx context.Context, input types.Recursiv return channel } -func StreamBigNumbers(ctx context.Context, digits int64) (*types.BigNumbers, error) { +func StreamBigNumbers(ctx context.Context, digits int64, opts ...CallOptionFunc) (*types.BigNumbers, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"digits": digits}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6375,10 +7407,20 @@ func (*stream) StreamBigNumbers(ctx context.Context, digits int64) <-chan types. return channel } -func StreamFailingAssertion(ctx context.Context, theme string, length int64) (*types.TwoStoriesOneTitle, error) { +func StreamFailingAssertion(ctx context.Context, theme string, length int64, opts ...CallOptionFunc) (*types.TwoStoriesOneTitle, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"theme": theme, "length": length}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6437,10 +7479,20 @@ func (*stream) StreamFailingAssertion(ctx context.Context, theme string, length return channel } -func StreamFailingCheck(ctx context.Context, theme string, length int64) (*types.TwoStoriesOneTitleCheck, error) { +func StreamFailingCheck(ctx context.Context, theme string, length int64, opts ...CallOptionFunc) (*types.TwoStoriesOneTitleCheck, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"theme": theme, "length": length}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6499,10 +7551,20 @@ func (*stream) StreamFailingCheck(ctx context.Context, theme string, length int6 return channel } -func StreamOneBigNumber(ctx context.Context, digits int64) (*int64, error) { +func StreamOneBigNumber(ctx context.Context, digits int64, opts ...CallOptionFunc) (*int64, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"digits": digits}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6561,10 +7623,20 @@ func (*stream) StreamOneBigNumber(ctx context.Context, digits int64) <-chan int6 return channel } -func StreamUnionIntegers(ctx context.Context, digits int64) (*[]types.Union__int__string, error) { +func StreamUnionIntegers(ctx context.Context, digits int64, opts ...CallOptionFunc) (*[]types.Union__int__string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"digits": digits}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6623,10 +7695,20 @@ func (*stream) StreamUnionIntegers(ctx context.Context, digits int64) <-chan []t return channel } -func StreamingCompoundNumbers(ctx context.Context, digits int64, yapping bool) (*types.CompoundBigNumbers, error) { +func StreamingCompoundNumbers(ctx context.Context, digits int64, yapping bool, opts ...CallOptionFunc) (*types.CompoundBigNumbers, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"digits": digits, "yapping": yapping}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6685,10 +7767,20 @@ func (*stream) StreamingCompoundNumbers(ctx context.Context, digits int64, yappi return channel } -func StructureDocument1559(ctx context.Context, document_txt string) (*types.Document1559, error) { +func StructureDocument1559(ctx context.Context, document_txt string, opts ...CallOptionFunc) (*types.Document1559, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"document_txt": document_txt}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6747,10 +7839,20 @@ func (*stream) StructureDocument1559(ctx context.Context, document_txt string) < return channel } -func TakeRecAliasDep(ctx context.Context, input types.RecursiveAliasDependency) (*types.RecursiveAliasDependency, error) { +func TakeRecAliasDep(ctx context.Context, input types.RecursiveAliasDependency, opts ...CallOptionFunc) (*types.RecursiveAliasDependency, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6809,10 +7911,20 @@ func (*stream) TakeRecAliasDep(ctx context.Context, input types.RecursiveAliasDe return channel } -func TellStory(ctx context.Context, story string) (*string, error) { +func TellStory(ctx context.Context, story string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"story": story}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6871,10 +7983,20 @@ func (*stream) TellStory(ctx context.Context, story string) <-chan string { return channel } -func TestAnthropic(ctx context.Context, input string) (*string, error) { +func TestAnthropic(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6933,10 +8055,20 @@ func (*stream) TestAnthropic(ctx context.Context, input string) <-chan string { return channel } -func TestAnthropicShorthand(ctx context.Context, input string) (*string, error) { +func TestAnthropicShorthand(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -6995,10 +8127,20 @@ func (*stream) TestAnthropicShorthand(ctx context.Context, input string) <-chan return channel } -func TestAws(ctx context.Context, input string) (*string, error) { +func TestAws(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7057,10 +8199,20 @@ func (*stream) TestAws(ctx context.Context, input string) <-chan string { return channel } -func TestAwsClaude37(ctx context.Context, input string) (*string, error) { +func TestAwsClaude37(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7119,10 +8271,20 @@ func (*stream) TestAwsClaude37(ctx context.Context, input string) <-chan string return channel } -func TestAwsInferenceProfile(ctx context.Context, input string) (*string, error) { +func TestAwsInferenceProfile(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7181,10 +8343,20 @@ func (*stream) TestAwsInferenceProfile(ctx context.Context, input string) <-chan return channel } -func TestAwsInvalidAccessKey(ctx context.Context, input string) (*string, error) { +func TestAwsInvalidAccessKey(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7243,10 +8415,20 @@ func (*stream) TestAwsInvalidAccessKey(ctx context.Context, input string) <-chan return channel } -func TestAwsInvalidProfile(ctx context.Context, input string) (*string, error) { +func TestAwsInvalidProfile(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7305,10 +8487,20 @@ func (*stream) TestAwsInvalidProfile(ctx context.Context, input string) <-chan s return channel } -func TestAwsInvalidRegion(ctx context.Context, input string) (*string, error) { +func TestAwsInvalidRegion(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7367,10 +8559,20 @@ func (*stream) TestAwsInvalidRegion(ctx context.Context, input string) <-chan st return channel } -func TestAwsInvalidSessionToken(ctx context.Context, input string) (*string, error) { +func TestAwsInvalidSessionToken(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7429,10 +8631,20 @@ func (*stream) TestAwsInvalidSessionToken(ctx context.Context, input string) <-c return channel } -func TestAzure(ctx context.Context, input string) (*string, error) { +func TestAzure(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7491,10 +8703,20 @@ func (*stream) TestAzure(ctx context.Context, input string) <-chan string { return channel } -func TestAzureFailure(ctx context.Context, input string) (*string, error) { +func TestAzureFailure(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7553,10 +8775,20 @@ func (*stream) TestAzureFailure(ctx context.Context, input string) <-chan string return channel } -func TestAzureO1NoMaxTokens(ctx context.Context, input string) (*string, error) { +func TestAzureO1NoMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7615,10 +8847,20 @@ func (*stream) TestAzureO1NoMaxTokens(ctx context.Context, input string) <-chan return channel } -func TestAzureO1WithMaxCompletionTokens(ctx context.Context, input string) (*string, error) { +func TestAzureO1WithMaxCompletionTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7677,10 +8919,20 @@ func (*stream) TestAzureO1WithMaxCompletionTokens(ctx context.Context, input str return channel } -func TestAzureO1WithMaxTokens(ctx context.Context, input string) (*string, error) { +func TestAzureO1WithMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7739,10 +8991,20 @@ func (*stream) TestAzureO1WithMaxTokens(ctx context.Context, input string) <-cha return channel } -func TestAzureO3NoMaxTokens(ctx context.Context, input string) (*string, error) { +func TestAzureO3NoMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7801,10 +9063,20 @@ func (*stream) TestAzureO3NoMaxTokens(ctx context.Context, input string) <-chan return channel } -func TestAzureO3WithMaxCompletionTokens(ctx context.Context, input string) (*string, error) { +func TestAzureO3WithMaxCompletionTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7863,10 +9135,20 @@ func (*stream) TestAzureO3WithMaxCompletionTokens(ctx context.Context, input str return channel } -func TestAzureWithMaxTokens(ctx context.Context, input string) (*string, error) { +func TestAzureWithMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7925,10 +9207,20 @@ func (*stream) TestAzureWithMaxTokens(ctx context.Context, input string) <-chan return channel } -func TestCaching(ctx context.Context, input string, not_cached string) (*string, error) { +func TestCaching(ctx context.Context, input string, not_cached string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input, "not_cached": not_cached}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -7987,10 +9279,20 @@ func (*stream) TestCaching(ctx context.Context, input string, not_cached string) return channel } -func TestFallbackClient(ctx context.Context) (*string, error) { +func TestFallbackClient(ctx context.Context, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8049,10 +9351,20 @@ func (*stream) TestFallbackClient(ctx context.Context) <-chan string { return channel } -func TestFallbackStrategy(ctx context.Context, input string) (*string, error) { +func TestFallbackStrategy(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8111,10 +9423,20 @@ func (*stream) TestFallbackStrategy(ctx context.Context, input string) <-chan st return channel } -func TestFallbackToShorthand(ctx context.Context, input string) (*string, error) { +func TestFallbackToShorthand(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8173,10 +9495,20 @@ func (*stream) TestFallbackToShorthand(ctx context.Context, input string) <-chan return channel } -func TestFnNamedArgsSingleBool(ctx context.Context, myBool bool) (*string, error) { +func TestFnNamedArgsSingleBool(ctx context.Context, myBool bool, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myBool": myBool}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8235,10 +9567,20 @@ func (*stream) TestFnNamedArgsSingleBool(ctx context.Context, myBool bool) <-cha return channel } -func TestFnNamedArgsSingleClass(ctx context.Context, myArg types.NamedArgsSingleClass) (*string, error) { +func TestFnNamedArgsSingleClass(ctx context.Context, myArg types.NamedArgsSingleClass, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myArg": myArg}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8297,10 +9639,20 @@ func (*stream) TestFnNamedArgsSingleClass(ctx context.Context, myArg types.Named return channel } -func TestFnNamedArgsSingleEnumList(ctx context.Context, myArg []types.NamedArgsSingleEnumList) (*string, error) { +func TestFnNamedArgsSingleEnumList(ctx context.Context, myArg []types.NamedArgsSingleEnumList, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myArg": myArg}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8359,10 +9711,20 @@ func (*stream) TestFnNamedArgsSingleEnumList(ctx context.Context, myArg []types. return channel } -func TestFnNamedArgsSingleFloat(ctx context.Context, myFloat float64) (*string, error) { +func TestFnNamedArgsSingleFloat(ctx context.Context, myFloat float64, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myFloat": myFloat}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8421,10 +9783,20 @@ func (*stream) TestFnNamedArgsSingleFloat(ctx context.Context, myFloat float64) return channel } -func TestFnNamedArgsSingleInt(ctx context.Context, myInt int64) (*string, error) { +func TestFnNamedArgsSingleInt(ctx context.Context, myInt int64, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myInt": myInt}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8483,10 +9855,20 @@ func (*stream) TestFnNamedArgsSingleInt(ctx context.Context, myInt int64) <-chan return channel } -func TestFnNamedArgsSingleMapStringToClass(ctx context.Context, myMap map[string]types.StringToClassEntry) (*map[string]types.StringToClassEntry, error) { +func TestFnNamedArgsSingleMapStringToClass(ctx context.Context, myMap map[string]types.StringToClassEntry, opts ...CallOptionFunc) (*map[string]types.StringToClassEntry, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myMap": myMap}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8545,10 +9927,20 @@ func (*stream) TestFnNamedArgsSingleMapStringToClass(ctx context.Context, myMap return channel } -func TestFnNamedArgsSingleMapStringToMap(ctx context.Context, myMap map[string]map[string]string) (*map[string]map[string]string, error) { +func TestFnNamedArgsSingleMapStringToMap(ctx context.Context, myMap map[string]map[string]string, opts ...CallOptionFunc) (*map[string]map[string]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myMap": myMap}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8607,10 +9999,20 @@ func (*stream) TestFnNamedArgsSingleMapStringToMap(ctx context.Context, myMap ma return channel } -func TestFnNamedArgsSingleMapStringToString(ctx context.Context, myMap map[string]string) (*map[string]string, error) { +func TestFnNamedArgsSingleMapStringToString(ctx context.Context, myMap map[string]string, opts ...CallOptionFunc) (*map[string]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myMap": myMap}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8669,10 +10071,20 @@ func (*stream) TestFnNamedArgsSingleMapStringToString(ctx context.Context, myMap return channel } -func TestFnNamedArgsSingleString(ctx context.Context, myString string) (*string, error) { +func TestFnNamedArgsSingleString(ctx context.Context, myString string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myString": myString}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8731,10 +10143,20 @@ func (*stream) TestFnNamedArgsSingleString(ctx context.Context, myString string) return channel } -func TestFnNamedArgsSingleStringArray(ctx context.Context, myStringArray []string) (*string, error) { +func TestFnNamedArgsSingleStringArray(ctx context.Context, myStringArray []string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myStringArray": myStringArray}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8793,10 +10215,20 @@ func (*stream) TestFnNamedArgsSingleStringArray(ctx context.Context, myStringArr return channel } -func TestFnNamedArgsSingleStringList(ctx context.Context, myArg []string) (*[]string, error) { +func TestFnNamedArgsSingleStringList(ctx context.Context, myArg []string, opts ...CallOptionFunc) (*[]string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myArg": myArg}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8855,10 +10287,20 @@ func (*stream) TestFnNamedArgsSingleStringList(ctx context.Context, myArg []stri return channel } -func TestGemini(ctx context.Context, input string) (*string, error) { +func TestGemini(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8917,10 +10359,20 @@ func (*stream) TestGemini(ctx context.Context, input string) <-chan string { return channel } -func TestGeminiOpenAiGeneric(ctx context.Context) (*string, error) { +func TestGeminiOpenAiGeneric(ctx context.Context, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -8979,10 +10431,20 @@ func (*stream) TestGeminiOpenAiGeneric(ctx context.Context) <-chan string { return channel } -func TestGeminiSystem(ctx context.Context, input string) (*string, error) { +func TestGeminiSystem(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9041,10 +10503,20 @@ func (*stream) TestGeminiSystem(ctx context.Context, input string) <-chan string return channel } -func TestGeminiSystemAsChat(ctx context.Context, input string) (*string, error) { +func TestGeminiSystemAsChat(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9103,10 +10575,20 @@ func (*stream) TestGeminiSystemAsChat(ctx context.Context, input string) <-chan return channel } -func TestGroq(ctx context.Context, input string) (*string, error) { +func TestGroq(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9165,10 +10647,20 @@ func (*stream) TestGroq(ctx context.Context, input string) <-chan string { return channel } -func TestImageInput(ctx context.Context, img any) (*string, error) { +func TestImageInput(ctx context.Context, img any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"img": img}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9227,10 +10719,20 @@ func (*stream) TestImageInput(ctx context.Context, img any) <-chan string { return channel } -func TestImageInputAnthropic(ctx context.Context, img any) (*string, error) { +func TestImageInputAnthropic(ctx context.Context, img any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"img": img}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9289,10 +10791,20 @@ func (*stream) TestImageInputAnthropic(ctx context.Context, img any) <-chan stri return channel } -func TestImageListInput(ctx context.Context, imgs []any) (*string, error) { +func TestImageListInput(ctx context.Context, imgs []any, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"imgs": imgs}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9351,10 +10863,20 @@ func (*stream) TestImageListInput(ctx context.Context, imgs []any) <-chan string return channel } -func TestMemory(ctx context.Context, input string) (*types.TestMemoryOutput, error) { +func TestMemory(ctx context.Context, input string, opts ...CallOptionFunc) (*types.TestMemoryOutput, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9413,10 +10935,20 @@ func (*stream) TestMemory(ctx context.Context, input string) <-chan types.TestMe return channel } -func TestMulticlassNamedArgs(ctx context.Context, myArg types.NamedArgsSingleClass, myArg2 types.NamedArgsSingleClass) (*string, error) { +func TestMulticlassNamedArgs(ctx context.Context, myArg types.NamedArgsSingleClass, myArg2 types.NamedArgsSingleClass, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myArg": myArg, "myArg2": myArg2}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9475,10 +11007,20 @@ func (*stream) TestMulticlassNamedArgs(ctx context.Context, myArg types.NamedArg return channel } -func TestNamedArgsLiteralBool(ctx context.Context, myBool bool) (*string, error) { +func TestNamedArgsLiteralBool(ctx context.Context, myBool bool, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myBool": myBool}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9537,10 +11079,20 @@ func (*stream) TestNamedArgsLiteralBool(ctx context.Context, myBool bool) <-chan return channel } -func TestNamedArgsLiteralInt(ctx context.Context, myInt int) (*string, error) { +func TestNamedArgsLiteralInt(ctx context.Context, myInt int, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myInt": myInt}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9599,10 +11151,20 @@ func (*stream) TestNamedArgsLiteralInt(ctx context.Context, myInt int) <-chan st return channel } -func TestNamedArgsLiteralString(ctx context.Context, myString string) (*string, error) { +func TestNamedArgsLiteralString(ctx context.Context, myString string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"myString": myString}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9661,10 +11223,20 @@ func (*stream) TestNamedArgsLiteralString(ctx context.Context, myString string) return channel } -func TestOllama(ctx context.Context, input string) (**string, error) { +func TestOllama(ctx context.Context, input string, opts ...CallOptionFunc) (**string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9725,10 +11297,20 @@ func (*stream) TestOllama(ctx context.Context, input string) <-chan *string { return channel } -func TestOllamaHaiku(ctx context.Context, input string) (*types.Haiku, error) { +func TestOllamaHaiku(ctx context.Context, input string, opts ...CallOptionFunc) (*types.Haiku, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9787,10 +11369,20 @@ func (*stream) TestOllamaHaiku(ctx context.Context, input string) <-chan types.H return channel } -func TestOpenAI(ctx context.Context, input string) (*string, error) { +func TestOpenAI(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9849,10 +11441,20 @@ func (*stream) TestOpenAI(ctx context.Context, input string) <-chan string { return channel } -func TestOpenAIDummyClient(ctx context.Context, input string) (*string, error) { +func TestOpenAIDummyClient(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9911,10 +11513,20 @@ func (*stream) TestOpenAIDummyClient(ctx context.Context, input string) <-chan s return channel } -func TestOpenAIGPT4oMini(ctx context.Context, input string) (*string, error) { +func TestOpenAIGPT4oMini(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -9973,10 +11585,20 @@ func (*stream) TestOpenAIGPT4oMini(ctx context.Context, input string) <-chan str return channel } -func TestOpenAILegacyProvider(ctx context.Context, input string) (*string, error) { +func TestOpenAILegacyProvider(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10035,10 +11657,20 @@ func (*stream) TestOpenAILegacyProvider(ctx context.Context, input string) <-cha return channel } -func TestOpenAIO1NoMaxTokens(ctx context.Context, input string) (*string, error) { +func TestOpenAIO1NoMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10097,10 +11729,20 @@ func (*stream) TestOpenAIO1NoMaxTokens(ctx context.Context, input string) <-chan return channel } -func TestOpenAIO1WithMaxCompletionTokens(ctx context.Context, input string) (*string, error) { +func TestOpenAIO1WithMaxCompletionTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10159,10 +11801,20 @@ func (*stream) TestOpenAIO1WithMaxCompletionTokens(ctx context.Context, input st return channel } -func TestOpenAIO1WithMaxTokens(ctx context.Context, input string) (*string, error) { +func TestOpenAIO1WithMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10221,10 +11873,20 @@ func (*stream) TestOpenAIO1WithMaxTokens(ctx context.Context, input string) <-ch return channel } -func TestOpenAIShorthand(ctx context.Context, input string) (*string, error) { +func TestOpenAIShorthand(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10283,10 +11945,20 @@ func (*stream) TestOpenAIShorthand(ctx context.Context, input string) <-chan str return channel } -func TestOpenAIWithFinishReasonError(ctx context.Context, input string) (*string, error) { +func TestOpenAIWithFinishReasonError(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10345,10 +12017,20 @@ func (*stream) TestOpenAIWithFinishReasonError(ctx context.Context, input string return channel } -func TestOpenAIWithMaxTokens(ctx context.Context, input string) (*string, error) { +func TestOpenAIWithMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10407,10 +12089,20 @@ func (*stream) TestOpenAIWithMaxTokens(ctx context.Context, input string) <-chan return channel } -func TestOpenAIWithNullMaxTokens(ctx context.Context, input string) (*string, error) { +func TestOpenAIWithNullMaxTokens(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10469,10 +12161,20 @@ func (*stream) TestOpenAIWithNullMaxTokens(ctx context.Context, input string) <- return channel } -func TestOpenRouterMistralSmall3_1_24b(ctx context.Context, input string) (*string, error) { +func TestOpenRouterMistralSmall3_1_24b(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10531,10 +12233,20 @@ func (*stream) TestOpenRouterMistralSmall3_1_24b(ctx context.Context, input stri return channel } -func TestRetryConstant(ctx context.Context) (*string, error) { +func TestRetryConstant(ctx context.Context, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10593,10 +12305,20 @@ func (*stream) TestRetryConstant(ctx context.Context) <-chan string { return channel } -func TestRetryExponential(ctx context.Context) (*string, error) { +func TestRetryExponential(ctx context.Context, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10655,10 +12377,20 @@ func (*stream) TestRetryExponential(ctx context.Context) <-chan string { return channel } -func TestRoundRobinStrategy(ctx context.Context, input string) (*string, error) { +func TestRoundRobinStrategy(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10717,10 +12449,20 @@ func (*stream) TestRoundRobinStrategy(ctx context.Context, input string) <-chan return channel } -func TestSingleFallbackClient(ctx context.Context) (*string, error) { +func TestSingleFallbackClient(ctx context.Context, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10779,10 +12521,20 @@ func (*stream) TestSingleFallbackClient(ctx context.Context) <-chan string { return channel } -func TestThinking(ctx context.Context, input string) (*types.CustomStory, error) { +func TestThinking(ctx context.Context, input string, opts ...CallOptionFunc) (*types.CustomStory, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10841,10 +12593,20 @@ func (*stream) TestThinking(ctx context.Context, input string) <-chan types.Cust return channel } -func TestUniverseQuestion(ctx context.Context, question types.UniverseQuestionInput) (*types.UniverseQuestion, error) { +func TestUniverseQuestion(ctx context.Context, question types.UniverseQuestionInput, opts ...CallOptionFunc) (*types.UniverseQuestion, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"question": question}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10903,10 +12665,20 @@ func (*stream) TestUniverseQuestion(ctx context.Context, question types.Universe return channel } -func TestVertex(ctx context.Context, input string) (*string, error) { +func TestVertex(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -10965,10 +12737,20 @@ func (*stream) TestVertex(ctx context.Context, input string) <-chan string { return channel } -func TestVertexClaude(ctx context.Context, input string) (*string, error) { +func TestVertexClaude(ctx context.Context, input string, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -11027,10 +12809,20 @@ func (*stream) TestVertexClaude(ctx context.Context, input string) <-chan string return channel } -func TestVertexWithSystemInstructions(ctx context.Context) (*string, error) { +func TestVertexWithSystemInstructions(ctx context.Context, opts ...CallOptionFunc) (*string, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -11089,10 +12881,20 @@ func (*stream) TestVertexWithSystemInstructions(ctx context.Context) <-chan stri return channel } -func UnionTest_Function(ctx context.Context, input types.Union__string__bool) (*types.UnionTest_ReturnType, error) { +func UnionTest_Function(ctx context.Context, input types.Union__string__bool, opts ...CallOptionFunc) (*types.UnionTest_ReturnType, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -11151,10 +12953,20 @@ func (*stream) UnionTest_Function(ctx context.Context, input types.Union__string return channel } -func UseBlockConstraint(ctx context.Context, inp types.BlockConstraintForParam) (*int64, error) { +func UseBlockConstraint(ctx context.Context, inp types.BlockConstraintForParam, opts ...CallOptionFunc) (*int64, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"inp": inp}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -11213,10 +13025,20 @@ func (*stream) UseBlockConstraint(ctx context.Context, inp types.BlockConstraint return channel } -func UseMaintainFieldOrder(ctx context.Context, input types.MaintainFieldOrder) (*types.MaintainFieldOrder, error) { +func UseMaintainFieldOrder(ctx context.Context, input types.MaintainFieldOrder, opts ...CallOptionFunc) (*types.MaintainFieldOrder, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"input": input}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -11275,10 +13097,20 @@ func (*stream) UseMaintainFieldOrder(ctx context.Context, input types.MaintainFi return channel } -func UseMalformedConstraints(ctx context.Context, a types.MalformedConstraints2) (*int64, error) { +func UseMalformedConstraints(ctx context.Context, a types.MalformedConstraints2, opts ...CallOptionFunc) (*int64, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"a": a}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) @@ -11337,10 +13169,20 @@ func (*stream) UseMalformedConstraints(ctx context.Context, a types.MalformedCon return channel } -func UseNestedBlockConstraint(ctx context.Context, inp types.NestedBlockConstraintForParam) (*int64, error) { +func UseNestedBlockConstraint(ctx context.Context, inp types.NestedBlockConstraintForParam, opts ...CallOptionFunc) (*int64, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"inp": inp}, } + + var callOpts callOption + for _, opt := range opts { + opt(&callOpts) + } + + if callOpts.clientRegistry != nil { + args.ClientRegistry = callOpts.clientRegistry + } + encoded, err := baml.EncodeRoot(args) if err != nil { panic(err) diff --git a/integ-tests/go/go.mod b/integ-tests/go/go.mod index beb32146ea..9b06b83263 100644 --- a/integ-tests/go/go.mod +++ b/integ-tests/go/go.mod @@ -3,7 +3,7 @@ module example.com/integ-tests go 1.24.0 require ( - github.com/boundaryml/baml v0.2.0 + github.com/boundaryml/baml v0.88.0 github.com/ghetzel/testify v1.4.1 github.com/google/flatbuffers v25.2.10+incompatible ) diff --git a/integ-tests/go/test.go b/integ-tests/go/test.go index 47bcca8ead..ad88fc52d5 100644 --- a/integ-tests/go/test.go +++ b/integ-tests/go/test.go @@ -5,12 +5,17 @@ import ( "fmt" b "example.com/integ-tests/baml_client" + baml "github.com/boundaryml/baml/engine/language_client_go/pkg" ) func main() { ctx := context.Background() - v2, err := b.AaaSamOutputFormat(ctx, "oranges") + registry := baml.NewClientRegistry() + registry.AddLlmClient("a", "openai", map[string]any{"a": "b"}) + registry.SetPrimaryClient("a") + + v2, err := b.AaaSamOutputFormat(ctx, "oranges", b.WithClientRegistry(registry)) if err != nil { panic(err) } From ebfdae283903bc0794b7ad0eef7446db054ccc9d Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Wed, 21 May 2025 17:50:47 -0700 Subject: [PATCH 02/10] [Go] Collector --- engine/language_client_cffi/build.rs | 2 +- engine/language_client_cffi/src/lib.rs | 128 +++++- .../src/go/templates/client.go.j2 | 12 +- .../baml_go/baml_cffi_wrapper.c | 3 +- .../baml_go/baml_cffi_wrapper.h | 5 +- engine/language_client_go/baml_go/exports.go | 31 +- engine/language_client_go/baml_go/lib.go | 3 + .../include/baml_cffi_generated.h | 8 +- engine/language_client_go/pkg/collector.go | 71 ++++ engine/language_client_go/pkg/encode_test.go | 2 +- engine/language_client_go/pkg/runtime.go | 15 +- integ-tests/go/baml_client/client.go | 376 +++++++++--------- integ-tests/go/test.go | 16 +- 13 files changed, 469 insertions(+), 203 deletions(-) create mode 100644 engine/language_client_go/pkg/collector.go diff --git a/engine/language_client_cffi/build.rs b/engine/language_client_cffi/build.rs index 8a7a356c9d..3112409bab 100644 --- a/engine/language_client_cffi/build.rs +++ b/engine/language_client_cffi/build.rs @@ -1,4 +1,4 @@ -use std::{path::Path, process::Command}; +use std::path::Path; use cbindgen; use flatc::flatc; diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index 0962b1a389..3ffb0285d8 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -1,13 +1,14 @@ /// cbindgen:ignore mod ctypes; +use std::ops::Deref; use std::{collections::HashMap, ffi::CStr, ptr::null, sync::Arc}; use anyhow::Result; use baml_runtime::client_registry::ClientRegistry; +use baml_runtime::tracingv2::storage::storage::{Collector, Usage}; use baml_runtime::{BamlRuntime, FunctionResult}; use once_cell::sync::{Lazy, OnceCell}; - const VERSION: &str = env!("CARGO_PKG_VERSION"); struct BamlFunctionArguments { @@ -162,8 +163,18 @@ pub extern "C" fn call_function_from_c( encoded_args: *const libc::c_char, length: usize, id: u32, + collectors: *const libc::c_void, + collectors_length: usize, ) -> *const libc::c_void { - match call_function_from_c_inner(runtime, function_name, encoded_args, length, id) { + match call_function_from_c_inner( + runtime, + function_name, + encoded_args, + length, + id, + collectors, + collectors_length, + ) { Ok(_) => null(), Err(e) => { Box::into_raw(Box::new(CString::new(e.to_string()).unwrap())) as *const libc::c_void @@ -177,6 +188,8 @@ fn call_function_from_c_inner( encoded_args: *const libc::c_char, length: usize, id: u32, + collectors: *const libc::c_void, + collectors_length: usize, ) -> Result<()> { // Safety: assume that the pointers provided are valid. let runtime = unsafe { &*(runtime as *const BamlRuntime) }; @@ -193,6 +206,22 @@ fn call_function_from_c_inner( let buffer = unsafe { std::slice::from_raw_parts(encoded_args as *const u8, length) }; let function_args = ctypes::buffer_to_cffi_function_arguments(buffer)?; + let collector_ptrs = collectors as *const *const libc::c_void; + let collectors = match collectors_length { + 0 => None, + _ => Some( + unsafe { std::slice::from_raw_parts(collector_ptrs, collectors_length) } + .iter() + .map(|c| unsafe { + let collector = Arc::from_raw(*c as *const Collector); + let clone = collector.clone(); + let _ = Arc::into_raw(clone); + collector + }) + .collect::>(), + ), + }; + let ctx = runtime.create_ctx_manager(BamlValue::String("cffi".to_string()), None); // Spawn an async task to await the future and call the callback when done. @@ -206,7 +235,7 @@ fn call_function_from_c_inner( &ctx, None, function_args.client_registry.as_ref(), - None, + collectors, ) .await; safe_trigger_callback(id, true, result); @@ -279,3 +308,96 @@ fn call_function_stream_from_c_inner( fn on_event(id: u32, result: FunctionResult) { safe_trigger_callback(id, true, Ok(result)); } + +#[no_mangle] +pub extern "C" fn call_collector_function( + object: *const libc::c_void, + object_type: *const c_char, + function_name: *const c_char, +) -> *const libc::c_void { + match call_collector_function_inner(object, object_type, function_name) { + Ok(result) => result, + Err(e) => { + Box::into_raw(Box::new(CString::new(e.to_string()).unwrap())) as *const libc::c_void + } + } +} + +fn call_collector_function_inner( + object: *const libc::c_void, + object_type: *const c_char, + function_name: *const c_char, +) -> Result<*const libc::c_void> { + let object_type = match unsafe { CStr::from_ptr(object_type) }.to_str() { + Ok(s) => s.to_owned(), + Err(_) => { + return Err(anyhow::anyhow!("Failed to convert object type to string")); + } + }; + + let function_name = match unsafe { CStr::from_ptr(function_name) }.to_str() { + Ok(s) => s.to_owned(), + Err(_) => { + return Err(anyhow::anyhow!("Failed to convert function name to string")); + } + }; + + if object.is_null() { + return match (object_type.as_str(), function_name.as_str()) { + ("collector", "new") => { + let collector = Collector::new(None); + Ok(Arc::into_raw(Arc::new(collector)) as *const libc::c_void) + } + _ => Err(anyhow::anyhow!( + "Failed to call collector function: {}", + function_name + )), + }; + } + + match object_type.as_str() { + "collector" => { + let collector = unsafe { Arc::from_raw(object as *const Collector) }; + let clone = collector.clone(); + let _ = Arc::into_raw(clone); + + match function_name.as_str() { + "destroy" => { + let _ = collector.deref(); + Ok(null()) + } + "usage" => { + let usage = collector.usage(); + Ok(Box::into_raw(Box::new(usage)) as *const libc::c_void) + } + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } + "usage" => { + let usage = unsafe { Box::from_raw(object as *mut Usage) }; + + match function_name.as_str() { + "destroy" => { + let _ = drop(usage); + Ok(null()) + } + "input_tokens" => Ok(usage.input_tokens.unwrap_or_default() as *mut libc::c_void), + "output_tokens" => Ok(usage.output_tokens.unwrap_or_default() as *mut libc::c_void), + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } +} diff --git a/engine/language_client_codegen/src/go/templates/client.go.j2 b/engine/language_client_codegen/src/go/templates/client.go.j2 index 3c46ab0bd6..75f9843b9d 100644 --- a/engine/language_client_codegen/src/go/templates/client.go.j2 +++ b/engine/language_client_codegen/src/go/templates/client.go.j2 @@ -39,6 +39,7 @@ func castOptional[T any](result any, castResult func(any) T) *T { type callOption struct { clientRegistry *baml.ClientRegistry + collectors []*baml.Collector } type CallOptionFunc func(*callOption) @@ -49,6 +50,15 @@ func WithClientRegistry(clientRegistry *baml.ClientRegistry) CallOptionFunc { } } +func WithCollector(collector *baml.Collector) CallOptionFunc { + return func(o *callOption) { + if o.collectors == nil { + o.collectors = []*baml.Collector{} + } + o.collectors = append(o.collectors, collector) + } +} + {% macro return_type_name(fn) -%} {% if fn.return_type.is_slice || fn.return_type.is_map -%} {{ fn.return_type.name }} @@ -79,7 +89,7 @@ func {{ fn.name }}(ctx context.Context{% for (name, type) in fn.args -%} if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "{{ fn.name }}", encoded) + result, err := bamlRuntime.CallFunction(ctx, "{{ fn.name }}", encoded, callOpts.collectors) if err != nil { return nil, err } diff --git a/engine/language_client_go/baml_go/baml_cffi_wrapper.c b/engine/language_client_go/baml_go/baml_cffi_wrapper.c index 7b4dfdd0c6..17c5779e8d 100644 --- a/engine/language_client_go/baml_go/baml_cffi_wrapper.c +++ b/engine/language_client_go/baml_go/baml_cffi_wrapper.c @@ -20,5 +20,6 @@ DEFINE_WRAPPER_FUNCTIONS(const void *, CreateBamlRuntime, (const char *root_path DEFINE_WRAPPER_FUNCTIONS(void, DestroyBamlRuntime, (const void *runtime), (runtime), ) DEFINE_WRAPPER_FUNCTIONS(int, InvokeRuntimeCli, (const char *const *args), (args), -1) DEFINE_WRAPPER_FUNCTIONS(void, RegisterCallbacks, (CallbackFn callback_fn, CallbackFn error_callback_fn), (callback_fn, error_callback_fn), ) -DEFINE_WRAPPER_FUNCTIONS(const void *, CallFunctionFromC, (const void *runtime, const char *function_name, const char *encoded_args, uintptr_t length, uint32_t id), (runtime, function_name, encoded_args, length, id), NULL) +DEFINE_WRAPPER_FUNCTIONS(const void *, CallFunctionFromC, (const void *runtime, const char *function_name, const char *encoded_args, uintptr_t length, uint32_t id, const void *const *collectors, uint32_t collectors_length), (runtime, function_name, encoded_args, length, id, collectors, collectors_length), NULL) DEFINE_WRAPPER_FUNCTIONS(const void *, CallFunctionStreamFromC, (const void *runtime, const char *function_name, const char *encoded_args, uintptr_t length, uint32_t id), (runtime, function_name, encoded_args, length, id), NULL) +DEFINE_WRAPPER_FUNCTIONS(const void *, CallCollectorFunction, (const void *object, const char *object_type, const char *function_name), (object, object_type, function_name), NULL) diff --git a/engine/language_client_go/baml_go/baml_cffi_wrapper.h b/engine/language_client_go/baml_go/baml_cffi_wrapper.h index 8dfe0b7f88..5d07e7c31d 100644 --- a/engine/language_client_go/baml_go/baml_cffi_wrapper.h +++ b/engine/language_client_go/baml_go/baml_cffi_wrapper.h @@ -23,9 +23,12 @@ void SetRegisterCallbacksFn(void *fn); void WrapRegisterCallbacks(CallbackFn callback_fn, CallbackFn error_callback_fn); void SetCallFunctionFromCFn(void *fn); -const void *WrapCallFunctionFromC(const void *runtime, const char *function_name, const char *encoded_args, uintptr_t length, uint32_t id); +const void *WrapCallFunctionFromC(const void *runtime, const char *function_name, const char *encoded_args, uintptr_t length, uint32_t id, const void *const *collectors, uint32_t collectors_length); void SetCallFunctionStreamFromCFn(void *fn); const void *WrapCallFunctionStreamFromC(const void *runtime, const char *function_name, const char *encoded_args, uintptr_t length, uint32_t id); +void SetCallCollectorFunctionFn(void *fn); +const void *WrapCallCollectorFunction(const void *object, const char *object_type, const char *function_name); + #endif // BAML_CFFI_WRAPPER_H diff --git a/engine/language_client_go/baml_go/exports.go b/engine/language_client_go/baml_go/exports.go index 2daa9cfb5a..8043fc93c7 100644 --- a/engine/language_client_go/baml_go/exports.go +++ b/engine/language_client_go/baml_go/exports.go @@ -62,13 +62,28 @@ func RegisterCallbacks(callbackFn unsafe.Pointer, errorFn unsafe.Pointer) error return nil } -func CallFunctionFromC(runtime unsafe.Pointer, functionName string, encodedArgs []byte, id uint32) (unsafe.Pointer, error) { +func CallFunctionFromC(runtime unsafe.Pointer, functionName string, encodedArgs []byte, id uint32, collectors []unsafe.Pointer) (unsafe.Pointer, error) { cFunctionName := C.CString(functionName) defer C.free(unsafe.Pointer(cFunctionName)) cEncodedArgs := (*C.char)(unsafe.Pointer(&encodedArgs[0])) - result := C.WrapCallFunctionFromC(runtime, cFunctionName, cEncodedArgs, C.uintptr_t(len(encodedArgs)), C.uint32_t(id)) + fmt.Printf("collectors: len=%d\n", len(collectors)) + for i, c := range collectors { + fmt.Printf(" [%d] ptr=%p\n", i, c) + } + + cCollectorArraySize := C.size_t(len(collectors)) * C.size_t(unsafe.Sizeof(uintptr(0))) + cCollectorArray := C.malloc(cCollectorArraySize) + defer C.free(cCollectorArray) + + // Copy Go pointers into C array + collectorSlice := (*[1 << 30]unsafe.Pointer)(cCollectorArray)[:len(collectors):len(collectors)] + for i, ptr := range collectors { + collectorSlice[i] = ptr + } + + result := C.WrapCallFunctionFromC(runtime, cFunctionName, cEncodedArgs, C.uintptr_t(len(encodedArgs)), C.uint32_t(id), (*unsafe.Pointer)(cCollectorArray), C.uint32_t(len(collectors))) return result, nil } @@ -83,3 +98,15 @@ func CallFunctionStreamFromC(runtime unsafe.Pointer, functionName string, encode return result, nil } + +func CallCollectorFunction(object unsafe.Pointer, objectType string, functionName string) (unsafe.Pointer, error) { + cObjectType := C.CString(objectType) + defer C.free(unsafe.Pointer(cObjectType)) + + cFunctionName := C.CString(functionName) + defer C.free(unsafe.Pointer(cFunctionName)) + + pointer := C.WrapCallCollectorFunction(object, cObjectType, cFunctionName) + + return pointer, nil +} diff --git a/engine/language_client_go/baml_go/lib.go b/engine/language_client_go/baml_go/lib.go index 1ce1e1f446..ba2a289013 100644 --- a/engine/language_client_go/baml_go/lib.go +++ b/engine/language_client_go/baml_go/lib.go @@ -143,6 +143,7 @@ func initializeBaml() error { lib.registerFn("register_callbacks") lib.registerFn("call_function_from_c") lib.registerFn("call_function_stream_from_c") + lib.registerFn("call_collector_function") }() if symbolLookupErr != nil { @@ -186,6 +187,8 @@ func (l *library) registerFn(fnName string) { C.SetCallFunctionFromCFn(fnPtr) case "call_function_stream_from_c": C.SetCallFunctionStreamFromCFn(fnPtr) + case "call_collector_function": + C.SetCallCollectorFunctionFn(fnPtr) default: panic(fmt.Sprintf("internal error: attempted to register unknown function '%s'", fnName)) } diff --git a/engine/language_client_go/include/baml_cffi_generated.h b/engine/language_client_go/include/baml_cffi_generated.h index 9dd33549d4..fcd5637160 100644 --- a/engine/language_client_go/include/baml_cffi_generated.h +++ b/engine/language_client_go/include/baml_cffi_generated.h @@ -36,7 +36,9 @@ const void *call_function_from_c(const void *runtime, const char *function_name, const char *encoded_args, uintptr_t length, - uint32_t id); + uint32_t id, + const void *collectors, + uintptr_t collectors_length); /** * Extern "C" function that returns immediately, scheduling the async call. @@ -47,3 +49,7 @@ const void *call_function_stream_from_c(const void *runtime, const char *encoded_args, uintptr_t length, uint32_t id); + +const void *call_collector_function(const void *object, + const char *object_type, + const char *function_name); diff --git a/engine/language_client_go/pkg/collector.go b/engine/language_client_go/pkg/collector.go new file mode 100644 index 0000000000..8fa58d8dc9 --- /dev/null +++ b/engine/language_client_go/pkg/collector.go @@ -0,0 +1,71 @@ +package baml + +import ( + "runtime" + "unsafe" + + "github.com/boundaryml/baml/engine/language_client_go/baml_go" +) + +type Collector struct { + c unsafe.Pointer +} + +type Usage struct { + c unsafe.Pointer +} + +const collectorType = "collector" +const usageType = "usage" + +func NewCollector() *Collector { + collectorPtr, err := baml_go.CallCollectorFunction(nil, collectorType, "new") + if err != nil { + panic(err) + } + + collector := &Collector{ + c: collectorPtr, + } + + runtime.AddCleanup(collector, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, collectorType, "destroy") + }, collector.c) + + return collector +} + +func (c *Collector) Usage() (*Usage, error) { + usagePtr, err := baml_go.CallCollectorFunction(c.c, collectorType, "usage") + if err != nil { + return nil, err + } + + usage := &Usage{ + c: usagePtr, + } + + runtime.AddCleanup(usage, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, collectorType, "destroy") + }, usage.c) + + return usage, nil +} + +func (u *Usage) InputTokens() (int, error) { + inputTokensPtr, err := baml_go.CallCollectorFunction(u.c, usageType, "input_tokens") + if err != nil { + return 0, err + } + + return int(uintptr(unsafe.Pointer(inputTokensPtr))), nil +} + +func (u *Usage) OutputTokens() (int, error) { + outputTokensPtr, err := baml_go.CallCollectorFunction(u.c, usageType, "output_tokens") + if err != nil { + return 0, err + } + + return int(uintptr(unsafe.Pointer(outputTokensPtr))), nil +} diff --git a/engine/language_client_go/pkg/encode_test.go b/engine/language_client_go/pkg/encode_test.go index ef7803abba..8b05d88051 100644 --- a/engine/language_client_go/pkg/encode_test.go +++ b/engine/language_client_go/pkg/encode_test.go @@ -16,7 +16,7 @@ func TestEncodeFunctionArguments(t *testing.T) { Kwargs: map[string]any{"a": "b", "c": 1, "d": 2.2, "e": true}, ClientRegistry: &ClientRegistry{ primary: &[]string{"a"}[0], - clients: ClientRegistryMap{ + clients: clientRegistryMap{ "a": clientProperty{ provider: "b", options: map[string]any{"a": "b", "c": 1, "d": 2.2, "e": true}, diff --git a/engine/language_client_go/pkg/runtime.go b/engine/language_client_go/pkg/runtime.go index 80c747287b..d755c09ab6 100644 --- a/engine/language_client_go/pkg/runtime.go +++ b/engine/language_client_go/pkg/runtime.go @@ -30,7 +30,7 @@ type BamlFunctionArguments struct { type ClientRegistry struct { primary *string - clients ClientRegistryMap + clients clientRegistryMap } type clientProperty struct { @@ -39,12 +39,12 @@ type clientProperty struct { options map[string]any } -type ClientRegistryMap map[string]clientProperty +type clientRegistryMap map[string]clientProperty func NewClientRegistry() *ClientRegistry { return &ClientRegistry{ primary: nil, - clients: ClientRegistryMap{}, + clients: clientRegistryMap{}, } } @@ -106,7 +106,7 @@ func CreateRuntime( return BamlRuntime{runtime: runtime}, nil } -func (r *BamlRuntime) CallFunction(ctx context.Context, functionName string, encoded_args []byte) (*ResultCallback, error) { +func (r *BamlRuntime) CallFunction(ctx context.Context, functionName string, encoded_args []byte, collectors []*Collector) (*ResultCallback, error) { callback_id, callback := create_unique_id(ctx) return_channel := make(chan ResultCallback) go func() { @@ -123,7 +123,12 @@ func (r *BamlRuntime) CallFunction(ctx context.Context, functionName string, enc } }() - _, err := baml_go.CallFunctionFromC(r.runtime, functionName, encoded_args, callback_id) + collectorPointers := make([]unsafe.Pointer, len(collectors)) + for i, collector := range collectors { + collectorPointers[i] = collector.c + } + + _, err := baml_go.CallFunctionFromC(r.runtime, functionName, encoded_args, callback_id, collectorPointers) if err != nil { close(return_channel) return nil, err diff --git a/integ-tests/go/baml_client/client.go b/integ-tests/go/baml_client/client.go index aae2fb48b7..d9ab4b1cd1 100644 --- a/integ-tests/go/baml_client/client.go +++ b/integ-tests/go/baml_client/client.go @@ -49,6 +49,7 @@ func castOptional[T any](result any, castResult func(any) T) *T { type callOption struct { clientRegistry *baml.ClientRegistry + collectors []*baml.Collector } type CallOptionFunc func(*callOption) @@ -59,6 +60,15 @@ func WithClientRegistry(clientRegistry *baml.ClientRegistry) CallOptionFunc { } } +func WithCollector(collector *baml.Collector) CallOptionFunc { + return func(o *callOption) { + if o.collectors == nil { + o.collectors = []*baml.Collector{} + } + o.collectors = append(o.collectors, collector) + } +} + func AaaSamOutputFormat(ctx context.Context, recipe string, opts ...CallOptionFunc) (*types.Recipe, error) { args := baml.BamlFunctionArguments{ Kwargs: map[string]any{"recipe": recipe}, @@ -77,7 +87,7 @@ func AaaSamOutputFormat(ctx context.Context, recipe string, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AaaSamOutputFormat", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AaaSamOutputFormat", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -149,7 +159,7 @@ func AliasThatPointsToRecursiveType(ctx context.Context, data types.LinkedListAl if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AliasThatPointsToRecursiveType", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AliasThatPointsToRecursiveType", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -221,7 +231,7 @@ func AliasWithMultipleAttrs(ctx context.Context, money int64, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AliasWithMultipleAttrs", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AliasWithMultipleAttrs", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -293,7 +303,7 @@ func AliasedInputClass(ctx context.Context, input types.InputClass, opts ...Call if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AliasedInputClass", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AliasedInputClass", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -365,7 +375,7 @@ func AliasedInputClass2(ctx context.Context, input types.InputClass, opts ...Cal if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AliasedInputClass2", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AliasedInputClass2", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -437,7 +447,7 @@ func AliasedInputClassNested(ctx context.Context, input types.InputClassNested, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AliasedInputClassNested", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AliasedInputClassNested", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -509,7 +519,7 @@ func AliasedInputEnum(ctx context.Context, input types.AliasedEnum, opts ...Call if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AliasedInputEnum", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AliasedInputEnum", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -581,7 +591,7 @@ func AliasedInputList(ctx context.Context, input []types.AliasedEnum, opts ...Ca if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AliasedInputList", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AliasedInputList", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -653,7 +663,7 @@ func AllowedOptionals(ctx context.Context, optionals types.OptionalListAndMap, o if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AllowedOptionals", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AllowedOptionals", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -725,7 +735,7 @@ func AssertFn(ctx context.Context, a int64, opts ...CallOptionFunc) (*int64, err if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AssertFn", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AssertFn", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -797,7 +807,7 @@ func AudioInput(ctx context.Context, aud any, opts ...CallOptionFunc) (*string, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AudioInput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AudioInput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -869,7 +879,7 @@ func AudioInputOpenai(ctx context.Context, aud any, prompt string, opts ...CallO if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "AudioInputOpenai", encoded) + result, err := bamlRuntime.CallFunction(ctx, "AudioInputOpenai", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -941,7 +951,7 @@ func BuildLinkedList(ctx context.Context, input []int64, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "BuildLinkedList", encoded) + result, err := bamlRuntime.CallFunction(ctx, "BuildLinkedList", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1013,7 +1023,7 @@ func BuildTree(ctx context.Context, input types.BinaryNode, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "BuildTree", encoded) + result, err := bamlRuntime.CallFunction(ctx, "BuildTree", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1085,7 +1095,7 @@ func ClassThatPointsToRecursiveClassThroughAlias(ctx context.Context, cls types. if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ClassThatPointsToRecursiveClassThroughAlias", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ClassThatPointsToRecursiveClassThroughAlias", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1157,7 +1167,7 @@ func ClassifyDynEnumTwo(ctx context.Context, input string, opts ...CallOptionFun if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ClassifyDynEnumTwo", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ClassifyDynEnumTwo", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1229,7 +1239,7 @@ func ClassifyMessage(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ClassifyMessage", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ClassifyMessage", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1301,7 +1311,7 @@ func ClassifyMessage2(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ClassifyMessage2", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ClassifyMessage2", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1373,7 +1383,7 @@ func ClassifyMessage3(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ClassifyMessage3", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ClassifyMessage3", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1445,7 +1455,7 @@ func Completion(ctx context.Context, prefix string, suffix string, language stri if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "Completion", encoded) + result, err := bamlRuntime.CallFunction(ctx, "Completion", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1517,7 +1527,7 @@ func CustomTask(ctx context.Context, input string, opts ...CallOptionFunc) (*typ if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "CustomTask", encoded) + result, err := bamlRuntime.CallFunction(ctx, "CustomTask", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1589,7 +1599,7 @@ func DescribeImage(ctx context.Context, img any, opts ...CallOptionFunc) (*strin if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DescribeImage", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DescribeImage", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1661,7 +1671,7 @@ func DescribeImage2(ctx context.Context, classWithImage types.ClassWithImage, im if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DescribeImage2", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DescribeImage2", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1733,7 +1743,7 @@ func DescribeImage3(ctx context.Context, classWithImage types.ClassWithImage, im if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DescribeImage3", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DescribeImage3", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1805,7 +1815,7 @@ func DescribeImage4(ctx context.Context, classWithImage types.ClassWithImage, im if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DescribeImage4", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DescribeImage4", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1877,7 +1887,7 @@ func DescribeMedia1599(ctx context.Context, img any, client_sector string, clien if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DescribeMedia1599", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DescribeMedia1599", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -1949,7 +1959,7 @@ func DifferentiateUnions(ctx context.Context, opts ...CallOptionFunc) (*types.Un if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DifferentiateUnions", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DifferentiateUnions", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2021,7 +2031,7 @@ func DummyOutputFunction(ctx context.Context, input string, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DummyOutputFunction", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DummyOutputFunction", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2093,7 +2103,7 @@ func DynamicFunc(ctx context.Context, input types.DynamicClassOne, opts ...CallO if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DynamicFunc", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DynamicFunc", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2165,7 +2175,7 @@ func DynamicInputOutput(ctx context.Context, input types.DynInputOutput, opts .. if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DynamicInputOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DynamicInputOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2237,7 +2247,7 @@ func DynamicListInputOutput(ctx context.Context, input []types.DynInputOutput, o if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "DynamicListInputOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "DynamicListInputOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2309,7 +2319,7 @@ func ExpectFailure(ctx context.Context, opts ...CallOptionFunc) (*string, error) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExpectFailure", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExpectFailure", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2381,7 +2391,7 @@ func ExtractContactInfo(ctx context.Context, document string, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractContactInfo", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractContactInfo", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2453,7 +2463,7 @@ func ExtractEntities(ctx context.Context, text string, opts ...CallOptionFunc) ( if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractEntities", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractEntities", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2525,7 +2535,7 @@ func ExtractHobby(ctx context.Context, text string, opts ...CallOptionFunc) ([]t if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractHobby", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractHobby", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2597,7 +2607,7 @@ func ExtractNames(ctx context.Context, input string, opts ...CallOptionFunc) ([] if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractNames", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractNames", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2669,7 +2679,7 @@ func ExtractPeople(ctx context.Context, text string, opts ...CallOptionFunc) ([] if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractPeople", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractPeople", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2741,7 +2751,7 @@ func ExtractReceiptInfo(ctx context.Context, email string, reason types.Union__s if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractReceiptInfo", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractReceiptInfo", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2813,7 +2823,7 @@ func ExtractResume(ctx context.Context, resume string, img *any, opts ...CallOpt if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractResume", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractResume", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2885,7 +2895,7 @@ func ExtractResume2(ctx context.Context, resume string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ExtractResume2", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ExtractResume2", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -2957,7 +2967,7 @@ func FnClassOptionalOutput(ctx context.Context, input string, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnClassOptionalOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnClassOptionalOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3031,7 +3041,7 @@ func FnClassOptionalOutput2(ctx context.Context, input string, opts ...CallOptio if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnClassOptionalOutput2", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnClassOptionalOutput2", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3105,7 +3115,7 @@ func FnEnumListOutput(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnEnumListOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnEnumListOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3177,7 +3187,7 @@ func FnEnumOutput(ctx context.Context, input string, opts ...CallOptionFunc) (*t if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnEnumOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnEnumOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3249,7 +3259,7 @@ func FnLiteralClassInputOutput(ctx context.Context, input types.LiteralClassHell if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnLiteralClassInputOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnLiteralClassInputOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3321,7 +3331,7 @@ func FnLiteralUnionClassInputOutput(ctx context.Context, input types.Union__Lite if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnLiteralUnionClassInputOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnLiteralUnionClassInputOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3393,7 +3403,7 @@ func FnNamedArgsSingleStringOptional(ctx context.Context, myString *string, opts if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnNamedArgsSingleStringOptional", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnNamedArgsSingleStringOptional", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3465,7 +3475,7 @@ func FnOutputBool(ctx context.Context, input string, opts ...CallOptionFunc) (*b if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputBool", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputBool", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3537,7 +3547,7 @@ func FnOutputClass(ctx context.Context, input string, opts ...CallOptionFunc) (* if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputClass", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputClass", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3609,7 +3619,7 @@ func FnOutputClassList(ctx context.Context, input string, opts ...CallOptionFunc if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputClassList", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputClassList", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3681,7 +3691,7 @@ func FnOutputClassNested(ctx context.Context, input string, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputClassNested", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputClassNested", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3753,7 +3763,7 @@ func FnOutputClassWithEnum(ctx context.Context, input string, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputClassWithEnum", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputClassWithEnum", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3825,7 +3835,7 @@ func FnOutputInt(ctx context.Context, input string, opts ...CallOptionFunc) (*in if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputInt", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputInt", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3897,7 +3907,7 @@ func FnOutputLiteralBool(ctx context.Context, input string, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputLiteralBool", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputLiteralBool", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -3969,7 +3979,7 @@ func FnOutputLiteralInt(ctx context.Context, input string, opts ...CallOptionFun if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputLiteralInt", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputLiteralInt", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4041,7 +4051,7 @@ func FnOutputLiteralString(ctx context.Context, input string, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputLiteralString", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputLiteralString", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4113,7 +4123,7 @@ func FnOutputStringList(ctx context.Context, input string, opts ...CallOptionFun if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnOutputStringList", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnOutputStringList", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4185,7 +4195,7 @@ func FnTestAliasedEnumOutput(ctx context.Context, input string, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnTestAliasedEnumOutput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnTestAliasedEnumOutput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4257,7 +4267,7 @@ func FnTestClassAlias(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnTestClassAlias", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnTestClassAlias", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4329,7 +4339,7 @@ func FnTestNamedArgsSingleEnum(ctx context.Context, myArg types.NamedArgsSingleE if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "FnTestNamedArgsSingleEnum", encoded) + result, err := bamlRuntime.CallFunction(ctx, "FnTestNamedArgsSingleEnum", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4401,7 +4411,7 @@ func GetDataType(ctx context.Context, text string, opts ...CallOptionFunc) (*typ if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "GetDataType", encoded) + result, err := bamlRuntime.CallFunction(ctx, "GetDataType", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4473,7 +4483,7 @@ func GetOrderInfo(ctx context.Context, email types.Email, opts ...CallOptionFunc if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "GetOrderInfo", encoded) + result, err := bamlRuntime.CallFunction(ctx, "GetOrderInfo", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4545,7 +4555,7 @@ func GetQuery(ctx context.Context, query string, opts ...CallOptionFunc) (*types if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "GetQuery", encoded) + result, err := bamlRuntime.CallFunction(ctx, "GetQuery", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4617,7 +4627,7 @@ func InOutEnumMapKey(ctx context.Context, i1 map[types.MapKey]string, i2 map[typ if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "InOutEnumMapKey", encoded) + result, err := bamlRuntime.CallFunction(ctx, "InOutEnumMapKey", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4689,7 +4699,7 @@ func InOutLiteralStringUnionMapKey(ctx context.Context, i1 map[types.Union__stri if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "InOutLiteralStringUnionMapKey", encoded) + result, err := bamlRuntime.CallFunction(ctx, "InOutLiteralStringUnionMapKey", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4761,7 +4771,7 @@ func InOutSingleLiteralStringMapKey(ctx context.Context, m map[string]string, op if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "InOutSingleLiteralStringMapKey", encoded) + result, err := bamlRuntime.CallFunction(ctx, "InOutSingleLiteralStringMapKey", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4833,7 +4843,7 @@ func JsonTypeAliasCycle(ctx context.Context, input types.JsonValue, opts ...Call if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "JsonTypeAliasCycle", encoded) + result, err := bamlRuntime.CallFunction(ctx, "JsonTypeAliasCycle", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4905,7 +4915,7 @@ func LLMEcho(ctx context.Context, input string, opts ...CallOptionFunc) (*string if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "LLMEcho", encoded) + result, err := bamlRuntime.CallFunction(ctx, "LLMEcho", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -4977,7 +4987,7 @@ func LiteralUnionsTest(ctx context.Context, input string, opts ...CallOptionFunc if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "LiteralUnionsTest", encoded) + result, err := bamlRuntime.CallFunction(ctx, "LiteralUnionsTest", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5049,7 +5059,7 @@ func MakeBlockConstraint(ctx context.Context, opts ...CallOptionFunc) (*types.Ch if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MakeBlockConstraint", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MakeBlockConstraint", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5121,7 +5131,7 @@ func MakeClassWithBlockDone(ctx context.Context, opts ...CallOptionFunc) (*types if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MakeClassWithBlockDone", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MakeClassWithBlockDone", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5193,7 +5203,7 @@ func MakeClassWithExternalDone(ctx context.Context, opts ...CallOptionFunc) (*ty if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MakeClassWithExternalDone", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MakeClassWithExternalDone", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5265,7 +5275,7 @@ func MakeNestedBlockConstraint(ctx context.Context, opts ...CallOptionFunc) (*ty if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MakeNestedBlockConstraint", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MakeNestedBlockConstraint", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5337,7 +5347,7 @@ func MakeSemanticContainer(ctx context.Context, opts ...CallOptionFunc) (*types. if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MakeSemanticContainer", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MakeSemanticContainer", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5409,7 +5419,7 @@ func MapAlias(ctx context.Context, m map[string][]string, opts ...CallOptionFunc if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MapAlias", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MapAlias", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5481,7 +5491,7 @@ func MergeAliasAttributes(ctx context.Context, money int64, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MergeAliasAttributes", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MergeAliasAttributes", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5553,7 +5563,7 @@ func MyFunc(ctx context.Context, input string, opts ...CallOptionFunc) (*types.D if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "MyFunc", encoded) + result, err := bamlRuntime.CallFunction(ctx, "MyFunc", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5625,7 +5635,7 @@ func NestedAlias(ctx context.Context, c types.Union__int__string__bool__float__L if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "NestedAlias", encoded) + result, err := bamlRuntime.CallFunction(ctx, "NestedAlias", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5697,7 +5707,7 @@ func NullLiteralClassHello(ctx context.Context, s string, opts ...CallOptionFunc if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "NullLiteralClassHello", encoded) + result, err := bamlRuntime.CallFunction(ctx, "NullLiteralClassHello", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5769,7 +5779,7 @@ func OpenAIWithAnthropicResponseHello(ctx context.Context, s string, opts ...Cal if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "OpenAIWithAnthropicResponseHello", encoded) + result, err := bamlRuntime.CallFunction(ctx, "OpenAIWithAnthropicResponseHello", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5841,7 +5851,7 @@ func OptionalTest_Function(ctx context.Context, input string, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "OptionalTest_Function", encoded) + result, err := bamlRuntime.CallFunction(ctx, "OptionalTest_Function", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5913,7 +5923,7 @@ func PredictAge(ctx context.Context, name string, opts ...CallOptionFunc) (*type if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PredictAge", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PredictAge", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -5985,7 +5995,7 @@ func PredictAgeBare(ctx context.Context, inp string, opts ...CallOptionFunc) (*t if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PredictAgeBare", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PredictAgeBare", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6057,7 +6067,7 @@ func PrimitiveAlias(ctx context.Context, p types.Union__int__string__bool__float if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PrimitiveAlias", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PrimitiveAlias", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6129,7 +6139,7 @@ func PromptTestClaude(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PromptTestClaude", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PromptTestClaude", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6201,7 +6211,7 @@ func PromptTestClaudeChat(ctx context.Context, input string, opts ...CallOptionF if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PromptTestClaudeChat", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PromptTestClaudeChat", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6273,7 +6283,7 @@ func PromptTestClaudeChatNoSystem(ctx context.Context, input string, opts ...Cal if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PromptTestClaudeChatNoSystem", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PromptTestClaudeChatNoSystem", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6345,7 +6355,7 @@ func PromptTestOpenAI(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PromptTestOpenAI", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PromptTestOpenAI", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6417,7 +6427,7 @@ func PromptTestOpenAIChat(ctx context.Context, input string, opts ...CallOptionF if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PromptTestOpenAIChat", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PromptTestOpenAIChat", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6489,7 +6499,7 @@ func PromptTestOpenAIChatNoSystem(ctx context.Context, input string, opts ...Cal if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PromptTestOpenAIChatNoSystem", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PromptTestOpenAIChatNoSystem", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6561,7 +6571,7 @@ func PromptTestStreaming(ctx context.Context, input string, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "PromptTestStreaming", encoded) + result, err := bamlRuntime.CallFunction(ctx, "PromptTestStreaming", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6633,7 +6643,7 @@ func RecursiveAliasCycle(ctx context.Context, input types.RecAliasOne, opts ...C if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "RecursiveAliasCycle", encoded) + result, err := bamlRuntime.CallFunction(ctx, "RecursiveAliasCycle", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6705,7 +6715,7 @@ func RecursiveClassWithAliasIndirection(ctx context.Context, cls types.NodeWithA if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "RecursiveClassWithAliasIndirection", encoded) + result, err := bamlRuntime.CallFunction(ctx, "RecursiveClassWithAliasIndirection", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6777,7 +6787,7 @@ func RecursiveUnionTest(ctx context.Context, input types.RecursiveUnion, opts .. if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "RecursiveUnionTest", encoded) + result, err := bamlRuntime.CallFunction(ctx, "RecursiveUnionTest", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6849,7 +6859,7 @@ func ReturnAliasWithMergedAttributes(ctx context.Context, money int64, opts ...C if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ReturnAliasWithMergedAttributes", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ReturnAliasWithMergedAttributes", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6921,7 +6931,7 @@ func ReturnFailingAssert(ctx context.Context, inp int64, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ReturnFailingAssert", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ReturnFailingAssert", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -6993,7 +7003,7 @@ func ReturnJsonEntry(ctx context.Context, s string, opts ...CallOptionFunc) (*ty if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ReturnJsonEntry", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ReturnJsonEntry", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7065,7 +7075,7 @@ func ReturnMalformedConstraints(ctx context.Context, a int64, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "ReturnMalformedConstraints", encoded) + result, err := bamlRuntime.CallFunction(ctx, "ReturnMalformedConstraints", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7137,7 +7147,7 @@ func SchemaDescriptions(ctx context.Context, input string, opts ...CallOptionFun if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "SchemaDescriptions", encoded) + result, err := bamlRuntime.CallFunction(ctx, "SchemaDescriptions", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7209,7 +7219,7 @@ func SimpleRecursiveListAlias(ctx context.Context, input types.RecursiveListAlia if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "SimpleRecursiveListAlias", encoded) + result, err := bamlRuntime.CallFunction(ctx, "SimpleRecursiveListAlias", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7281,7 +7291,7 @@ func SimpleRecursiveMapAlias(ctx context.Context, input types.RecursiveMapAlias, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "SimpleRecursiveMapAlias", encoded) + result, err := bamlRuntime.CallFunction(ctx, "SimpleRecursiveMapAlias", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7353,7 +7363,7 @@ func StreamBigNumbers(ctx context.Context, digits int64, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "StreamBigNumbers", encoded) + result, err := bamlRuntime.CallFunction(ctx, "StreamBigNumbers", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7425,7 +7435,7 @@ func StreamFailingAssertion(ctx context.Context, theme string, length int64, opt if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "StreamFailingAssertion", encoded) + result, err := bamlRuntime.CallFunction(ctx, "StreamFailingAssertion", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7497,7 +7507,7 @@ func StreamFailingCheck(ctx context.Context, theme string, length int64, opts .. if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "StreamFailingCheck", encoded) + result, err := bamlRuntime.CallFunction(ctx, "StreamFailingCheck", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7569,7 +7579,7 @@ func StreamOneBigNumber(ctx context.Context, digits int64, opts ...CallOptionFun if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "StreamOneBigNumber", encoded) + result, err := bamlRuntime.CallFunction(ctx, "StreamOneBigNumber", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7641,7 +7651,7 @@ func StreamUnionIntegers(ctx context.Context, digits int64, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "StreamUnionIntegers", encoded) + result, err := bamlRuntime.CallFunction(ctx, "StreamUnionIntegers", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7713,7 +7723,7 @@ func StreamingCompoundNumbers(ctx context.Context, digits int64, yapping bool, o if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "StreamingCompoundNumbers", encoded) + result, err := bamlRuntime.CallFunction(ctx, "StreamingCompoundNumbers", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7785,7 +7795,7 @@ func StructureDocument1559(ctx context.Context, document_txt string, opts ...Cal if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "StructureDocument1559", encoded) + result, err := bamlRuntime.CallFunction(ctx, "StructureDocument1559", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7857,7 +7867,7 @@ func TakeRecAliasDep(ctx context.Context, input types.RecursiveAliasDependency, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TakeRecAliasDep", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TakeRecAliasDep", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -7929,7 +7939,7 @@ func TellStory(ctx context.Context, story string, opts ...CallOptionFunc) (*stri if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TellStory", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TellStory", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8001,7 +8011,7 @@ func TestAnthropic(ctx context.Context, input string, opts ...CallOptionFunc) (* if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAnthropic", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAnthropic", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8073,7 +8083,7 @@ func TestAnthropicShorthand(ctx context.Context, input string, opts ...CallOptio if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAnthropicShorthand", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAnthropicShorthand", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8145,7 +8155,7 @@ func TestAws(ctx context.Context, input string, opts ...CallOptionFunc) (*string if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAws", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAws", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8217,7 +8227,7 @@ func TestAwsClaude37(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAwsClaude37", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAwsClaude37", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8289,7 +8299,7 @@ func TestAwsInferenceProfile(ctx context.Context, input string, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAwsInferenceProfile", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAwsInferenceProfile", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8361,7 +8371,7 @@ func TestAwsInvalidAccessKey(ctx context.Context, input string, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidAccessKey", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidAccessKey", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8433,7 +8443,7 @@ func TestAwsInvalidProfile(ctx context.Context, input string, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidProfile", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidProfile", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8505,7 +8515,7 @@ func TestAwsInvalidRegion(ctx context.Context, input string, opts ...CallOptionF if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidRegion", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidRegion", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8577,7 +8587,7 @@ func TestAwsInvalidSessionToken(ctx context.Context, input string, opts ...CallO if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidSessionToken", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAwsInvalidSessionToken", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8649,7 +8659,7 @@ func TestAzure(ctx context.Context, input string, opts ...CallOptionFunc) (*stri if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzure", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzure", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8721,7 +8731,7 @@ func TestAzureFailure(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzureFailure", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzureFailure", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8793,7 +8803,7 @@ func TestAzureO1NoMaxTokens(ctx context.Context, input string, opts ...CallOptio if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzureO1NoMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzureO1NoMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8865,7 +8875,7 @@ func TestAzureO1WithMaxCompletionTokens(ctx context.Context, input string, opts if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzureO1WithMaxCompletionTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzureO1WithMaxCompletionTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -8937,7 +8947,7 @@ func TestAzureO1WithMaxTokens(ctx context.Context, input string, opts ...CallOpt if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzureO1WithMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzureO1WithMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9009,7 +9019,7 @@ func TestAzureO3NoMaxTokens(ctx context.Context, input string, opts ...CallOptio if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzureO3NoMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzureO3NoMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9081,7 +9091,7 @@ func TestAzureO3WithMaxCompletionTokens(ctx context.Context, input string, opts if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzureO3WithMaxCompletionTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzureO3WithMaxCompletionTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9153,7 +9163,7 @@ func TestAzureWithMaxTokens(ctx context.Context, input string, opts ...CallOptio if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestAzureWithMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestAzureWithMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9225,7 +9235,7 @@ func TestCaching(ctx context.Context, input string, not_cached string, opts ...C if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestCaching", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestCaching", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9297,7 +9307,7 @@ func TestFallbackClient(ctx context.Context, opts ...CallOptionFunc) (*string, e if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFallbackClient", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFallbackClient", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9369,7 +9379,7 @@ func TestFallbackStrategy(ctx context.Context, input string, opts ...CallOptionF if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFallbackStrategy", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFallbackStrategy", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9441,7 +9451,7 @@ func TestFallbackToShorthand(ctx context.Context, input string, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFallbackToShorthand", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFallbackToShorthand", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9513,7 +9523,7 @@ func TestFnNamedArgsSingleBool(ctx context.Context, myBool bool, opts ...CallOpt if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleBool", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleBool", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9585,7 +9595,7 @@ func TestFnNamedArgsSingleClass(ctx context.Context, myArg types.NamedArgsSingle if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleClass", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleClass", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9657,7 +9667,7 @@ func TestFnNamedArgsSingleEnumList(ctx context.Context, myArg []types.NamedArgsS if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleEnumList", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleEnumList", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9729,7 +9739,7 @@ func TestFnNamedArgsSingleFloat(ctx context.Context, myFloat float64, opts ...Ca if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleFloat", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleFloat", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9801,7 +9811,7 @@ func TestFnNamedArgsSingleInt(ctx context.Context, myInt int64, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleInt", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleInt", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9873,7 +9883,7 @@ func TestFnNamedArgsSingleMapStringToClass(ctx context.Context, myMap map[string if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleMapStringToClass", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleMapStringToClass", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -9945,7 +9955,7 @@ func TestFnNamedArgsSingleMapStringToMap(ctx context.Context, myMap map[string]m if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleMapStringToMap", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleMapStringToMap", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10017,7 +10027,7 @@ func TestFnNamedArgsSingleMapStringToString(ctx context.Context, myMap map[strin if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleMapStringToString", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleMapStringToString", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10089,7 +10099,7 @@ func TestFnNamedArgsSingleString(ctx context.Context, myString string, opts ...C if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleString", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleString", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10161,7 +10171,7 @@ func TestFnNamedArgsSingleStringArray(ctx context.Context, myStringArray []strin if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleStringArray", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleStringArray", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10233,7 +10243,7 @@ func TestFnNamedArgsSingleStringList(ctx context.Context, myArg []string, opts . if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleStringList", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestFnNamedArgsSingleStringList", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10305,7 +10315,7 @@ func TestGemini(ctx context.Context, input string, opts ...CallOptionFunc) (*str if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestGemini", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestGemini", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10377,7 +10387,7 @@ func TestGeminiOpenAiGeneric(ctx context.Context, opts ...CallOptionFunc) (*stri if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestGeminiOpenAiGeneric", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestGeminiOpenAiGeneric", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10449,7 +10459,7 @@ func TestGeminiSystem(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestGeminiSystem", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestGeminiSystem", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10521,7 +10531,7 @@ func TestGeminiSystemAsChat(ctx context.Context, input string, opts ...CallOptio if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestGeminiSystemAsChat", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestGeminiSystemAsChat", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10593,7 +10603,7 @@ func TestGroq(ctx context.Context, input string, opts ...CallOptionFunc) (*strin if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestGroq", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestGroq", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10665,7 +10675,7 @@ func TestImageInput(ctx context.Context, img any, opts ...CallOptionFunc) (*stri if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestImageInput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestImageInput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10737,7 +10747,7 @@ func TestImageInputAnthropic(ctx context.Context, img any, opts ...CallOptionFun if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestImageInputAnthropic", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestImageInputAnthropic", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10809,7 +10819,7 @@ func TestImageListInput(ctx context.Context, imgs []any, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestImageListInput", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestImageListInput", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10881,7 +10891,7 @@ func TestMemory(ctx context.Context, input string, opts ...CallOptionFunc) (*typ if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestMemory", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestMemory", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -10953,7 +10963,7 @@ func TestMulticlassNamedArgs(ctx context.Context, myArg types.NamedArgsSingleCla if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestMulticlassNamedArgs", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestMulticlassNamedArgs", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11025,7 +11035,7 @@ func TestNamedArgsLiteralBool(ctx context.Context, myBool bool, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestNamedArgsLiteralBool", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestNamedArgsLiteralBool", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11097,7 +11107,7 @@ func TestNamedArgsLiteralInt(ctx context.Context, myInt int, opts ...CallOptionF if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestNamedArgsLiteralInt", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestNamedArgsLiteralInt", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11169,7 +11179,7 @@ func TestNamedArgsLiteralString(ctx context.Context, myString string, opts ...Ca if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestNamedArgsLiteralString", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestNamedArgsLiteralString", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11241,7 +11251,7 @@ func TestOllama(ctx context.Context, input string, opts ...CallOptionFunc) (**st if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOllama", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOllama", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11315,7 +11325,7 @@ func TestOllamaHaiku(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOllamaHaiku", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOllamaHaiku", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11387,7 +11397,7 @@ func TestOpenAI(ctx context.Context, input string, opts ...CallOptionFunc) (*str if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAI", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAI", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11459,7 +11469,7 @@ func TestOpenAIDummyClient(ctx context.Context, input string, opts ...CallOption if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIDummyClient", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIDummyClient", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11531,7 +11541,7 @@ func TestOpenAIGPT4oMini(ctx context.Context, input string, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIGPT4oMini", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIGPT4oMini", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11603,7 +11613,7 @@ func TestOpenAILegacyProvider(ctx context.Context, input string, opts ...CallOpt if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAILegacyProvider", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAILegacyProvider", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11675,7 +11685,7 @@ func TestOpenAIO1NoMaxTokens(ctx context.Context, input string, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIO1NoMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIO1NoMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11747,7 +11757,7 @@ func TestOpenAIO1WithMaxCompletionTokens(ctx context.Context, input string, opts if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIO1WithMaxCompletionTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIO1WithMaxCompletionTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11819,7 +11829,7 @@ func TestOpenAIO1WithMaxTokens(ctx context.Context, input string, opts ...CallOp if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIO1WithMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIO1WithMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11891,7 +11901,7 @@ func TestOpenAIShorthand(ctx context.Context, input string, opts ...CallOptionFu if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIShorthand", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIShorthand", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -11963,7 +11973,7 @@ func TestOpenAIWithFinishReasonError(ctx context.Context, input string, opts ... if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIWithFinishReasonError", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIWithFinishReasonError", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12035,7 +12045,7 @@ func TestOpenAIWithMaxTokens(ctx context.Context, input string, opts ...CallOpti if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIWithMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIWithMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12107,7 +12117,7 @@ func TestOpenAIWithNullMaxTokens(ctx context.Context, input string, opts ...Call if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIWithNullMaxTokens", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenAIWithNullMaxTokens", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12179,7 +12189,7 @@ func TestOpenRouterMistralSmall3_1_24b(ctx context.Context, input string, opts . if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestOpenRouterMistralSmall3_1_24b", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestOpenRouterMistralSmall3_1_24b", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12251,7 +12261,7 @@ func TestRetryConstant(ctx context.Context, opts ...CallOptionFunc) (*string, er if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestRetryConstant", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestRetryConstant", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12323,7 +12333,7 @@ func TestRetryExponential(ctx context.Context, opts ...CallOptionFunc) (*string, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestRetryExponential", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestRetryExponential", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12395,7 +12405,7 @@ func TestRoundRobinStrategy(ctx context.Context, input string, opts ...CallOptio if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestRoundRobinStrategy", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestRoundRobinStrategy", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12467,7 +12477,7 @@ func TestSingleFallbackClient(ctx context.Context, opts ...CallOptionFunc) (*str if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestSingleFallbackClient", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestSingleFallbackClient", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12539,7 +12549,7 @@ func TestThinking(ctx context.Context, input string, opts ...CallOptionFunc) (*t if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestThinking", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestThinking", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12611,7 +12621,7 @@ func TestUniverseQuestion(ctx context.Context, question types.UniverseQuestionIn if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestUniverseQuestion", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestUniverseQuestion", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12683,7 +12693,7 @@ func TestVertex(ctx context.Context, input string, opts ...CallOptionFunc) (*str if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestVertex", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestVertex", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12755,7 +12765,7 @@ func TestVertexClaude(ctx context.Context, input string, opts ...CallOptionFunc) if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestVertexClaude", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestVertexClaude", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12827,7 +12837,7 @@ func TestVertexWithSystemInstructions(ctx context.Context, opts ...CallOptionFun if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "TestVertexWithSystemInstructions", encoded) + result, err := bamlRuntime.CallFunction(ctx, "TestVertexWithSystemInstructions", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12899,7 +12909,7 @@ func UnionTest_Function(ctx context.Context, input types.Union__string__bool, op if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "UnionTest_Function", encoded) + result, err := bamlRuntime.CallFunction(ctx, "UnionTest_Function", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -12971,7 +12981,7 @@ func UseBlockConstraint(ctx context.Context, inp types.BlockConstraintForParam, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "UseBlockConstraint", encoded) + result, err := bamlRuntime.CallFunction(ctx, "UseBlockConstraint", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -13043,7 +13053,7 @@ func UseMaintainFieldOrder(ctx context.Context, input types.MaintainFieldOrder, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "UseMaintainFieldOrder", encoded) + result, err := bamlRuntime.CallFunction(ctx, "UseMaintainFieldOrder", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -13115,7 +13125,7 @@ func UseMalformedConstraints(ctx context.Context, a types.MalformedConstraints2, if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "UseMalformedConstraints", encoded) + result, err := bamlRuntime.CallFunction(ctx, "UseMalformedConstraints", encoded, callOpts.collectors) if err != nil { return nil, err } @@ -13187,7 +13197,7 @@ func UseNestedBlockConstraint(ctx context.Context, inp types.NestedBlockConstrai if err != nil { panic(err) } - result, err := bamlRuntime.CallFunction(ctx, "UseNestedBlockConstraint", encoded) + result, err := bamlRuntime.CallFunction(ctx, "UseNestedBlockConstraint", encoded, callOpts.collectors) if err != nil { return nil, err } diff --git a/integ-tests/go/test.go b/integ-tests/go/test.go index ad88fc52d5..c7d41f2dfd 100644 --- a/integ-tests/go/test.go +++ b/integ-tests/go/test.go @@ -11,16 +11,24 @@ import ( func main() { ctx := context.Background() - registry := baml.NewClientRegistry() - registry.AddLlmClient("a", "openai", map[string]any{"a": "b"}) - registry.SetPrimaryClient("a") + collector := baml.NewCollector() - v2, err := b.AaaSamOutputFormat(ctx, "oranges", b.WithClientRegistry(registry)) + v2, err := b.AaaSamOutputFormat(ctx, "oranges", b.WithCollector(collector)) if err != nil { panic(err) } fmt.Println(*v2) + usage, err := collector.Usage() + if err != nil { + panic(err) + } + input_tokens, err := usage.InputTokens() + if err != nil { + panic(err) + } + fmt.Printf("input_tokens: %d\n", input_tokens) + v2, err = b.AaaSamOutputFormat(ctx, "pineapple") if err != nil { panic(err) From c03166392da7aa28baceba0b6d96779ef124a702 Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Thu, 22 May 2025 08:57:48 -0700 Subject: [PATCH 03/10] Fix the Box issue --- engine/language_client_cffi/src/lib.rs | 4 ++-- integ-tests/go/test.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index 3ffb0285d8..3559e680a5 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -378,11 +378,11 @@ fn call_collector_function_inner( } } "usage" => { - let usage = unsafe { Box::from_raw(object as *mut Usage) }; + let usage = unsafe { &mut *(object as *mut Usage) }; match function_name.as_str() { "destroy" => { - let _ = drop(usage); + let _ = unsafe { Box::from_raw(usage) }; Ok(null()) } "input_tokens" => Ok(usage.input_tokens.unwrap_or_default() as *mut libc::c_void), diff --git a/integ-tests/go/test.go b/integ-tests/go/test.go index c7d41f2dfd..77c6d83c86 100644 --- a/integ-tests/go/test.go +++ b/integ-tests/go/test.go @@ -27,7 +27,12 @@ func main() { if err != nil { panic(err) } + output_tokens, err := usage.OutputTokens() + if err != nil { + panic(err) + } fmt.Printf("input_tokens: %d\n", input_tokens) + fmt.Printf("output_tokens: %d\n", output_tokens) v2, err = b.AaaSamOutputFormat(ctx, "pineapple") if err != nil { From b7d3d6856a97d642ae0b90abce87a167ad34ab4f Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Thu, 22 May 2025 09:07:05 -0700 Subject: [PATCH 04/10] Proper free --- engine/language_client_cffi/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index 3559e680a5..010c7dc343 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -382,7 +382,7 @@ fn call_collector_function_inner( match function_name.as_str() { "destroy" => { - let _ = unsafe { Box::from_raw(usage) }; + let _ = unsafe { Box::from_raw(object as *mut Usage) }; Ok(null()) } "input_tokens" => Ok(usage.input_tokens.unwrap_or_default() as *mut libc::c_void), From 724ff0a63e2e7d832dd5ea3a96bba355e8e59b94 Mon Sep 17 00:00:00 2001 From: Vaibhav Gupta Date: Thu, 22 May 2025 13:40:36 -0700 Subject: [PATCH 05/10] fixing ref-count issues --- engine/language_client_cffi/src/lib.rs | 27 ++++++------ .../src/raw_ptr_wrapper.rs | 42 +++++++++++++++++++ 2 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 engine/language_client_cffi/src/raw_ptr_wrapper.rs diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index 010c7dc343..6d0bdf947d 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -1,14 +1,18 @@ /// cbindgen:ignore mod ctypes; +mod raw_ptr_wrapper; + use std::ops::Deref; use std::{collections::HashMap, ffi::CStr, ptr::null, sync::Arc}; - use anyhow::Result; use baml_runtime::client_registry::ClientRegistry; use baml_runtime::tracingv2::storage::storage::{Collector, Usage}; use baml_runtime::{BamlRuntime, FunctionResult}; use once_cell::sync::{Lazy, OnceCell}; +use raw_ptr_wrapper::CollectorWrapper; + + const VERSION: &str = env!("CARGO_PKG_VERSION"); struct BamlFunctionArguments { @@ -206,18 +210,14 @@ fn call_function_from_c_inner( let buffer = unsafe { std::slice::from_raw_parts(encoded_args as *const u8, length) }; let function_args = ctypes::buffer_to_cffi_function_arguments(buffer)?; - let collector_ptrs = collectors as *const *const libc::c_void; + // let runtime = unsafe { &*(runtime as *const BamlRuntime) }; + let collector_ptrs = unsafe { std::slice::from_raw_parts(collectors as *const *const libc::c_void, collectors_length) }; let collectors = match collectors_length { 0 => None, _ => Some( - unsafe { std::slice::from_raw_parts(collector_ptrs, collectors_length) } + collector_ptrs .iter() - .map(|c| unsafe { - let collector = Arc::from_raw(*c as *const Collector); - let clone = collector.clone(); - let _ = Arc::into_raw(clone); - collector - }) + .map(|c| CollectorWrapper::from_raw(*c, true)) .collect::>(), ), }; @@ -235,7 +235,7 @@ fn call_function_from_c_inner( &ctx, None, function_args.client_registry.as_ref(), - collectors, + collectors.map(|c| c.iter().map(|c| c.deref().clone()).collect()), ) .await; safe_trigger_callback(id, true, result); @@ -357,13 +357,12 @@ fn call_collector_function_inner( match object_type.as_str() { "collector" => { - let collector = unsafe { Arc::from_raw(object as *const Collector) }; - let clone = collector.clone(); - let _ = Arc::into_raw(clone); + let collector = CollectorWrapper::from_raw(object, true); match function_name.as_str() { "destroy" => { - let _ = collector.deref(); + collector.destroy(); + // collector goes out of scope here Ok(null()) } "usage" => { diff --git a/engine/language_client_cffi/src/raw_ptr_wrapper.rs b/engine/language_client_cffi/src/raw_ptr_wrapper.rs new file mode 100644 index 0000000000..018d91a20e --- /dev/null +++ b/engine/language_client_cffi/src/raw_ptr_wrapper.rs @@ -0,0 +1,42 @@ +use std::ops::Deref; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; + +use baml_runtime::tracingv2::storage::storage::Collector; + +pub struct RawPtrWrapper { + inner: Arc, + persist: AtomicBool, +} + +impl RawPtrWrapper { + pub fn from_raw(object: *const libc::c_void, persist: bool ) -> Self { + Self { inner: unsafe { Arc::from_raw(object as *const T) }, persist: AtomicBool::new(persist) } + } + + pub fn destroy(self) { + self.persist.store(false, std::sync::atomic::Ordering::Relaxed); + } + + pub fn inner(&self) -> &Arc { + &self.inner + } +} + +impl Deref for RawPtrWrapper { + type Target = Arc; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl Drop for RawPtrWrapper { + fn drop(&mut self) { + if self.persist.load(std::sync::atomic::Ordering::Relaxed) { + let _ = Arc::into_raw(self.inner.clone()); + } + } +} + +pub type CollectorWrapper = RawPtrWrapper; From d2f905eb240c5cf3a495293b50b40d00236fab58 Mon Sep 17 00:00:00 2001 From: Vaibhav Gupta Date: Thu, 22 May 2025 13:40:58 -0700 Subject: [PATCH 06/10] removed other method --- engine/language_client_cffi/src/raw_ptr_wrapper.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/engine/language_client_cffi/src/raw_ptr_wrapper.rs b/engine/language_client_cffi/src/raw_ptr_wrapper.rs index 018d91a20e..b66dd2e0e9 100644 --- a/engine/language_client_cffi/src/raw_ptr_wrapper.rs +++ b/engine/language_client_cffi/src/raw_ptr_wrapper.rs @@ -17,10 +17,6 @@ impl RawPtrWrapper { pub fn destroy(self) { self.persist.store(false, std::sync::atomic::Ordering::Relaxed); } - - pub fn inner(&self) -> &Arc { - &self.inner - } } impl Deref for RawPtrWrapper { From 3119e93cbb730f7e51e074fec516542fcf0aa209 Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Mon, 26 May 2025 08:43:30 -0700 Subject: [PATCH 07/10] Add more collector wrapping --- engine/language_client_cffi/src/lib.rs | 165 +++++++++++- .../src/raw_ptr_wrapper.rs | 17 +- engine/language_client_go/pkg/collector.go | 236 +++++++++++++++++- integ-tests/go/test.go | 109 +++++++- 4 files changed, 505 insertions(+), 22 deletions(-) diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index 6d0bdf947d..da672db889 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -3,15 +3,20 @@ mod ctypes; mod raw_ptr_wrapper; -use std::ops::Deref; -use std::{collections::HashMap, ffi::CStr, ptr::null, sync::Arc}; use anyhow::Result; use baml_runtime::client_registry::ClientRegistry; -use baml_runtime::tracingv2::storage::storage::{Collector, Usage}; +use baml_runtime::tracingv2::storage::storage::{Collector, LLMCall, LLMStreamCall, Timing, Usage}; use baml_runtime::{BamlRuntime, FunctionResult}; use once_cell::sync::{Lazy, OnceCell}; -use raw_ptr_wrapper::CollectorWrapper; - +use raw_ptr_wrapper::{CollectorWrapper, FunctionLogWrapper}; +use std::ops::Deref; +use std::ptr::null_mut; +use std::{ + collections::HashMap, + ffi::CStr, + ptr::null, + sync::{Arc, Mutex}, +}; const VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -211,13 +216,15 @@ fn call_function_from_c_inner( let function_args = ctypes::buffer_to_cffi_function_arguments(buffer)?; // let runtime = unsafe { &*(runtime as *const BamlRuntime) }; - let collector_ptrs = unsafe { std::slice::from_raw_parts(collectors as *const *const libc::c_void, collectors_length) }; + let collector_ptrs = unsafe { + std::slice::from_raw_parts(collectors as *const *const libc::c_void, collectors_length) + }; let collectors = match collectors_length { 0 => None, _ => Some( collector_ptrs .iter() - .map(|c| CollectorWrapper::from_raw(*c, true)) + .map(|c| CollectorWrapper::from_raw(*c, true)) .collect::>(), ), }; @@ -369,6 +376,11 @@ fn call_collector_function_inner( let usage = collector.usage(); Ok(Box::into_raw(Box::new(usage)) as *const libc::c_void) } + "last" => { + let last = collector.last_function_log(); + let wrapper = Arc::new(Mutex::new(last)); + Ok(Arc::into_raw(wrapper) as *const libc::c_void) + } _ => Err(anyhow::anyhow!( "Failed to call function: {} on object type: {}", function_name, @@ -384,6 +396,7 @@ fn call_collector_function_inner( let _ = unsafe { Box::from_raw(object as *mut Usage) }; Ok(null()) } + // pretend this is an integer not a pointer, which is dirty but works for now "input_tokens" => Ok(usage.input_tokens.unwrap_or_default() as *mut libc::c_void), "output_tokens" => Ok(usage.output_tokens.unwrap_or_default() as *mut libc::c_void), _ => Err(anyhow::anyhow!( @@ -393,6 +406,144 @@ fn call_collector_function_inner( )), } } + "function_log" => { + let function_log = FunctionLogWrapper::from_raw(object, true); + match function_name.as_str() { + "id" => { + let id = function_log.lock().unwrap().id().0; + let c_id = CString::new(id).unwrap(); + Ok(c_id.into_raw() as *const libc::c_void) + } + "function_name" => { + let function_name = function_log.lock().unwrap().function_name(); + let c_function_name = CString::new(function_name).unwrap(); + Ok(c_function_name.into_raw() as *const libc::c_void) + } + "log_type" => { + let log_type = function_log.lock().unwrap().log_type(); + let c_log_type = CString::new(log_type.to_string()).unwrap(); + Ok(c_log_type.into_raw() as *const libc::c_void) + } + "raw_llm_response" => { + let raw_llm_response = function_log.lock().unwrap().raw_llm_response(); + let c_raw_llm_response = + CString::new(raw_llm_response.unwrap_or_default()).unwrap(); + Ok(c_raw_llm_response.into_raw() as *const libc::c_void) + } + "calls" => { + let calls = function_log.lock().unwrap().calls(); + let c_calls = calls + .iter() + .map(|c| match c { + baml_runtime::tracingv2::storage::storage::LLMCallKind::Basic( + inner, + ) => Box::into_raw(Box::new(inner.clone())) as *mut libc::c_void, + baml_runtime::tracingv2::storage::storage::LLMCallKind::Stream( + inner, + ) => Box::into_raw(Box::new(inner.clone())) as *mut libc::c_void, + }) + .chain(std::iter::once(null_mut())) + .collect::>(); + let c_calls_ptr = c_calls.as_ptr() as *const libc::c_void; + // leak this so go can have it + std::mem::forget(c_calls); + Ok(c_calls_ptr) + } + "timing" => { + let timing = function_log.lock().unwrap().timing(); + Ok(Box::into_raw(Box::new(timing)) as *const libc::c_void) + } + "usage" => { + let usage = function_log.lock().unwrap().usage(); + Ok(Box::into_raw(Box::new(usage)) as *const libc::c_void) + } + "destroy" => { + function_log.destroy(); + Ok(null()) + } + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } + "timing" => { + let timing = unsafe { &mut *(object as *mut Timing) }; + match function_name.as_str() { + "destroy" => { + let _ = unsafe { Box::from_raw(object as *mut Timing) }; + Ok(null()) + } + "start_time_utc_ms" => Ok(timing.start_time_utc_ms as *mut libc::c_void), + "duration_ms" => Ok(timing + .duration_ms + .map(|d| d as *mut libc::c_void) + .unwrap_or(null_mut())), + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } + "llm_call" => { + let llm_call = unsafe { &mut *(object as *mut LLMCall) }; + match function_name.as_str() { + "client_name" => { + let c_client_name = CString::new(llm_call.client_name.clone()).unwrap(); + Ok(c_client_name.into_raw() as *const libc::c_void) + } + "provider" => { + let c_provider = CString::new(llm_call.provider.clone()).unwrap(); + Ok(c_provider.into_raw() as *const libc::c_void) + } + "timing" => { + let timing = llm_call.timing.clone(); + Ok(Box::into_raw(Box::new(timing)) as *const libc::c_void) + } + "usage" => { + let usage = llm_call.usage.clone().unwrap(); + Ok(Box::into_raw(Box::new(usage)) as *const libc::c_void) + } + "destroy" => { + let _ = unsafe { Box::from_raw(object as *mut LLMCall) }; + Ok(null()) + } + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } + "string" => match function_name.as_str() { + "destroy" => { + let _ = unsafe { CString::from_raw(object as *mut c_char) }; + Ok(null()) + } + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + }, + "list" => { + let ptrs = object as *mut *mut libc::c_void; + match function_name.as_str() { + "destroy" => { + unsafe { + drop(Box::from_raw(ptrs)); + } + Ok(null()) + } + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } _ => Err(anyhow::anyhow!( "Failed to call function: {} on object type: {}", function_name, diff --git a/engine/language_client_cffi/src/raw_ptr_wrapper.rs b/engine/language_client_cffi/src/raw_ptr_wrapper.rs index b66dd2e0e9..a6045703ba 100644 --- a/engine/language_client_cffi/src/raw_ptr_wrapper.rs +++ b/engine/language_client_cffi/src/raw_ptr_wrapper.rs @@ -1,8 +1,8 @@ use std::ops::Deref; use std::sync::atomic::AtomicBool; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; -use baml_runtime::tracingv2::storage::storage::Collector; +use baml_runtime::tracingv2::storage::storage::{Collector, FunctionLog}; pub struct RawPtrWrapper { inner: Arc, @@ -10,12 +10,16 @@ pub struct RawPtrWrapper { } impl RawPtrWrapper { - pub fn from_raw(object: *const libc::c_void, persist: bool ) -> Self { - Self { inner: unsafe { Arc::from_raw(object as *const T) }, persist: AtomicBool::new(persist) } + pub fn from_raw(object: *const libc::c_void, persist: bool) -> Self { + Self { + inner: unsafe { Arc::from_raw(object as *const T) }, + persist: AtomicBool::new(persist), + } } pub fn destroy(self) { - self.persist.store(false, std::sync::atomic::Ordering::Relaxed); + self.persist + .store(false, std::sync::atomic::Ordering::Relaxed); } } @@ -27,7 +31,7 @@ impl Deref for RawPtrWrapper { } } -impl Drop for RawPtrWrapper { +impl Drop for RawPtrWrapper { fn drop(&mut self) { if self.persist.load(std::sync::atomic::Ordering::Relaxed) { let _ = Arc::into_raw(self.inner.clone()); @@ -36,3 +40,4 @@ impl Drop for RawPtrWrapper { } pub type CollectorWrapper = RawPtrWrapper; +pub type FunctionLogWrapper = RawPtrWrapper>; diff --git a/engine/language_client_go/pkg/collector.go b/engine/language_client_go/pkg/collector.go index 8fa58d8dc9..abcae6ea42 100644 --- a/engine/language_client_go/pkg/collector.go +++ b/engine/language_client_go/pkg/collector.go @@ -1,22 +1,38 @@ package baml import ( + "C" "runtime" "unsafe" "github.com/boundaryml/baml/engine/language_client_go/baml_go" ) +const collectorType = "collector" +const usageType = "usage" +const functionLogType = "function_log" +const stringType = "string" +const timingType = "timing" +const llmCallType = "llm_call" + type Collector struct { c unsafe.Pointer } - type Usage struct { c unsafe.Pointer } -const collectorType = "collector" -const usageType = "usage" +type FunctionLog struct { + c unsafe.Pointer +} + +type Timing struct { + c unsafe.Pointer +} + +type LLMCall struct { + c unsafe.Pointer +} func NewCollector() *Collector { collectorPtr, err := baml_go.CallCollectorFunction(nil, collectorType, "new") @@ -46,12 +62,29 @@ func (c *Collector) Usage() (*Usage, error) { } runtime.AddCleanup(usage, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, collectorType, "destroy") + baml_go.CallCollectorFunction(c, usageType, "destroy") }, usage.c) return usage, nil } +func (c *Collector) Last() (*FunctionLog, error) { + functionLogPtr, err := baml_go.CallCollectorFunction(c.c, collectorType, "last") + if err != nil { + return nil, err + } + + functionLog := &FunctionLog{ + c: functionLogPtr, + } + + runtime.AddCleanup(functionLog, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, functionLogType, "destroy") + }, functionLog.c) + + return functionLog, nil +} + func (u *Usage) InputTokens() (int, error) { inputTokensPtr, err := baml_go.CallCollectorFunction(u.c, usageType, "input_tokens") if err != nil { @@ -69,3 +102,198 @@ func (u *Usage) OutputTokens() (int, error) { return int(uintptr(unsafe.Pointer(outputTokensPtr))), nil } + +func (f *FunctionLog) Usage() (*Usage, error) { + usagePtr, err := baml_go.CallCollectorFunction(f.c, functionLogType, "usage") + if err != nil { + return nil, err + } + + usage := &Usage{ + c: usagePtr, + } + + runtime.AddCleanup(usage, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, usageType, "destroy") + }, usage.c) + + return usage, nil +} + +func (f *FunctionLog) Id() (string, error) { + stringPtr, err := baml_go.CallCollectorFunction(f.c, functionLogType, "id") + if err != nil { + return "", err + } + + id := C.GoString((*C.char)(stringPtr)) + + baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") + + return id, nil +} + +func (f *FunctionLog) FunctionName() (string, error) { + stringPtr, err := baml_go.CallCollectorFunction(f.c, functionLogType, "function_name") + if err != nil { + return "", err + } + + functionName := C.GoString((*C.char)(stringPtr)) + + baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") + + return functionName, nil +} + +func (f *FunctionLog) LogType() (string, error) { + stringPtr, err := baml_go.CallCollectorFunction(f.c, functionLogType, "log_type") + if err != nil { + return "", err + } + + logType := C.GoString((*C.char)(stringPtr)) + + baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") + + return logType, nil +} + +func (f *FunctionLog) Timing() (*Timing, error) { + timingPtr, err := baml_go.CallCollectorFunction(f.c, functionLogType, "timing") + if err != nil { + return nil, err + } + + timing := &Timing{ + c: timingPtr, + } + + runtime.AddCleanup(timing, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, timingType, "destroy") + }, timing.c) + + return timing, nil +} + +func (f *FunctionLog) RawLlmResponse() (string, error) { + stringPtr, err := baml_go.CallCollectorFunction(f.c, functionLogType, "raw_llm_response") + if err != nil { + return "", err + } + + rawLlmResponse := C.GoString((*C.char)(stringPtr)) + + baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") + + return rawLlmResponse, nil +} + +func (f *FunctionLog) Calls() ([]*LLMCall, error) { + callsRaw, err := baml_go.CallCollectorFunction(f.c, functionLogType, "calls") + if err != nil { + return nil, err + } + + const max = 1024 + + callArray := (*[max]*C.void)(callsRaw) + + calls := make([]*LLMCall, 0) + for i := 0; i < max; i++ { + ptr := callArray[i] + if ptr == nil { + break + } + + call := &LLMCall{c: unsafe.Pointer(ptr)} + + runtime.AddCleanup(call, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, llmCallType, "destroy") + }, call.c) + + calls = append(calls, call) + } + + baml_go.CallCollectorFunction(callsRaw, "list", "destroy") + + return calls, nil +} + +func (t *Timing) StartTimeUtcMs() (int, error) { + startTimeUtcMsPtr, err := baml_go.CallCollectorFunction(t.c, timingType, "start_time_utc_ms") + if err != nil { + return 0, err + } + + return int(uintptr(unsafe.Pointer(startTimeUtcMsPtr))), nil +} + +func (t *Timing) DurationMs() (int, error) { + durationMsPtr, err := baml_go.CallCollectorFunction(t.c, timingType, "duration_ms") + if err != nil { + return 0, err + } + + return int(uintptr(unsafe.Pointer(durationMsPtr))), nil +} + +func (l *LLMCall) ClientName() (string, error) { + stringPtr, err := baml_go.CallCollectorFunction(l.c, llmCallType, "client_name") + if err != nil { + return "", err + } + + clientName := C.GoString((*C.char)(stringPtr)) + + baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") + + return clientName, nil +} + +func (l *LLMCall) Provider() (string, error) { + stringPtr, err := baml_go.CallCollectorFunction(l.c, llmCallType, "provider") + if err != nil { + return "", err + } + + provider := C.GoString((*C.char)(stringPtr)) + + baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") + + return provider, nil +} + +func (l *LLMCall) Timing() (*Timing, error) { + timingPtr, err := baml_go.CallCollectorFunction(l.c, llmCallType, "timing") + if err != nil { + return nil, err + } + + timing := &Timing{ + c: timingPtr, + } + + runtime.AddCleanup(timing, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, timingType, "destroy") + }, timing.c) + + return timing, nil +} + +func (l *LLMCall) Usage() (*Usage, error) { + usagePtr, err := baml_go.CallCollectorFunction(l.c, llmCallType, "usage") + if err != nil { + return nil, err + } + + usage := &Usage{ + c: usagePtr, + } + + runtime.AddCleanup(usage, func(c unsafe.Pointer) { + baml_go.CallCollectorFunction(c, usageType, "destroy") + }, usage.c) + + return usage, nil +} diff --git a/integ-tests/go/test.go b/integ-tests/go/test.go index 77c6d83c86..c1830bb5ac 100644 --- a/integ-tests/go/test.go +++ b/integ-tests/go/test.go @@ -34,14 +34,113 @@ func main() { fmt.Printf("input_tokens: %d\n", input_tokens) fmt.Printf("output_tokens: %d\n", output_tokens) - v2, err = b.AaaSamOutputFormat(ctx, "pineapple") + last, err := collector.Last() + if err != nil { + panic(err) + } + usage, err = last.Usage() + if err != nil { + panic(err) + } + last_input_tokens, err := usage.InputTokens() + if err != nil { + panic(err) + } + last_output_tokens, err := usage.OutputTokens() if err != nil { panic(err) } - fmt.Println(*v2) - stream := b.Stream.AaaSamOutputFormat(ctx, "pineapple") - for chunk := range stream { - fmt.Println(chunk) + fmt.Printf("last input tokens: %d\n", last_input_tokens) + fmt.Printf("last output tokens: %d\n", last_output_tokens) + + id, err := last.Id() + if err != nil { + panic(err) + } + fmt.Printf("last id: %s\n", id) + + functionName, err := last.FunctionName() + if err != nil { + panic(err) } + fmt.Printf("last function name: %s\n", functionName) + + timing, err := last.Timing() + if err != nil { + panic(err) + } + startTimeUtcMs, err := timing.StartTimeUtcMs() + if err != nil { + panic(err) + } + durationMs, err := timing.DurationMs() + if err != nil { + panic(err) + } + + fmt.Printf("last start time utc ms: %d\n", startTimeUtcMs) + fmt.Printf("last duration ms: %d\n", durationMs) + + rawLlmResponse, err := last.RawLlmResponse() + if err != nil { + panic(err) + } + fmt.Printf("last raw llm response: %s\n", rawLlmResponse) + + calls, err := last.Calls() + if err != nil { + panic(err) + } + for _, call := range calls { + clientName, err := call.ClientName() + if err != nil { + panic(err) + } + fmt.Printf("call client name: %s\n", clientName) + provider, err := call.Provider() + if err != nil { + panic(err) + } + fmt.Printf("call provider: %s\n", provider) + timing, err := call.Timing() + if err != nil { + panic(err) + } + startTimeUtcMs, err := timing.StartTimeUtcMs() + if err != nil { + panic(err) + } + fmt.Printf("call start time utc ms: %d\n", startTimeUtcMs) + durationMs, err := timing.DurationMs() + if err != nil { + panic(err) + } + fmt.Printf("call duration ms: %d\n", durationMs) + usage, err := call.Usage() + if err != nil { + panic(err) + } + inputTokens, err := usage.InputTokens() + if err != nil { + panic(err) + } + fmt.Printf("call input tokens: %d\n", inputTokens) + outputTokens, err := usage.OutputTokens() + if err != nil { + panic(err) + } + fmt.Printf("call output tokens: %d\n", outputTokens) + } + + // v2, err = b.AaaSamOutputFormat(ctx, "pineapple") + // if err != nil { + // panic(err) + // } + // fmt.Println(*v2) + + // stream := b.Stream.AaaSamOutputFormat(ctx, "pineapple") + // for chunk := range stream { + // fmt.Println(chunk) + // } } From 743af29c4731839ad128d55346fb34d221222c8c Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Mon, 26 May 2025 13:02:21 -0700 Subject: [PATCH 08/10] Make this a bit easier to read --- engine/language_client_go/pkg/collector.go | 208 +++++++++++---------- 1 file changed, 108 insertions(+), 100 deletions(-) diff --git a/engine/language_client_go/pkg/collector.go b/engine/language_client_go/pkg/collector.go index abcae6ea42..492fc403b5 100644 --- a/engine/language_client_go/pkg/collector.go +++ b/engine/language_client_go/pkg/collector.go @@ -18,37 +18,123 @@ const llmCallType = "llm_call" type Collector struct { c unsafe.Pointer } + +func (c *Collector) pointer() unsafe.Pointer { + return c.c +} + +func (c *Collector) rustType() string { + return collectorType +} + type Usage struct { c unsafe.Pointer } +func (u *Usage) pointer() unsafe.Pointer { + return u.c +} + +func (u *Usage) rustType() string { + return usageType +} + +func createUsage(c unsafe.Pointer) *Usage { + return &Usage{ + c: c, + } +} + type FunctionLog struct { c unsafe.Pointer } +func (f *FunctionLog) pointer() unsafe.Pointer { + return f.c +} + +func (f *FunctionLog) rustType() string { + return functionLogType +} + +func createFunctionLog(c unsafe.Pointer) *FunctionLog { + return &FunctionLog{ + c: c, + } +} + type Timing struct { c unsafe.Pointer } +func (t *Timing) pointer() unsafe.Pointer { + return t.c +} + +func (t *Timing) rustType() string { + return timingType +} + +func createTiming(c unsafe.Pointer) *Timing { + return &Timing{ + c: c, + } +} + type LLMCall struct { c unsafe.Pointer } +func (l *LLMCall) pointer() unsafe.Pointer { + return l.c +} + +func (l *LLMCall) rustType() string { + return llmCallType +} + +func createLLMCall(c unsafe.Pointer) *LLMCall { + return &LLMCall{ + c: c, + } +} + +type rustPointer interface { + pointer() unsafe.Pointer + rustType() string +} + +func wrap[T rustPointer](createFn func(c unsafe.Pointer) T, c unsafe.Pointer) T { + wrapped := createFn(c) + + runtime.AddCleanup(&wrapped, func(ptr unsafe.Pointer) { + baml_go.CallCollectorFunction(ptr, wrapped.rustType(), "destroy") + }, wrapped.pointer()) + + return wrapped +} + +func createCollector(c unsafe.Pointer) *Collector { + return &Collector{ + c: c, + } +} + +func convertString(ptr unsafe.Pointer) string { + str := C.GoString((*C.char)(ptr)) + + baml_go.CallCollectorFunction(ptr, stringType, "destroy") + + return str +} + func NewCollector() *Collector { collectorPtr, err := baml_go.CallCollectorFunction(nil, collectorType, "new") if err != nil { panic(err) } - collector := &Collector{ - c: collectorPtr, - } - - runtime.AddCleanup(collector, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, collectorType, "destroy") - }, collector.c) - - return collector + return wrap(createCollector, collectorPtr) } func (c *Collector) Usage() (*Usage, error) { @@ -57,15 +143,7 @@ func (c *Collector) Usage() (*Usage, error) { return nil, err } - usage := &Usage{ - c: usagePtr, - } - - runtime.AddCleanup(usage, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, usageType, "destroy") - }, usage.c) - - return usage, nil + return wrap(createUsage, usagePtr), nil } func (c *Collector) Last() (*FunctionLog, error) { @@ -74,15 +152,7 @@ func (c *Collector) Last() (*FunctionLog, error) { return nil, err } - functionLog := &FunctionLog{ - c: functionLogPtr, - } - - runtime.AddCleanup(functionLog, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, functionLogType, "destroy") - }, functionLog.c) - - return functionLog, nil + return wrap(createFunctionLog, functionLogPtr), nil } func (u *Usage) InputTokens() (int, error) { @@ -109,15 +179,7 @@ func (f *FunctionLog) Usage() (*Usage, error) { return nil, err } - usage := &Usage{ - c: usagePtr, - } - - runtime.AddCleanup(usage, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, usageType, "destroy") - }, usage.c) - - return usage, nil + return wrap(createUsage, usagePtr), nil } func (f *FunctionLog) Id() (string, error) { @@ -126,11 +188,7 @@ func (f *FunctionLog) Id() (string, error) { return "", err } - id := C.GoString((*C.char)(stringPtr)) - - baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") - - return id, nil + return convertString(stringPtr), nil } func (f *FunctionLog) FunctionName() (string, error) { @@ -139,11 +197,7 @@ func (f *FunctionLog) FunctionName() (string, error) { return "", err } - functionName := C.GoString((*C.char)(stringPtr)) - - baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") - - return functionName, nil + return convertString(stringPtr), nil } func (f *FunctionLog) LogType() (string, error) { @@ -152,11 +206,7 @@ func (f *FunctionLog) LogType() (string, error) { return "", err } - logType := C.GoString((*C.char)(stringPtr)) - - baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") - - return logType, nil + return convertString(stringPtr), nil } func (f *FunctionLog) Timing() (*Timing, error) { @@ -165,15 +215,7 @@ func (f *FunctionLog) Timing() (*Timing, error) { return nil, err } - timing := &Timing{ - c: timingPtr, - } - - runtime.AddCleanup(timing, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, timingType, "destroy") - }, timing.c) - - return timing, nil + return wrap(createTiming, timingPtr), nil } func (f *FunctionLog) RawLlmResponse() (string, error) { @@ -182,11 +224,7 @@ func (f *FunctionLog) RawLlmResponse() (string, error) { return "", err } - rawLlmResponse := C.GoString((*C.char)(stringPtr)) - - baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") - - return rawLlmResponse, nil + return convertString(stringPtr), nil } func (f *FunctionLog) Calls() ([]*LLMCall, error) { @@ -206,13 +244,7 @@ func (f *FunctionLog) Calls() ([]*LLMCall, error) { break } - call := &LLMCall{c: unsafe.Pointer(ptr)} - - runtime.AddCleanup(call, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, llmCallType, "destroy") - }, call.c) - - calls = append(calls, call) + calls = append(calls, wrap(createLLMCall, unsafe.Pointer(ptr))) } baml_go.CallCollectorFunction(callsRaw, "list", "destroy") @@ -244,11 +276,7 @@ func (l *LLMCall) ClientName() (string, error) { return "", err } - clientName := C.GoString((*C.char)(stringPtr)) - - baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") - - return clientName, nil + return convertString(stringPtr), nil } func (l *LLMCall) Provider() (string, error) { @@ -257,11 +285,7 @@ func (l *LLMCall) Provider() (string, error) { return "", err } - provider := C.GoString((*C.char)(stringPtr)) - - baml_go.CallCollectorFunction(stringPtr, stringType, "destroy") - - return provider, nil + return convertString(stringPtr), nil } func (l *LLMCall) Timing() (*Timing, error) { @@ -270,15 +294,7 @@ func (l *LLMCall) Timing() (*Timing, error) { return nil, err } - timing := &Timing{ - c: timingPtr, - } - - runtime.AddCleanup(timing, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, timingType, "destroy") - }, timing.c) - - return timing, nil + return wrap(createTiming, timingPtr), nil } func (l *LLMCall) Usage() (*Usage, error) { @@ -287,13 +303,5 @@ func (l *LLMCall) Usage() (*Usage, error) { return nil, err } - usage := &Usage{ - c: usagePtr, - } - - runtime.AddCleanup(usage, func(c unsafe.Pointer) { - baml_go.CallCollectorFunction(c, usageType, "destroy") - }, usage.c) - - return usage, nil + return wrap(createUsage, usagePtr), nil } From ca905742e74240e1b3fb465e9794ef4ac8176018 Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Tue, 27 May 2025 12:00:52 -0700 Subject: [PATCH 09/10] Add LLMCall.selected --- engine/language_client_cffi/src/lib.rs | 4 ++++ engine/language_client_go/pkg/collector.go | 9 +++++++++ integ-tests/go/test.go | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index da672db889..67e8471678 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -510,6 +510,10 @@ fn call_collector_function_inner( let _ = unsafe { Box::from_raw(object as *mut LLMCall) }; Ok(null()) } + "selected" => { + let selected = if llm_call.selected { 1 } else { 0 }; + Ok(selected as *const libc::c_void) + } _ => Err(anyhow::anyhow!( "Failed to call function: {} on object type: {}", function_name, diff --git a/engine/language_client_go/pkg/collector.go b/engine/language_client_go/pkg/collector.go index 492fc403b5..dff4659e17 100644 --- a/engine/language_client_go/pkg/collector.go +++ b/engine/language_client_go/pkg/collector.go @@ -305,3 +305,12 @@ func (l *LLMCall) Usage() (*Usage, error) { return wrap(createUsage, usagePtr), nil } + +func (l *LLMCall) Selected() (bool, error) { + selectedPtr, err := baml_go.CallCollectorFunction(l.c, llmCallType, "selected") + if err != nil { + return false, err + } + + return int(uintptr(unsafe.Pointer(selectedPtr))) == 1, nil +} diff --git a/integ-tests/go/test.go b/integ-tests/go/test.go index c1830bb5ac..2b7521c5ed 100644 --- a/integ-tests/go/test.go +++ b/integ-tests/go/test.go @@ -131,6 +131,11 @@ func main() { panic(err) } fmt.Printf("call output tokens: %d\n", outputTokens) + selected, err := call.Selected() + if err != nil { + panic(err) + } + fmt.Printf("call selected: %t\n", selected) } // v2, err = b.AaaSamOutputFormat(ctx, "pineapple") From b0a3e20589e57a0ec6fddb7bd1f6300692058f53 Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Thu, 29 May 2025 14:11:44 -0700 Subject: [PATCH 10/10] add more collector interfaces --- .../baml-lib/baml-types/src/tracing/events.rs | 6 +- engine/language_client_cffi/src/lib.rs | 45 ++++++++++++- .../src/raw_ptr_wrapper.rs | 2 + engine/language_client_go/pkg/collector.go | 65 +++++++++++++++++++ integ-tests/go/test.go | 54 ++++++++++++++- 5 files changed, 169 insertions(+), 3 deletions(-) diff --git a/engine/baml-lib/baml-types/src/tracing/events.rs b/engine/baml-lib/baml-types/src/tracing/events.rs index b056bef620..262be82cfe 100644 --- a/engine/baml-lib/baml-types/src/tracing/events.rs +++ b/engine/baml-lib/baml-types/src/tracing/events.rs @@ -247,7 +247,11 @@ impl HTTPBody { } pub fn text(&self) -> anyhow::Result<&str> { - std::str::from_utf8(&self.raw).map_err(|e| anyhow::anyhow!("HTTP body is not UTF-8: {}", e)) + match self.raw.len() { + 0 => Ok(""), + _ => std::str::from_utf8(&self.raw) + .map_err(|e| anyhow::anyhow!("HTTP body is not UTF-8: {}", e)), + } } pub fn json(&self) -> anyhow::Result { diff --git a/engine/language_client_cffi/src/lib.rs b/engine/language_client_cffi/src/lib.rs index 72dcb4500a..1aa6084dc5 100644 --- a/engine/language_client_cffi/src/lib.rs +++ b/engine/language_client_cffi/src/lib.rs @@ -7,8 +7,9 @@ use anyhow::Result; use baml_runtime::client_registry::ClientRegistry; use baml_runtime::tracingv2::storage::storage::{Collector, LLMCall, LLMStreamCall, Timing, Usage}; use baml_runtime::{BamlRuntime, FunctionResult}; +use baml_types::tracing::events::HTTPBody; use once_cell::sync::{Lazy, OnceCell}; -use raw_ptr_wrapper::{CollectorWrapper, FunctionLogWrapper}; +use raw_ptr_wrapper::{CollectorWrapper, FunctionLogWrapper, HTTPResponseWrapper}; use std::ops::Deref; use std::ptr::null_mut; use std::{ @@ -525,6 +526,48 @@ fn call_collector_function_inner( let selected = if llm_call.selected { 1 } else { 0 }; Ok(selected as *const libc::c_void) } + "http_response" => llm_call + .response + .clone() + .map(|r| Arc::into_raw(r) as *const libc::c_void) + .ok_or(anyhow::anyhow!("No response")), + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } + "http_response" => { + let http_response = HTTPResponseWrapper::from_raw(object, true); + match function_name.as_str() { + "destroy" => { + http_response.destroy(); + Ok(null()) + } + "http_body" => { + let http_body = http_response.body.clone(); + Ok(Box::into_raw(Box::new(http_body)) as *const libc::c_void) + } + _ => Err(anyhow::anyhow!( + "Failed to call function: {} on object type: {}", + function_name, + object_type + )), + } + } + "http_body" => { + let http_body = unsafe { &mut *(object as *mut HTTPBody) }; + match function_name.as_str() { + "destroy" => { + let _ = unsafe { Box::from_raw(object as *mut HTTPBody) }; + Ok(null()) + } + "text" => { + let text = http_body.text().unwrap(); + let c_text = CString::new(text).unwrap(); + Ok(c_text.into_raw() as *const libc::c_void) + } _ => Err(anyhow::anyhow!( "Failed to call function: {} on object type: {}", function_name, diff --git a/engine/language_client_cffi/src/raw_ptr_wrapper.rs b/engine/language_client_cffi/src/raw_ptr_wrapper.rs index a6045703ba..d31c8d4a77 100644 --- a/engine/language_client_cffi/src/raw_ptr_wrapper.rs +++ b/engine/language_client_cffi/src/raw_ptr_wrapper.rs @@ -3,6 +3,7 @@ use std::sync::atomic::AtomicBool; use std::sync::{Arc, Mutex}; use baml_runtime::tracingv2::storage::storage::{Collector, FunctionLog}; +use baml_types::tracing::events::HTTPResponse; pub struct RawPtrWrapper { inner: Arc, @@ -41,3 +42,4 @@ impl Drop for RawPtrWrapper { pub type CollectorWrapper = RawPtrWrapper; pub type FunctionLogWrapper = RawPtrWrapper>; +pub type HTTPResponseWrapper = RawPtrWrapper; diff --git a/engine/language_client_go/pkg/collector.go b/engine/language_client_go/pkg/collector.go index dff4659e17..c4db9d3967 100644 --- a/engine/language_client_go/pkg/collector.go +++ b/engine/language_client_go/pkg/collector.go @@ -14,6 +14,8 @@ const functionLogType = "function_log" const stringType = "string" const timingType = "timing" const llmCallType = "llm_call" +const httpResponseType = "http_response" +const httpBodyType = "http_body" type Collector struct { c unsafe.Pointer @@ -99,6 +101,42 @@ func createLLMCall(c unsafe.Pointer) *LLMCall { } } +type HTTPResponse struct { + c unsafe.Pointer +} + +func (h *HTTPResponse) pointer() unsafe.Pointer { + return h.c +} + +func (h *HTTPResponse) rustType() string { + return httpResponseType +} + +func createHTTPResponse(c unsafe.Pointer) *HTTPResponse { + return &HTTPResponse{ + c: c, + } +} + +type HTTPBody struct { + c unsafe.Pointer +} + +func (h *HTTPBody) pointer() unsafe.Pointer { + return h.c +} + +func (h *HTTPBody) rustType() string { + return httpBodyType +} + +func createHTTPBody(c unsafe.Pointer) *HTTPBody { + return &HTTPBody{ + c: c, + } +} + type rustPointer interface { pointer() unsafe.Pointer rustType() string @@ -314,3 +352,30 @@ func (l *LLMCall) Selected() (bool, error) { return int(uintptr(unsafe.Pointer(selectedPtr))) == 1, nil } + +func (l *LLMCall) HTTPResponse() (*HTTPResponse, error) { + httpResponsePtr, err := baml_go.CallCollectorFunction(l.c, llmCallType, "http_response") + if err != nil { + return nil, err + } + + return wrap(createHTTPResponse, httpResponsePtr), nil +} + +func (h *HTTPResponse) Body() (*HTTPBody, error) { + bodyPtr, err := baml_go.CallCollectorFunction(h.c, httpResponseType, "http_body") + if err != nil { + return nil, err + } + + return wrap(createHTTPBody, bodyPtr), nil +} + +func (h *HTTPBody) Text() (string, error) { + textPtr, err := baml_go.CallCollectorFunction(h.c, httpBodyType, "text") + if err != nil { + return "", err + } + + return convertString(textPtr), nil +} diff --git a/integ-tests/go/test.go b/integ-tests/go/test.go index 2b7521c5ed..4b1341eb02 100644 --- a/integ-tests/go/test.go +++ b/integ-tests/go/test.go @@ -13,7 +13,45 @@ func main() { collector := baml.NewCollector() - v2, err := b.AaaSamOutputFormat(ctx, "oranges", b.WithCollector(collector)) + collector2 := baml.NewCollector() + + v2, err := b.AaaSamOutputFormat(ctx, "oranges", b.WithCollector(collector), b.WithCollector(collector2)) + if err != nil { + panic(err) + } + fmt.Println(*v2) + + // go func() { + // time.Sleep(100 * time.Millisecond) + // for { + // last, err := collector2.Last() + // if err != nil { + // panic(err) + // } + + // calls, err := last.Calls() + // if err != nil { + // panic(err) + // } + + // httpResponse, err := calls[0].HTTPResponse() + // if err != nil { + // panic(err) + // } + // fmt.Printf("[go func] http_response: %v\n", httpResponse) + // body, err := httpResponse.Body() + // if err != nil { + // panic(err) + // } + // text, err := body.Text() + // if err != nil { + // panic(err) + // } + // fmt.Printf("[go func] text: %s\n", text) + // } + // }() + + v2, err = b.AaaSamOutputFormat(ctx, "oranges", b.WithCollector(collector), b.WithCollector(collector2)) if err != nil { panic(err) } @@ -136,6 +174,20 @@ func main() { panic(err) } fmt.Printf("call selected: %t\n", selected) + + httpResponse, err := call.HTTPResponse() + if err != nil { + panic(err) + } + body, err := httpResponse.Body() + if err != nil { + panic(err) + } + text, err := body.Text() + if err != nil { + panic(err) + } + fmt.Printf("call http response text: %s\n", text) } // v2, err = b.AaaSamOutputFormat(ctx, "pineapple")