From 30bf88f65c8583ab02db6a7b7db40c1e9f3b05b6 Mon Sep 17 00:00:00 2001 From: hellovai Date: Mon, 8 Jul 2024 10:13:31 -0500 Subject: [PATCH 1/6] Removing stream_options from azure and ollama clients (#760) Only openai supports this at the moment --- .../primitive/openai/openai_client.rs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs index f4e046b0e..8a956e66b 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs @@ -23,6 +23,7 @@ use futures::StreamExt; pub struct OpenAIClient { pub name: String, + provider: String, // client: ClientWalker<'ir>, retry_policy: Option, context: RenderContext_Client, @@ -275,12 +276,14 @@ impl RequestBuilder for OpenAIClient { if stream { body_obj.insert("stream".into(), json!(true)); - body_obj.insert( - "stream_options".into(), - json!({ - "include_usage": true, - }), - ); + if self.provider == "openai" { + body_obj.insert( + "stream_options".into(), + json!({ + "include_usage": true, + }), + ); + } } Ok(req.json(&body)) @@ -403,10 +406,10 @@ impl WithStreamChat for OpenAIClient { } macro_rules! make_openai_client { - ($client:ident, $properties:ident) => { + ($client:ident, $properties:ident, $provider:expr) => { Ok(Self { name: $client.name().into(), - + provider: $provider.into(), context: RenderContext_Client { name: $client.name().into(), provider: $client.elem().provider.clone(), @@ -432,17 +435,17 @@ macro_rules! make_openai_client { impl OpenAIClient { pub fn new(client: &ClientWalker, ctx: &RuntimeContext) -> Result { let properties = resolve_openai_properties(client, ctx)?; - make_openai_client!(client, properties) + make_openai_client!(client, properties, "openai") } pub fn new_ollama(client: &ClientWalker, ctx: &RuntimeContext) -> Result { let properties = resolve_ollama_properties(client, ctx)?; - make_openai_client!(client, properties) + make_openai_client!(client, properties, "ollama") } pub fn new_azure(client: &ClientWalker, ctx: &RuntimeContext) -> Result { let properties = resolve_azure_properties(client, ctx)?; - make_openai_client!(client, properties) + make_openai_client!(client, properties, "azure") } } From f846902690ccffa7708a4b795cfef77fd92cafc7 Mon Sep 17 00:00:00 2001 From: hellovai Date: Mon, 8 Jul 2024 11:53:39 -0500 Subject: [PATCH 2/6] chore: Upgrade to 0.49 (#761) --- CHANGELOG.md | 17 +++++++++-- engine/Cargo.lock | 28 +++++++++---------- engine/Cargo.toml | 2 +- engine/language_client_python/pyproject.toml | 2 +- engine/language_client_ruby/baml.gemspec | 2 +- .../language_client_typescript/package.json | 2 +- tools/versions/engine.cfg | 2 +- tools/versions/python.cfg | 2 +- tools/versions/ruby.cfg | 2 +- tools/versions/typescript.cfg | 2 +- tools/versions/vscode.cfg | 2 +- typescript/vscode-ext/packages/package.json | 2 +- 12 files changed, 38 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4be4d398b..c88a146c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,23 @@ All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines. +## [0.49.0](https://github.com/boundaryml/baml/compare/0.46.0..0.49.0) - 2024-07-08 + +### Bug Fixes +- Fixed Azure / Ollama clients. Removing stream_options from azure and ollama clients (#760) - ([30bf88f](https://github.com/boundaryml/baml/commit/30bf88f65c8583ab02db6a7b7db40c1e9f3b05b6)) - hellovai + +### Features +- Add support for arm64-linux (#751) - ([adb8ee3](https://github.com/boundaryml/baml/commit/adb8ee3097fd386370f75b3ba179d18b952e9678)) - Samuel Lijin + ## [0.48.0](https://github.com/boundaryml/baml/compare/0.47.0..0.48.0) - 2024-07-04 +### Bug Fixes +- Fix env variables dialoge on VSCode (#750) +- Playground selects correct function after loading (#757) - ([09963a0](https://github.com/boundaryml/baml/commit/09963a02e581da9eb8f7bafd3ba812058c97f672)) - aaronvg + -### UNMATCHED -- improve error handling when submitting logs to api (#754) - ([49c768f](https://github.com/boundaryml/baml/commit/49c768fbe8eb8023cba28b8dc68c2553d8b2318a)) - aaronvg -- readd ts files - ([1635bf0](https://github.com/boundaryml/baml/commit/1635bf06f87a18b1f933b6c112cd38044239d5c5)) - Aaron Villalpando +### Miscellaneous Chores +- Better error messages on logging failures to Boundary Studio (#754) - ([49c768f](https://github.com/boundaryml/baml/commit/49c768fbe8eb8023cba28b8dc68c2553d8b2318a)) - aaronvg ## [0.47.0](https://github.com/boundaryml/baml/compare/0.46.0..0.47.0) - 2024-07-03 diff --git a/engine/Cargo.lock b/engine/Cargo.lock index 2e9f3d418..0d0854936 100644 --- a/engine/Cargo.lock +++ b/engine/Cargo.lock @@ -687,7 +687,7 @@ dependencies = [ [[package]] name = "baml" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "baml-lib", @@ -728,7 +728,7 @@ dependencies = [ [[package]] name = "baml-fmt" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "baml-lib", @@ -750,7 +750,7 @@ dependencies = [ [[package]] name = "baml-lib" -version = "0.48.0" +version = "0.49.0" dependencies = [ "base64 0.13.1", "dissimilar", @@ -788,7 +788,7 @@ dependencies = [ [[package]] name = "baml-runtime" -version = "0.48.0" +version = "0.49.0" dependencies = [ "ambassador", "anyhow", @@ -865,7 +865,7 @@ dependencies = [ [[package]] name = "baml-schema-build" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "baml-runtime", @@ -897,7 +897,7 @@ dependencies = [ [[package]] name = "baml-types" -version = "0.48.0" +version = "0.49.0" dependencies = [ "indexmap 2.2.6", "minijinja", @@ -2269,7 +2269,7 @@ dependencies = [ [[package]] name = "internal-baml-codegen" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "askama", @@ -2289,7 +2289,7 @@ dependencies = [ [[package]] name = "internal-baml-core" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "baml-types", @@ -2323,7 +2323,7 @@ dependencies = [ [[package]] name = "internal-baml-diagnostics" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "colored", @@ -2336,7 +2336,7 @@ dependencies = [ [[package]] name = "internal-baml-jinja" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "askama", @@ -2353,7 +2353,7 @@ dependencies = [ [[package]] name = "internal-baml-parser-database" -version = "0.48.0" +version = "0.49.0" dependencies = [ "baml-types", "colored", @@ -2375,7 +2375,7 @@ dependencies = [ [[package]] name = "internal-baml-prompt-parser" -version = "0.48.0" +version = "0.49.0" dependencies = [ "internal-baml-diagnostics", "internal-baml-schema-ast", @@ -2387,7 +2387,7 @@ dependencies = [ [[package]] name = "internal-baml-schema-ast" -version = "0.48.0" +version = "0.49.0" dependencies = [ "baml-types", "either", @@ -2463,7 +2463,7 @@ checksum = "9dbbfed4e59ba9750e15ba154fdfd9329cee16ff3df539c2666b70f58cc32105" [[package]] name = "jsonish" -version = "0.48.0" +version = "0.49.0" dependencies = [ "anyhow", "assert-json-diff", diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 7310a35e2..0ea56de99 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -60,7 +60,7 @@ internal-baml-core = { path = "baml-lib/baml-core" } internal-baml-jinja = { path = "baml-lib/jinja" } [workspace.package] -version = "0.48.0" +version = "0.49.0" authors = ["Boundary "] description = "BAML Toolchain" diff --git a/engine/language_client_python/pyproject.toml b/engine/language_client_python/pyproject.toml index be9e2107c..635489daa 100644 --- a/engine/language_client_python/pyproject.toml +++ b/engine/language_client_python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "baml-py" -version = "0.48.0" +version = "0.49.0" description = "BAML python bindings (pyproject.toml)" readme = "README.md" authors = [["Boundary", "contact@boundaryml.com"]] diff --git a/engine/language_client_ruby/baml.gemspec b/engine/language_client_ruby/baml.gemspec index a8557ba43..a0685918c 100644 --- a/engine/language_client_ruby/baml.gemspec +++ b/engine/language_client_ruby/baml.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |spec| spec.name = "baml" - spec.version = "0.48.0" + spec.version = "0.49.0" spec.authors = ["BoundaryML"] spec.email = ["contact@boundaryml.com"] diff --git a/engine/language_client_typescript/package.json b/engine/language_client_typescript/package.json index c8145e10c..98350c289 100644 --- a/engine/language_client_typescript/package.json +++ b/engine/language_client_typescript/package.json @@ -1,6 +1,6 @@ { "name": "@boundaryml/baml", - "version": "0.48.0", + "version": "0.49.0", "description": "BAML typescript bindings (package.json)", "repository": { "type": "git", diff --git a/tools/versions/engine.cfg b/tools/versions/engine.cfg index f78202871..97a7876b6 100644 --- a/tools/versions/engine.cfg +++ b/tools/versions/engine.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.48.0 +current_version = 0.49.0 commit = False tag = False parse = ^(?P\d+)\.(?P\d+).(?P\d+)$ diff --git a/tools/versions/python.cfg b/tools/versions/python.cfg index 702b4187c..d446bc62d 100644 --- a/tools/versions/python.cfg +++ b/tools/versions/python.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.48.0 +current_version = 0.49.0 commit = False tag = False parse = ^(?P\d+)\.(?P\d+).(?P\d+)$ diff --git a/tools/versions/ruby.cfg b/tools/versions/ruby.cfg index 53c8b1cba..8d0e39a17 100644 --- a/tools/versions/ruby.cfg +++ b/tools/versions/ruby.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.48.0 +current_version = 0.49.0 commit = False tag = False parse = ^(?P\d+)\.(?P\d+).(?P\d+)$ diff --git a/tools/versions/typescript.cfg b/tools/versions/typescript.cfg index 60f32bfc8..f6d422f42 100644 --- a/tools/versions/typescript.cfg +++ b/tools/versions/typescript.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.48.0 +current_version = 0.49.0 commit = False tag = False parse = ^(?P\d+)\.(?P\d+).(?P\d+)$ diff --git a/tools/versions/vscode.cfg b/tools/versions/vscode.cfg index 11605f006..821843ad3 100644 --- a/tools/versions/vscode.cfg +++ b/tools/versions/vscode.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.48.0 +current_version = 0.49.0 commit = False tag = False parse = ^(?P\d+)\.(?P\d+).(?P\d+)$ diff --git a/typescript/vscode-ext/packages/package.json b/typescript/vscode-ext/packages/package.json index 326c99cf6..3fdb69343 100644 --- a/typescript/vscode-ext/packages/package.json +++ b/typescript/vscode-ext/packages/package.json @@ -2,7 +2,7 @@ "name": "baml-extension", "displayName": "Baml", "description": "BAML is a DSL for AI applications.", - "version": "0.48.0", + "version": "0.49.0", "publisher": "Boundary", "repository": "https://github.com/BoundaryML/baml", "homepage": "https://www.boundaryml.com", From adc4da1fa36cc9c30ea36e25de1a6cefcce0bc97 Mon Sep 17 00:00:00 2001 From: aaronvg Date: Mon, 8 Jul 2024 10:12:40 -0700 Subject: [PATCH 3/6] fix env vars button color (#762) --- typescript/playground-common/src/shared/Selectors.tsx | 10 +++++----- .../playground-common/src/shared/SettingsDialog.tsx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/typescript/playground-common/src/shared/Selectors.tsx b/typescript/playground-common/src/shared/Selectors.tsx index 447ae8101..4d7bbe37d 100644 --- a/typescript/playground-common/src/shared/Selectors.tsx +++ b/typescript/playground-common/src/shared/Selectors.tsx @@ -75,7 +75,7 @@ const TestDropdown: React.FC = () => { return (
- + Test {selected && } @@ -128,7 +128,7 @@ const JumpToFunction: React.FC = () => { source_file: selected.span.file_path, value: `${selected.span.file_path.split('/').pop() ?? '.baml'}:${selected.span.start_line + 1}`, }} - className='text-xs text-muted-foreground decoration-0 py-0' + className='py-0 text-xs text-muted-foreground decoration-0' /> ) } @@ -156,7 +156,7 @@ const JumpToTestCase: React.FC = () => { export const ViewSelector: React.FC = () => { return (
-
+
@@ -168,13 +168,13 @@ export const ViewSelector: React.FC = () => { - + diff --git a/typescript/playground-common/src/shared/SettingsDialog.tsx b/typescript/playground-common/src/shared/SettingsDialog.tsx index beef5b68e..7eec05bb1 100644 --- a/typescript/playground-common/src/shared/SettingsDialog.tsx +++ b/typescript/playground-common/src/shared/SettingsDialog.tsx @@ -181,7 +181,7 @@ export const ShowSettingsButton: React.FC<{ iconClassName: string }> = ({ iconCl const button = ( diff --git a/typescript/vscode-ext/packages/vscode/src/extension.ts b/typescript/vscode-ext/packages/vscode/src/extension.ts index 6ab474f90..7cb94b5e8 100644 --- a/typescript/vscode-ext/packages/vscode/src/extension.ts +++ b/typescript/vscode-ext/packages/vscode/src/extension.ts @@ -204,7 +204,7 @@ export function activate(context: vscode.ExtensionContext) { let originalUrl = req.headers['baml-original-url'] if (typeof originalUrl === 'string') { delete req.headers['baml-original-url'] - delete req.headers['baml-render-url'] + req.headers['origin'] = `http://localhost:${port}` // Ensure the URL does not end with a slash From c0fb4540d9193194fcafd7fcef71468442d9e6fa Mon Sep 17 00:00:00 2001 From: hellovai Date: Tue, 9 Jul 2024 22:04:37 -0700 Subject: [PATCH 6/6] Add support for Client Registry (#683) BAML functions now support passing in which model / configuration they use at runtime. * Enables dynamically picking which options they want to run. * Tracing captures dynamic properties * Retry policies must be created in BAML --- docs/docs/calling-baml/client-registry.mdx | 96 +++++ docs/docs/calling-baml/dynamic-clients.mdx | 0 docs/docs/get-started/what-is-baml.mdx | 2 +- docs/docs/snippets/clients/overview.mdx | 23 +- .../docs/snippets/clients/providers/other.mdx | 38 +- docs/mint.json | 13 +- docs/snippets/client-constructor.mdx | 23 ++ .../snippet-example.mdx | 0 .../baml-runtime/src/client_registry/mod.rs | 61 +++ .../src/internal/llm_client/llm_provider.rs | 30 +- .../src/internal/llm_client/mod.rs | 23 ++ .../primitive/anthropic/anthropic_client.rs | 57 ++- .../primitive/google/google_client.rs | 100 ++--- .../src/internal/llm_client/primitive/mod.rs | 61 ++- .../primitive/openai/openai_client.rs | 74 +++- .../primitive/openai/properties/azure.rs | 17 +- .../primitive/openai/properties/ollama.rs | 17 +- .../primitive/openai/properties/openai.rs | 20 +- .../internal/llm_client/strategy/fallback.rs | 89 ++-- .../src/internal/llm_client/strategy/mod.rs | 40 +- .../llm_client/strategy/roundrobin.rs | 141 ++++--- .../src/internal/prompt_renderer/mod.rs | 5 +- engine/baml-runtime/src/lib.rs | 64 +-- .../src/runtime/runtime_interface.rs | 8 + engine/baml-runtime/src/runtime_interface.rs | 2 +- engine/baml-runtime/src/tracing/mod.rs | 13 +- .../baml-runtime/src/types/context_manager.rs | 31 +- .../baml-runtime/src/types/runtime_context.rs | 5 +- engine/baml-runtime/src/types/stream.rs | 43 +- engine/baml-runtime/tests/test_runtime.rs | 2 +- .../src/python/templates/client.py.j2 | 6 +- .../src/typescript/templates/client.ts.j2 | 8 +- .../python_src/baml_py/__init__.py | 2 + .../python_src/baml_py/baml_py.pyi | 13 + .../python_src/baml_py/stream.py | 4 - engine/language_client_python/src/lib.rs | 1 + engine/language_client_python/src/runtime.rs | 12 +- .../src/types/client_registry.rs | 56 +++ .../src/types/function_result_stream.rs | 10 +- .../language_client_python/src/types/mod.rs | 2 + .../language_client_python/src/types/span.rs | 2 +- .../ruby_ffi/src/function_result_stream.rs | 10 +- .../ext/ruby_ffi/src/lib.rs | 31 +- engine/language_client_typescript/index.d.ts | 2 +- .../language_client_typescript/index.d.ts.map | 2 +- engine/language_client_typescript/index.js | 4 +- engine/language_client_typescript/native.d.ts | 10 +- engine/language_client_typescript/native.js | 1 + .../language_client_typescript/src/runtime.rs | 17 +- .../src/types/client_registry.rs | 58 +++ .../src/types/function_result_stream.rs | 22 +- .../src/types/function_results.rs | 2 +- .../src/types/mod.rs | 1 + .../src/types/span.rs | 8 +- .../typescript_src/index.ts | 2 + integ-tests/python/baml_client/client.py | 316 ++++++++++++--- integ-tests/python/tests/test_functions.py | 13 + integ-tests/typescript/baml_client/client.ts | 380 ++++++++++++------ .../typescript/tests/integ-tests.test.ts | 16 +- 59 files changed, 1536 insertions(+), 573 deletions(-) create mode 100644 docs/docs/calling-baml/client-registry.mdx delete mode 100644 docs/docs/calling-baml/dynamic-clients.mdx create mode 100644 docs/snippets/client-constructor.mdx rename docs/{_snippets => snippets}/snippet-example.mdx (100%) create mode 100644 engine/baml-runtime/src/client_registry/mod.rs create mode 100644 engine/language_client_python/src/types/client_registry.rs create mode 100644 engine/language_client_typescript/src/types/client_registry.rs diff --git a/docs/docs/calling-baml/client-registry.mdx b/docs/docs/calling-baml/client-registry.mdx new file mode 100644 index 000000000..a013dff97 --- /dev/null +++ b/docs/docs/calling-baml/client-registry.mdx @@ -0,0 +1,96 @@ +--- +title: "Client Registry" +--- + +If you need to modify the model / parameters for an LLM client at runtime, you can modify the `ClientRegistry` for any specified function. + + + +```python Python +from baml_py import ClientRegistry + +async def run(): + cr = ClientRegistry() + # Creates a new client + cr.add_llm_client(name='MyAmazingClient', provider='openai', options={ + "model": "gpt-4o", + "temperature": 0.7, + "api_key": "sk-..." + }) + # Sets MyAmazingClient as the primary client + cr.set_primary('MyAmazingClient') + + # ExtractResume will now use MyAmazingClient as the calling client + res = await b.ExtractResume("...", { "client_registry": cr }) +``` + +```typescript TypeScript +import { ClientRegistry } from '@boundaryml/baml' + +async function run() { + const cr = new ClientRegistry() + // Creates a new client + cr.addLlmClient({ name: 'MyAmazingClient', provider: 'openai', options: { + model: "gpt-4o", + temperature: 0.7, + api_key: "sk-..." + }}) + // Sets MyAmazingClient as the primary client + cr.setPrimary('MyAmazingClient') + + // ExtractResume will now use MyAmazingClient as the calling client + const res = await b.ExtractResume("...", { clientRegistry: cr }) +} +``` + +```ruby Ruby +Not available yet +``` + + + +## ClientRegistry Interface +import ClientConstructorParams from '/snippets/client-params.mdx' + + + + Note: `ClientRegistry` is imported from `baml_py` in Python and `@boundaryml/baml` in TypeScript, not `baml_client`. + + As we mature `ClientRegistry`, we will add a more type-safe and ergonomic interface directly in `baml_client`. See [Github issue #766](https://github.com/BoundaryML/baml/issues/766). + + +Methods use `snake_case` in Python and `camelCase` in TypeScript. + +### add_llm_client / addLlmClient +A function to add an LLM client to the registry. + + + The name of the client. + + + Using the exact same name as a client also defined in .baml files overwrites the existing client whenever the ClientRegistry is used. + + + + + + +The name of a retry policy that is already defined in a .baml file. See [Retry Policies](/docs/snippets/clients/retry.mdx). + + +### set_primary / setPrimary +This sets the client for the function to use. (i.e. replaces the `client` property in a function) + + + The name of the client to use. + + This can be a new client that was added with `add_llm_client` or an existing client that is already in a .baml file. + diff --git a/docs/docs/calling-baml/dynamic-clients.mdx b/docs/docs/calling-baml/dynamic-clients.mdx deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/docs/get-started/what-is-baml.mdx b/docs/docs/get-started/what-is-baml.mdx index 72ad88aa9..b6f3bb13b 100644 --- a/docs/docs/get-started/what-is-baml.mdx +++ b/docs/docs/get-started/what-is-baml.mdx @@ -52,7 +52,7 @@ Share your creations and ask questions in our [Discord](https://discord.gg/BTNBe ## Starter projects - [BAML + NextJS 14 + Streaming](https://github.com/BoundaryML/baml-examples/tree/main/nextjs-starter) -- [BAML + FastAPI + Streaming](https://github.com/BoundaryML/baml-examples/tree/main/fastapi-starter) +- [BAML + FastAPI + Streaming](https://github.com/BoundaryML/baml-examples/tree/main/python-fastapi-starter) ## First steps We recommend checking the examples in [PromptFiddle.com](https://promptfiddle.com). Once you're ready to start, [install the toolchain](/docs/get-started/quickstart/python) and read the [guides](/docs/calling-baml/calling-functions). diff --git a/docs/docs/snippets/clients/overview.mdx b/docs/docs/snippets/clients/overview.mdx index e2a8f88da..96654cb2c 100644 --- a/docs/docs/snippets/clients/overview.mdx +++ b/docs/docs/snippets/clients/overview.mdx @@ -25,30 +25,11 @@ function MakeHaiku(topic: string) -> string { ## Fields - -This configures which provider to use. The provider is responsible for handling the actual API calls to the LLM service. The provider is a required field. +import ClientConstructorParams from '/snippets/client-constructor.mdx' -The configuration modifies the URL request BAML runtime makes. - -| Provider Name | Docs | Notes | -| -------------- | -------------------------------- | ---------------------------------------------------------- | -| `openai` | [OpenAI](providers/openai) | Anything that follows openai's API exactly | -| `ollama` | [Ollama](providers/ollama) | Alias for an openai client but with default ollama options | -| `azure-openai` | [Azure OpenAI](providers/azure) | | -| `anthropic` | [Anthropic](providers/anthropic) | | -| `google-ai` | [Google AI](providers/gemini) | | -| `fallback` | [Fallback](fallback) | Used to chain models conditional on failures | -| `round-robin` | [Round Robin](round-robin) | Used to load balance | - - + The name of the retry policy. See [Retry Policy](/docs/snippets/clients/retry). - - - These vary per provider. Please see provider specific documentation for more - information. Generally they are pass through options to the POST request made - to the LLM. - diff --git a/docs/docs/snippets/clients/providers/other.mdx b/docs/docs/snippets/clients/providers/other.mdx index 33ee98a34..057745b15 100644 --- a/docs/docs/snippets/clients/providers/other.mdx +++ b/docs/docs/snippets/clients/providers/other.mdx @@ -1,5 +1,5 @@ --- -title: Others (e.g. openrouter) +title: Others (e.g. groq, openrouter) --- Since many model providers are settling on following the OpenAI Chat API spec, the recommended way to use them is to use the `openai` provider. @@ -26,3 +26,39 @@ client MyClient { } } ``` + +### Groq + +https://groq.com - Fast AI Inference + +You can use Groq's openai interface with BAML. + +See https://console.groq.com/docs/openai for more information. + +```rust BAML +client MyClient { + provider openai + options { + base_url "https://api.groq.com/openai/v1" + api_key env.GROQ_API_KEY + model "llama3-70b-8192" + } +} +``` + +### Together AI + +https://www.together.ai/ - The fastest cloud platform for building and running generative AI. + +See https://docs.together.ai/docs/openai-api-compatibility for more information. + +```rust BAML +client MyClient { + provider openai + options { + base_url "https://api.together.ai/v1" + api_key env.TOGETHER_API_KEY + model "meta-llama/Llama-3-70b-chat-hf" + } +} +``` diff --git a/docs/mint.json b/docs/mint.json index 45a21b030..d74e34cef 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -137,16 +137,21 @@ ] }, { - "group": "Calling BAML Functions", + "group": "Advanced BAML Snippets", + "pages": [ + "docs/calling-baml/dynamic-types", + "docs/calling-baml/client-registry" + ] + }, + { + "group": "BAML with Python/TS/Ruby", "pages": [ "docs/calling-baml/generate-baml-client", "docs/calling-baml/set-env-vars", "docs/calling-baml/calling-functions", "docs/calling-baml/streaming", "docs/calling-baml/concurrent-calls", - "docs/calling-baml/multi-modal", - "docs/calling-baml/dynamic-types", - "docs/calling-baml/dynamic-clients" + "docs/calling-baml/multi-modal" ] }, { diff --git a/docs/snippets/client-constructor.mdx b/docs/snippets/client-constructor.mdx new file mode 100644 index 000000000..63256bf33 --- /dev/null +++ b/docs/snippets/client-constructor.mdx @@ -0,0 +1,23 @@ + +This configures which provider to use. The provider is responsible for handling the actual API calls to the LLM service. The provider is a required field. + +The configuration modifies the URL request BAML runtime makes. + +| Provider Name | Docs | Notes | +| -------------- | -------------------------------- | ---------------------------------------------------------- | +| `openai` | [OpenAI](/docs/snippets/clients/providers/openai) | Anything that follows openai's API exactly | +| `ollama` | [Ollama](/docs/snippets/clients/providers/ollama) | Alias for an openai client but with default ollama options | +| `azure-openai` | [Azure OpenAI](/docs/snippets/clients/providers/azure) | | +| `anthropic` | [Anthropic](/docs/snippets/clients/providers/anthropic) | | +| `google-ai` | [Google AI](/docs/snippets/clients/providers/gemini) | | +| `fallback` | [Fallback](/docs/snippets/clients/fallback) | Used to chain models conditional on failures | +| `round-robin` | [Round Robin](/docs/snippets/clients/round-robin) | Used to load balance | + + + + +These vary per provider. Please see provider specific documentation for more +information. Generally they are pass through options to the POST request made +to the LLM. + + diff --git a/docs/_snippets/snippet-example.mdx b/docs/snippets/snippet-example.mdx similarity index 100% rename from docs/_snippets/snippet-example.mdx rename to docs/snippets/snippet-example.mdx diff --git a/engine/baml-runtime/src/client_registry/mod.rs b/engine/baml-runtime/src/client_registry/mod.rs new file mode 100644 index 000000000..ed5e6d2ff --- /dev/null +++ b/engine/baml-runtime/src/client_registry/mod.rs @@ -0,0 +1,61 @@ +// This is designed to build any type of client, not just primitives +use anyhow::{Context, Result}; +use std::collections::HashMap; +use std::sync::Arc; + +use baml_types::{BamlMap, BamlValue}; +use serde::Serialize; + +use crate::{internal::llm_client::llm_provider::LLMProvider, RuntimeContext}; + +#[derive(Clone)] +pub enum PrimitiveClient { + OpenAI, + Anthropic, + Google, +} + +#[derive(Serialize, Clone)] +pub struct ClientProperty { + pub name: String, + pub provider: String, + pub retry_policy: Option, + pub options: BamlMap, +} + +#[derive(Clone)] +pub struct ClientRegistry { + clients: HashMap, + primary: Option, +} + +impl ClientRegistry { + pub fn new() -> Self { + Self { + clients: Default::default(), + primary: None, + } + } + + pub fn add_client(&mut self, client: ClientProperty) { + self.clients.insert(client.name.clone(), client); + } + + pub fn set_primary(&mut self, primary: String) { + self.primary = Some(primary); + } + + pub fn to_clients( + &self, + ctx: &RuntimeContext, + ) -> Result<(Option, HashMap>)> { + let mut clients = HashMap::new(); + for (name, client) in &self.clients { + let provider = LLMProvider::try_from((client, ctx)) + .context(format!("Failed to parse client: {}", name))?; + clients.insert(name.into(), Arc::new(provider)); + } + // TODO: Also do validation here + Ok((self.primary.clone(), clients)) + } +} diff --git a/engine/baml-runtime/src/internal/llm_client/llm_provider.rs b/engine/baml-runtime/src/internal/llm_client/llm_provider.rs index 46f364eb7..0e80d72d7 100644 --- a/engine/baml-runtime/src/internal/llm_client/llm_provider.rs +++ b/engine/baml-runtime/src/internal/llm_client/llm_provider.rs @@ -3,7 +3,9 @@ use std::sync::Arc; use anyhow::Result; use internal_baml_core::ir::ClientWalker; -use crate::{runtime_interface::InternalClientLookup, RuntimeContext}; +use crate::{ + client_registry::ClientProperty, runtime_interface::InternalClientLookup, RuntimeContext, +}; use super::{ orchestrator::{ @@ -20,6 +22,15 @@ pub enum LLMProvider { Strategy(LLMStrategyProvider), } +impl std::fmt::Debug for LLMProvider { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + LLMProvider::Primitive(provider) => write!(f, "Primitive({})", provider), + LLMProvider::Strategy(provider) => write!(f, "Strategy({})", provider), + } + } +} + impl WithRetryPolicy for LLMProvider { fn retry_policy_name(&self) -> Option<&str> { match self { @@ -37,7 +48,22 @@ impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for LLMProvider { "baml-fallback" | "fallback" | "baml-round-robin" | "round-robin" => { LLMStrategyProvider::try_from((client, ctx)).map(LLMProvider::Strategy) } - _name => LLMPrimitiveProvider::try_from((client, ctx)) + _ => LLMPrimitiveProvider::try_from((client, ctx)) + .map(Arc::new) + .map(LLMProvider::Primitive), + } + } +} + +impl TryFrom<(&ClientProperty, &RuntimeContext)> for LLMProvider { + type Error = anyhow::Error; + + fn try_from(value: (&ClientProperty, &RuntimeContext)) -> Result { + match value.0.provider.as_str() { + "baml-fallback" | "fallback" | "baml-round-robin" | "round-robin" => { + LLMStrategyProvider::try_from(value).map(LLMProvider::Strategy) + } + _ => LLMPrimitiveProvider::try_from(value) .map(Arc::new) .map(LLMProvider::Primitive), } diff --git a/engine/baml-runtime/src/internal/llm_client/mod.rs b/engine/baml-runtime/src/internal/llm_client/mod.rs index 7fbfafa16..63b8cdaf7 100644 --- a/engine/baml-runtime/src/internal/llm_client/mod.rs +++ b/engine/baml-runtime/src/internal/llm_client/mod.rs @@ -11,6 +11,7 @@ pub mod traits; use anyhow::Result; +use internal_baml_core::ir::ClientWalker; use internal_baml_jinja::RenderedPrompt; use serde::Serialize; use std::error::Error; @@ -169,3 +170,25 @@ impl std::fmt::Display for LLMCompleteResponse { write!(f, "{}", self.content.dimmed()) } } + +// For parsing args +fn resolve_properties_walker( + client: &ClientWalker, + ctx: &crate::RuntimeContext, +) -> Result> { + use anyhow::Context; + (&client.item.elem.options) + .iter() + .map(|(k, v)| { + Ok(( + k.into(), + ctx.resolve_expression::(v) + .context(format!( + "client {} could not resolve options.{}", + client.name(), + k + ))?, + )) + }) + .collect::>>() +} diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs index bae08a9c7..21a67f6c2 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs @@ -10,6 +10,7 @@ use internal_baml_jinja::{ }; use crate::{ + client_registry::ClientProperty, internal::llm_client::{ primitive::{ anthropic::types::{AnthropicMessageResponse, StopReason}, @@ -56,23 +57,9 @@ pub struct AnthropicClient { // resolves/constructs PostRequestProperties from the client's options and runtime context, fleshing out the needed headers and parameters // basically just reads the client's options and matches them to needed properties or defaults them fn resolve_properties( - client: &ClientWalker, + mut properties: HashMap, ctx: &RuntimeContext, ) -> Result { - let mut properties = (&client.item.elem.options) - .iter() - .map(|(k, v)| { - Ok(( - k.into(), - ctx.resolve_expression::(v) - .context(format!( - "client {} could not resolve options.{}", - client.name(), - k - ))?, - )) - }) - .collect::>>()?; // this is a required field properties .entry("max_tokens".into()) @@ -298,17 +285,46 @@ impl WithStreamChat for AnthropicClient { // constructs base client and resolves properties based on context impl AnthropicClient { - pub fn new(client: &ClientWalker, ctx: &RuntimeContext) -> Result { - let post_properties = resolve_properties(client, ctx)?; - let default_role = post_properties.default_role.clone(); // clone before moving + pub fn dynamic_new(client: &ClientProperty, ctx: &RuntimeContext) -> Result { + let properties = resolve_properties( + client + .options + .iter() + .map(|(k, v)| Ok((k.clone(), json!(v)))) + .collect::>>()?, + ctx, + )?; + let default_role = properties.default_role.clone(); + Ok(Self { + name: client.name.clone(), + properties, + context: RenderContext_Client { + name: client.name.clone(), + provider: client.provider.clone(), + default_role, + }, + features: ModelFeatures { + chat: true, + completion: false, + anthropic_system_constraints: true, + resolve_media_urls: true, + }, + retry_policy: client.retry_policy.clone(), + client: create_client()?, + }) + } + pub fn new(client: &ClientWalker, ctx: &RuntimeContext) -> Result { + let properties = super::super::resolve_properties_walker(client, ctx)?; + let properties = resolve_properties(properties, ctx)?; + let default_role = properties.default_role.clone(); Ok(Self { name: client.name().into(), - properties: post_properties, + properties, context: RenderContext_Client { name: client.name().into(), provider: client.elem().provider.clone(), - default_role: default_role, + default_role, }, features: ModelFeatures { chat: true, @@ -346,6 +362,7 @@ impl RequestBuilder for AnthropicClient { } else { &self.properties.base_url }; + let mut req = self.client.post(if prompt.is_left() { format!("{}/v1/complete", destination_url) } else { diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/google/google_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/google/google_client.rs index 0cc977d5b..145594dc3 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/google/google_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/google/google_client.rs @@ -1,3 +1,4 @@ +use crate::client_registry::ClientProperty; use crate::RuntimeContext; use crate::{ internal::llm_client::{ @@ -42,25 +43,9 @@ pub struct GoogleClient { } fn resolve_properties( - client: &ClientWalker, + mut properties: HashMap, ctx: &RuntimeContext, ) -> Result { - let mut properties = (&client.item.elem.options) - .iter() - .map(|(k, v)| { - Ok(( - k.into(), - ctx.resolve_expression::(v) - .context(format!( - "client {} could not resolve options.{}", - client.name(), - k - ))?, - )) - }) - .collect::>>()?; - // this is a required field - let default_role = properties .remove("default_role") .and_then(|v| v.as_str().map(|s| s.to_string())) @@ -240,17 +225,17 @@ impl WithStreamChat for GoogleClient { } impl GoogleClient { - pub fn new(client: &ClientWalker, ctx: &RuntimeContext) -> Result { - let post_properties = resolve_properties(client, ctx)?; - let default_role = post_properties.default_role.clone(); // clone before moving - + pub fn new(client: &ClientWalker, ctx: &RuntimeContext) -> Result { + let properties = super::super::resolve_properties_walker(client, ctx)?; + let properties = resolve_properties(properties, ctx)?; + let default_role = properties.default_role.clone(); Ok(Self { name: client.name().into(), - properties: post_properties, + properties, context: RenderContext_Client { name: client.name().into(), provider: client.elem().provider.clone(), - default_role: default_role, + default_role, }, features: ModelFeatures { chat: true, @@ -266,6 +251,36 @@ impl GoogleClient { client: create_client()?, }) } + + pub fn dynamic_new(client: &ClientProperty, ctx: &RuntimeContext) -> Result { + let properties = resolve_properties( + client + .options + .iter() + .map(|(k, v)| Ok((k.clone(), json!(v)))) + .collect::>>()?, + ctx, + )?; + let default_role = properties.default_role.clone(); + + Ok(Self { + name: client.name.clone(), + properties, + context: RenderContext_Client { + name: client.name.clone(), + provider: client.provider.clone(), + default_role, + }, + features: ModelFeatures { + chat: true, + completion: false, + anthropic_system_constraints: false, + resolve_media_urls: true, + }, + retry_policy: client.retry_policy.clone(), + client: create_client()?, + }) + } } impl RequestBuilder for GoogleClient { @@ -284,38 +299,24 @@ impl RequestBuilder for GoogleClient { should_stream = "streamGenerateContent?alt=sse"; } - let destination_url = if allow_proxy { - self.properties - .proxy_url - .as_ref() - .unwrap_or(&"".to_string()) - .clone() - } else { - format!( - "{}/models/{}:{}", - self.properties.base_url, - self.properties.model_id.as_ref().unwrap_or(&"".to_string()), - should_stream - ) + let baml_original_url = format!( + "{}/models/{}:{}", + self.properties.base_url, + self.properties.model_id.as_ref().unwrap_or(&"".to_string()), + should_stream + ); + let mut req = match (&self.properties.proxy_url, allow_proxy) { + (Some(proxy_url), true) => { + let req = self.client.post(proxy_url.clone()); + req.header("baml-original-url", baml_original_url) + } + _ => self.client.post(baml_original_url), }; - let mut req = self.client.post(destination_url); - for (key, value) in &self.properties.headers { req = req.header(key, value); } - if allow_proxy { - let baml_original_url = format!( - "{}/models/{}:{}", - self.properties.base_url, - self.properties.model_id.as_ref().unwrap_or(&"".to_string()), - should_stream - ); - - req = req.header("baml-original-url", baml_original_url.clone()); - } - req = req.header( "x-goog-api-key", self.properties @@ -337,6 +338,7 @@ impl RequestBuilder for GoogleClient { Ok(req.json(&body)) } + fn request_options(&self) -> &HashMap { &self.properties.properties } diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/mod.rs b/engine/baml-runtime/src/internal/llm_client/primitive/mod.rs index 4889f27b9..a75ed49d3 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/mod.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/mod.rs @@ -5,8 +5,8 @@ use baml_types::BamlValue; use internal_baml_core::ir::{repr::IntermediateRepr, ClientWalker}; use crate::{ - internal::prompt_renderer::PromptRenderer, runtime_interface::InternalClientLookup, - RuntimeContext, + client_registry::ClientProperty, internal::prompt_renderer::PromptRenderer, + runtime_interface::InternalClientLookup, RuntimeContext, }; use self::{ @@ -53,25 +53,6 @@ pub enum LLMPrimitiveProvider { Aws(aws::AwsClient), } -// impl WithRetryPolicy for LLMPrimitiveProvider { -// fn retry_policy_name(&self) -> Option<&str> { -// match self { -// LLMPrimitiveProvider::OpenAI(client) => { -// LLMPrimitive2::OpenAIClient(client).retry_policy_name() -// } -// LLMPrimitiveProvider::Anthropic(client) => { -// LLMPrimitive2::AnthropicClient(client).retry_policy_name() -// } -// LLMPrimitiveProvider::Google(client) => { -// LLMPrimitive2::GoogleClient(client).retry_policy_name() -// } -// LLMPrimitiveProvider::Aws(client) => { -// LLMPrimitive2::AwsClient(client).retry_policy_name() -// } -// } -// } -// } - macro_rules! match_llm_provider { // Define the variants inside the macro ($self:expr, $method:ident, async $(, $args:tt)*) => { @@ -99,6 +80,42 @@ impl WithRetryPolicy for LLMPrimitiveProvider { } } +impl TryFrom<(&ClientProperty, &RuntimeContext)> for LLMPrimitiveProvider { + type Error = anyhow::Error; + + fn try_from((value, ctx): (&ClientProperty, &RuntimeContext)) -> Result { + match value.provider.as_str() { + "openai" => OpenAIClient::dynamic_new(value, ctx).map(LLMPrimitiveProvider::OpenAI), + "azure-openai" => { + OpenAIClient::dynamic_new_azure(value, ctx).map(LLMPrimitiveProvider::OpenAI) + } + "ollama" => { + OpenAIClient::dynamic_new_ollama(value, ctx).map(LLMPrimitiveProvider::OpenAI) + } + "anthropic" => { + AnthropicClient::dynamic_new(value, ctx).map(LLMPrimitiveProvider::Anthropic) + } + "google-ai" => GoogleClient::dynamic_new(value, ctx).map(LLMPrimitiveProvider::Google), + other => { + let options = [ + "openai", + "anthropic", + "ollama", + "google-ai", + "azure-openai", + "fallback", + "round-robin", + ]; + anyhow::bail!( + "Unsupported provider: {}. Available ones are: {}", + other, + options.join(", ") + ) + } + } + } +} + impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for LLMPrimitiveProvider { type Error = anyhow::Error; @@ -217,3 +234,5 @@ impl LLMPrimitiveProvider { match_llm_provider!(self, request_options) } } + +use super::resolve_properties_walker; diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs index b7fde1766..6b079cbd4 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs @@ -7,6 +7,7 @@ use internal_baml_jinja::{ChatMessagePart, RenderContext_Client, RenderedChatMes use serde_json::json; +use crate::client_registry::ClientProperty; use crate::internal::llm_client::primitive::request::{ make_parsed_request, make_request, RequestBuilder, }; @@ -201,7 +202,7 @@ use crate::internal::llm_client::{ }; use super::properties::{ - resolve_azure_properties, resolve_ollama_properties, resolve_openai_properties, + self, resolve_azure_properties, resolve_ollama_properties, resolve_openai_properties, PostRequestProperities, }; use super::types::{ChatCompletionResponse, ChatCompletionResponseDelta, FinishReason}; @@ -401,6 +402,26 @@ impl WithStreamChat for OpenAIClient { } macro_rules! make_openai_client { + ($client:ident, $properties:ident, $provider:expr, dynamic) => { + Ok(Self { + name: $client.name.clone(), + provider: $provider.into(), + context: RenderContext_Client { + name: $client.name.clone(), + provider: $client.provider.clone(), + default_role: $properties.default_role.clone(), + }, + properties: $properties, + features: ModelFeatures { + chat: true, + completion: false, + anthropic_system_constraints: false, + resolve_media_urls: false, + }, + retry_policy: $client.retry_policy.clone(), + client: create_client()?, + }) + }; ($client:ident, $properties:ident, $provider:expr) => { Ok(Self { name: $client.name().into(), @@ -429,19 +450,64 @@ macro_rules! make_openai_client { impl OpenAIClient { pub fn new(client: &ClientWalker, ctx: &RuntimeContext) -> Result { - let properties = resolve_openai_properties(client, ctx)?; + let properties = super::super::resolve_properties_walker(client, ctx)?; + let properties = resolve_openai_properties(properties, ctx)?; make_openai_client!(client, properties, "openai") } pub fn new_ollama(client: &ClientWalker, ctx: &RuntimeContext) -> Result { - let properties = resolve_ollama_properties(client, ctx)?; + let properties = super::super::resolve_properties_walker(client, ctx)?; + let properties = resolve_ollama_properties(properties, ctx)?; make_openai_client!(client, properties, "ollama") } pub fn new_azure(client: &ClientWalker, ctx: &RuntimeContext) -> Result { - let properties = resolve_azure_properties(client, ctx)?; + let properties = super::super::resolve_properties_walker(client, ctx)?; + let properties = resolve_azure_properties(properties, ctx)?; make_openai_client!(client, properties, "azure") } + + pub fn dynamic_new(client: &ClientProperty, ctx: &RuntimeContext) -> Result { + let properties = resolve_openai_properties( + client + .options + .iter() + .map(|(k, v)| Ok((k.clone(), json!(v)))) + .collect::>>()?, + &ctx, + )?; + make_openai_client!(client, properties, "openai", dynamic) + } + + pub fn dynamic_new_ollama( + client: &ClientProperty, + ctx: &RuntimeContext, + ) -> Result { + let properties = resolve_ollama_properties( + client + .options + .iter() + .map(|(k, v)| Ok((k.clone(), json!(v)))) + .collect::>>()?, + ctx, + )?; + make_openai_client!(client, properties, "ollama", dynamic) + } + + pub fn dynamic_new_azure( + client: &ClientProperty, + ctx: &RuntimeContext, + ) -> Result { + let properties = resolve_azure_properties( + client + .options + .iter() + .map(|(k, v)| Ok((k.clone(), json!(v)))) + .collect::>>()?, + ctx, + )?; + make_openai_client!(client, properties, "azure", dynamic) + } } fn convert_message_parts_to_content(parts: &Vec) -> serde_json::Value { diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/azure.rs b/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/azure.rs index a95aeff7d..e01af2b37 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/azure.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/azure.rs @@ -8,26 +8,11 @@ use crate::RuntimeContext; use super::PostRequestProperities; pub fn resolve_properties( - client: &ClientWalker, + mut properties: HashMap, ctx: &RuntimeContext, ) -> Result { // POST https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version} - let mut properties = (&client.item.elem.options) - .iter() - .map(|(k, v)| { - Ok(( - k.into(), - ctx.resolve_expression::(v) - .context(format!( - "client {} could not resolve options.{}", - client.name(), - k - ))?, - )) - }) - .collect::>>()?; - let default_role = properties .remove("default_role") .and_then(|v| v.as_str().map(|s| s.to_string())) diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/ollama.rs b/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/ollama.rs index 5f1b6faa7..55fdc9b71 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/ollama.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/ollama.rs @@ -8,24 +8,9 @@ use crate::RuntimeContext; use super::PostRequestProperities; pub fn resolve_properties( - client: &ClientWalker, + mut properties: HashMap, ctx: &RuntimeContext, ) -> Result { - let mut properties = (&client.item.elem.options) - .iter() - .map(|(k, v)| { - Ok(( - k.into(), - ctx.resolve_expression::(v) - .context(format!( - "client {} could not resolve options.{}", - client.name(), - k - ))?, - )) - }) - .collect::>>()?; - let default_role = properties .remove("default_role") .and_then(|v| v.as_str().map(|s| s.to_string())) diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/openai.rs b/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/openai.rs index 0cb5d05bd..d89b8b5ae 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/openai.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/openai.rs @@ -1,31 +1,15 @@ use std::collections::HashMap; -use anyhow::{Context, Result}; -use internal_baml_core::ir::ClientWalker; +use anyhow::Result; use crate::RuntimeContext; use super::PostRequestProperities; pub fn resolve_properties( - client: &ClientWalker, + mut properties: HashMap, ctx: &RuntimeContext, ) -> Result { - let mut properties = (&client.item.elem.options) - .iter() - .map(|(k, v)| { - Ok(( - k.into(), - ctx.resolve_expression::(v) - .context(format!( - "client {} could not resolve options.{}", - client.name(), - k - ))?, - )) - }) - .collect::>>()?; - let default_role = properties .remove("default_role") .and_then(|v| v.as_str().map(|s| s.to_string())) diff --git a/engine/baml-runtime/src/internal/llm_client/strategy/fallback.rs b/engine/baml-runtime/src/internal/llm_client/strategy/fallback.rs index a75f0015a..b8aafa93b 100644 --- a/engine/baml-runtime/src/internal/llm_client/strategy/fallback.rs +++ b/engine/baml-runtime/src/internal/llm_client/strategy/fallback.rs @@ -1,8 +1,11 @@ +use std::collections::HashMap; + use anyhow::{Context, Result}; use internal_baml_core::ir::ClientWalker; use crate::{ + client_registry::ClientProperty, internal::llm_client::orchestrator::{ ExecutionScope, IterOrchestrator, OrchestrationScope, OrchestrationState, }, @@ -16,47 +19,67 @@ pub struct FallbackStrategy { // TODO: We can add conditions to each client clients: Vec, } -impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for FallbackStrategy { + +impl TryFrom<(&ClientProperty, &RuntimeContext)> for FallbackStrategy { type Error = anyhow::Error; - fn try_from((client, ctx): (&ClientWalker, &RuntimeContext)) -> Result { - let properties = &client.item.elem.options; + fn try_from( + (client, ctx): (&ClientProperty, &RuntimeContext), + ) -> std::result::Result { + let strategy = resolve_properties( + client + .options + .iter() + .map(|(k, v)| Ok((k.clone(), serde_json::json!(v)))) + .collect::>>()?, + ctx, + )?; + Ok(Self { + name: client.name.clone(), + retry_policy: client.retry_policy.clone(), + clients: strategy, + }) + } +} - let mut unknown_keys = vec![]; +fn resolve_properties( + mut properties: HashMap, + ctx: &RuntimeContext, +) -> Result> { + let strategy = properties + .remove("strategy") + .map(|v| serde_json::from_value::>(v)) + .transpose() + .context("Failed to resolve strategy into string[]")?; - let mut strategy = None; - for (key, value) in properties { - match key.as_str() { - "strategy" => { - let clients = ctx - .resolve_expression::>(value) - .context("Failed to resolve strategy expression into string[]"); - strategy = Some(clients); - } - other => unknown_keys.push(other), - }; + let strategy = if let Some(strategy) = strategy { + if strategy.is_empty() { + anyhow::bail!("Empty strategy array, at least one client is required"); } + strategy + } else { + anyhow::bail!("Missing a strategy field"); + }; - if !unknown_keys.is_empty() { - let supported_keys = ["strategy"]; - anyhow::bail!( - "Unknown keys: {}. Supported keys are: {}", - unknown_keys.join(", "), - supported_keys.join(", ") - ); - } + if !properties.is_empty() { + let supported_keys = ["strategy"]; + let unknown_keys = properties.keys().map(String::from).collect::>(); + anyhow::bail!( + "Unknown keys: {}. Supported keys are: {}", + unknown_keys.join(", "), + supported_keys.join(", ") + ); + } + + Ok(strategy) +} - let strategy = match strategy { - Some(Ok(strategy)) => { - if strategy.is_empty() { - anyhow::bail!("Empty strategy array, at least one client is required"); - } - strategy - } - Some(Err(e)) => return Err(e), - None => anyhow::bail!("Missing a strategy field"), - }; +impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for FallbackStrategy { + type Error = anyhow::Error; + fn try_from((client, ctx): (&ClientWalker, &RuntimeContext)) -> Result { + let properties = super::super::resolve_properties_walker(client, ctx)?; + let strategy = resolve_properties(properties, ctx)?; Ok(Self { name: client.item.elem.name.clone(), retry_policy: client.retry_policy().as_ref().map(String::from), diff --git a/engine/baml-runtime/src/internal/llm_client/strategy/mod.rs b/engine/baml-runtime/src/internal/llm_client/strategy/mod.rs index ce1fb30a4..9b147951d 100644 --- a/engine/baml-runtime/src/internal/llm_client/strategy/mod.rs +++ b/engine/baml-runtime/src/internal/llm_client/strategy/mod.rs @@ -6,7 +6,9 @@ pub mod roundrobin; use internal_baml_core::ir::ClientWalker; -use crate::{runtime_interface::InternalClientLookup, RuntimeContext}; +use crate::{ + client_registry::ClientProperty, runtime_interface::InternalClientLookup, RuntimeContext, +}; use self::{fallback::FallbackStrategy, roundrobin::RoundRobinStrategy}; @@ -22,6 +24,19 @@ pub enum LLMStrategyProvider { Fallback(FallbackStrategy), } +impl std::fmt::Display for LLMStrategyProvider { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + LLMStrategyProvider::RoundRobin(strategy) => { + write!(f, "RoundRobin({})", strategy.name) + } + LLMStrategyProvider::Fallback(strategy) => { + write!(f, "Fallback({})", strategy.name) + } + } + } +} + impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for LLMStrategyProvider { type Error = anyhow::Error; @@ -45,6 +60,29 @@ impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for LLMStrategyProvider { } } +impl TryFrom<(&ClientProperty, &RuntimeContext)> for LLMStrategyProvider { + type Error = anyhow::Error; + + fn try_from((client, ctx): (&ClientProperty, &RuntimeContext)) -> Result { + match client.provider.as_str() { + "baml-round-robin" | "round-robin" => RoundRobinStrategy::try_from((client, ctx)) + .map(Arc::new) + .map(LLMStrategyProvider::RoundRobin), + "baml-fallback" | "fallback" => { + FallbackStrategy::try_from((client, ctx)).map(LLMStrategyProvider::Fallback) + } + other => { + let options = ["round-robin", "fallback"]; + anyhow::bail!( + "Unsupported strategy provider: {}. Available ones are: {}", + other, + options.join(", ") + ) + } + } + } +} + impl WithRetryPolicy for LLMStrategyProvider { fn retry_policy_name(&self) -> Option<&str> { match self { diff --git a/engine/baml-runtime/src/internal/llm_client/strategy/roundrobin.rs b/engine/baml-runtime/src/internal/llm_client/strategy/roundrobin.rs index 639285baf..8f370a9c8 100644 --- a/engine/baml-runtime/src/internal/llm_client/strategy/roundrobin.rs +++ b/engine/baml-runtime/src/internal/llm_client/strategy/roundrobin.rs @@ -1,9 +1,13 @@ use anyhow::{Context, Result}; -use std::sync::{atomic::AtomicUsize, Arc}; +use std::{ + collections::HashMap, + sync::{atomic::AtomicUsize, Arc}, +}; use internal_baml_core::ir::ClientWalker; use crate::{ + client_registry::ClientProperty, internal::llm_client::orchestrator::{ ExecutionScope, IterOrchestrator, OrchestrationScope, OrchestrationState, OrchestratorNodeIterator, @@ -32,72 +36,91 @@ impl RoundRobinStrategy { } } -impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for RoundRobinStrategy { +impl TryFrom<(&ClientProperty, &RuntimeContext)> for RoundRobinStrategy { type Error = anyhow::Error; - fn try_from((client, ctx): (&ClientWalker, &RuntimeContext)) -> Result { - let properties = &client.item.elem.options; - - let mut unknown_keys = vec![]; - - let mut start = None; - let mut strategy = None; - for (key, value) in properties { - match key.as_str() { - "start" => { - let start_expr = ctx - .resolve_expression::(value) - .context("Invalid start index (not a number)"); - start = Some(start_expr); - } - "strategy" => { - let clients = ctx - .resolve_expression::>(value) - .context("Failed to resolve strategy expression into string[]"); - strategy = Some(clients); - } - other => unknown_keys.push(other), - }; - } + fn try_from( + (client, ctx): (&ClientProperty, &RuntimeContext), + ) -> std::result::Result { + let (strategy, start) = resolve_properties( + client + .options + .iter() + .map(|(k, v)| Ok((k.clone(), serde_json::json!(v)))) + .collect::>>()?, + ctx, + )?; + + Ok(RoundRobinStrategy { + name: client.name.clone(), + retry_policy: client.retry_policy.clone(), + clients: strategy, + current_index: AtomicUsize::new(start), + }) + } +} - if !unknown_keys.is_empty() { - let supported_keys = ["start", "strategy"]; - anyhow::bail!( - "Unknown keys: {}. Supported keys are: {}", - unknown_keys.join(", "), - supported_keys.join(", ") - ); +fn resolve_properties( + mut properties: HashMap, + _ctx: &RuntimeContext, +) -> Result<(Vec, usize)> { + let strategy = properties + .remove("strategy") + .map(|v| serde_json::from_value::>(v)) + .transpose() + .context("Failed to resolve strategy into string[]")?; + + let strategy = if let Some(strategy) = strategy { + if strategy.is_empty() { + anyhow::bail!("Empty strategy array, at least one client is required"); } + strategy + } else { + anyhow::bail!("Missing a strategy field"); + }; + + let start = properties + .remove("start") + .map(|v| serde_json::from_value::(v)) + .transpose() + .context("Invalid start index (not a number)")?; + + if !properties.is_empty() { + let supported_keys = ["strategy", "start"]; + let unknown_keys = properties.keys().map(String::from).collect::>(); + anyhow::bail!( + "Unknown keys: {}. Supported keys are: {}", + unknown_keys.join(", "), + supported_keys.join(", ") + ); + } - let strategy = match strategy { - Some(Ok(strategy)) => { - if strategy.is_empty() { - anyhow::bail!("Empty strategy array, at least one client is required"); - } - strategy + let start = match start { + Some(start) => start % strategy.len(), + None => { + #[cfg(not(target_arch = "wasm32"))] + { + fastrand::usize(..strategy.len()) } - Some(Err(e)) => return Err(e), - None => anyhow::bail!("Missing a strategy field"), - }; - - let start = match start { - Some(Ok(start)) => start % strategy.len(), - Some(Err(e)) => return Err(e), - None => { - #[cfg(not(target_arch = "wasm32"))] - { - fastrand::usize(..strategy.len()) - } - - // For VSCode, we don't want a random start point, - // as it can make rendering inconsistent - #[cfg(target_arch = "wasm32")] - { - 0 - } + + // For VSCode, we don't want a random start point, + // as it can make rendering inconsistent + #[cfg(target_arch = "wasm32")] + { + 0 } - }; + } + }; + + Ok((strategy, start)) +} +impl TryFrom<(&ClientWalker<'_>, &RuntimeContext)> for RoundRobinStrategy { + type Error = anyhow::Error; + + fn try_from((client, ctx): (&ClientWalker, &RuntimeContext)) -> Result { + let properties = super::super::resolve_properties_walker(client, ctx)?; + let (strategy, start) = resolve_properties(properties, ctx)?; Ok(Self { name: client.item.elem.name.clone(), retry_policy: client.retry_policy().as_ref().map(String::from), diff --git a/engine/baml-runtime/src/internal/prompt_renderer/mod.rs b/engine/baml-runtime/src/internal/prompt_renderer/mod.rs index 50d41e7e9..96ff49e2d 100644 --- a/engine/baml-runtime/src/internal/prompt_renderer/mod.rs +++ b/engine/baml-runtime/src/internal/prompt_renderer/mod.rs @@ -41,7 +41,10 @@ impl PromptRenderer { Ok(PromptRenderer { function_name: function.name().into(), - client_name: config.client.clone(), + client_name: match &ctx.client_overrides { + Some((Some(client), _)) => client.clone(), + _ => config.client.clone(), + }, output_defs: render_output_format(ir, ctx, &func_v2.output.elem)?, output_type: func_v2.output.elem.clone(), }) diff --git a/engine/baml-runtime/src/lib.rs b/engine/baml-runtime/src/lib.rs index a3e53cf2a..f8dbb1370 100644 --- a/engine/baml-runtime/src/lib.rs +++ b/engine/baml-runtime/src/lib.rs @@ -13,6 +13,7 @@ pub(crate) mod internal; #[cfg(not(target_arch = "wasm32"))] mod cli; +pub mod client_registry; mod macros; mod request; mod runtime; @@ -29,6 +30,7 @@ use anyhow::Result; use baml_types::BamlMap; use baml_types::BamlValue; +use client_registry::ClientRegistry; use indexmap::IndexMap; use internal_baml_core::configuration::GeneratorOutputType; use on_log_event::LogEventCallbackSync; @@ -137,25 +139,29 @@ impl BamlRuntime { where F: Fn(FunctionResult) -> (), { - let (span, rctx) = self - .tracer - .start_span(test_name, ctx, None, &Default::default()); - - let params = self.inner.get_test_params(function_name, test_name, &rctx); - - let response = match params { - Ok(params) => match self.stream_function(function_name.into(), ¶ms, ctx, None) { - Ok(mut stream) => { - let (response, span) = stream.run(on_event, ctx, None).await; - let response = response.map(|res| TestResponse { - function_response: res, - function_span: span, - }); - - response + let span = self.tracer.start_span(test_name, ctx, &Default::default()); + + let response = match ctx.create_ctx(None, None) { + Ok(rctx) => { + let params = self.inner.get_test_params(function_name, test_name, &rctx); + match params { + Ok(params) => { + match self.stream_function(function_name.into(), ¶ms, ctx, None, None) { + Ok(mut stream) => { + let (response, span) = stream.run(on_event, ctx, None, None).await; + let response = response.map(|res| TestResponse { + function_response: res, + function_span: span, + }); + + response + } + Err(e) => Err(e), + } + } + Err(e) => Err(e), } - Err(e) => Err(e), - }, + } Err(e) => Err(e), }; @@ -182,14 +188,19 @@ impl BamlRuntime { params: &BamlMap, ctx: &RuntimeContextManager, tb: Option<&TypeBuilder>, + cb: Option<&ClientRegistry>, ) -> (Result, Option) { log::trace!("Calling function: {}", function_name); - let (span, rctx) = self.tracer.start_span(&function_name, ctx, tb, ¶ms); + let span = self.tracer.start_span(&function_name, ctx, ¶ms); log::trace!("Span started"); - let response = self - .inner - .call_function_impl(function_name, params, rctx) - .await; + let response = match ctx.create_ctx(tb, cb) { + Ok(rctx) => { + self.inner + .call_function_impl(function_name, params, rctx) + .await + } + Err(e) => Err(e), + }; let mut target_id = None; if let Some(span) = span { @@ -213,12 +224,13 @@ impl BamlRuntime { params: &BamlMap, ctx: &RuntimeContextManager, tb: Option<&TypeBuilder>, + cb: Option<&ClientRegistry>, ) -> Result { self.inner.stream_function_impl( function_name, params, self.tracer.clone(), - ctx.create_ctx(tb), + ctx.create_ctx(tb, cb)?, ) } @@ -270,8 +282,8 @@ impl ExperimentalTracingInterface for BamlRuntime { function_name: &str, params: &BamlMap, ctx: &RuntimeContextManager, - ) -> (Option, RuntimeContext) { - self.tracer.start_span(function_name, ctx, None, params) + ) -> Option { + self.tracer.start_span(function_name, ctx, params) } #[cfg(not(target_arch = "wasm32"))] diff --git a/engine/baml-runtime/src/runtime/runtime_interface.rs b/engine/baml-runtime/src/runtime/runtime_interface.rs index f0994f8f0..b422e6832 100644 --- a/engine/baml-runtime/src/runtime/runtime_interface.rs +++ b/engine/baml-runtime/src/runtime/runtime_interface.rs @@ -36,6 +36,14 @@ impl<'a> InternalClientLookup<'a> for InternalBamlRuntime { client_name: &str, ctx: &RuntimeContext, ) -> Result> { + if let Some(client) = ctx + .client_overrides + .as_ref() + .and_then(|(_, c)| c.get(client_name)) + { + return Ok(client.clone()); + } + #[cfg(target_arch = "wasm32")] let mut clients = self.clients.lock().unwrap(); #[cfg(not(target_arch = "wasm32"))] diff --git a/engine/baml-runtime/src/runtime_interface.rs b/engine/baml-runtime/src/runtime_interface.rs index 59cb4572b..544c8df53 100644 --- a/engine/baml-runtime/src/runtime_interface.rs +++ b/engine/baml-runtime/src/runtime_interface.rs @@ -56,7 +56,7 @@ pub trait ExperimentalTracingInterface { function_name: &str, params: &BamlMap, ctx: &RuntimeContextManager, - ) -> (Option, RuntimeContext); + ) -> Option; #[cfg(target_arch = "wasm32")] #[allow(async_fn_in_trait)] diff --git a/engine/baml-runtime/src/tracing/mod.rs b/engine/baml-runtime/src/tracing/mod.rs index 85d5d4e5e..016c09b93 100644 --- a/engine/baml-runtime/src/tracing/mod.rs +++ b/engine/baml-runtime/src/tracing/mod.rs @@ -13,9 +13,9 @@ use std::sync::{Arc, Mutex}; use uuid::Uuid; use crate::{ - internal::llm_client::LLMResponse, tracing::api_wrapper::core_types::Role, - type_builder::TypeBuilder, FunctionResult, RuntimeContext, RuntimeContextManager, SpanCtx, - TestResponse, TraceStats, + client_registry::ClientRegistry, internal::llm_client::LLMResponse, + tracing::api_wrapper::core_types::Role, type_builder::TypeBuilder, FunctionResult, + RuntimeContext, RuntimeContextManager, SpanCtx, TestResponse, TraceStats, }; use self::api_wrapper::{ @@ -102,14 +102,13 @@ impl BamlTracer { &self, function_name: &str, ctx: &RuntimeContextManager, - tb: Option<&TypeBuilder>, params: &BamlMap, - ) -> (Option, RuntimeContext) { + ) -> Option { self.trace_stats.guard().start(); let span_id = ctx.enter(function_name); log::trace!("Entering span {:#?} in {:?}", span_id, function_name); if !self.enabled { - return (None, ctx.create_ctx(tb)); + return None; } let span = TracingSpan { span_id, @@ -117,7 +116,7 @@ impl BamlTracer { start_time: web_time::SystemTime::now(), }; - (Some(span), ctx.create_ctx(tb)) + Some(span) } #[cfg(target_arch = "wasm32")] diff --git a/engine/baml-runtime/src/types/context_manager.rs b/engine/baml-runtime/src/types/context_manager.rs index 93a1e7b95..a6aa5c5c0 100644 --- a/engine/baml-runtime/src/types/context_manager.rs +++ b/engine/baml-runtime/src/types/context_manager.rs @@ -3,16 +3,17 @@ use std::{ sync::{Arc, Mutex}, }; +use anyhow::{Context, Result}; use baml_types::BamlValue; use std::fmt; -use crate::{type_builder::TypeBuilder, RuntimeContext, SpanCtx}; +use crate::{client_registry::ClientRegistry, type_builder::TypeBuilder, RuntimeContext, SpanCtx}; -type Context = (uuid::Uuid, String, HashMap); +type BamlContext = (uuid::Uuid, String, HashMap); #[derive(Default, Clone)] pub struct RuntimeContextManager { - context: Arc>>, + context: Arc>>, env_vars: HashMap, global_tags: Arc>>, } @@ -94,7 +95,11 @@ impl RuntimeContextManager { Some((id, prev, tags)) } - pub fn create_ctx(&self, tb: Option<&TypeBuilder>) -> RuntimeContext { + pub fn create_ctx( + &self, + tb: Option<&TypeBuilder>, + cb: Option<&ClientRegistry>, + ) -> Result { let mut tags = self.global_tags.lock().unwrap().clone(); let ctx_tags = { self.context @@ -114,12 +119,25 @@ impl RuntimeContextManager { let (cls, enm) = tb.map(|tb| tb.to_overrides()).unwrap_or_default(); - RuntimeContext { + let mut ctx = RuntimeContext { env: self.env_vars.clone(), tags, + client_overrides: Default::default(), class_override: cls, enum_overrides: enm, - } + }; + + let client_overrides = match cb { + Some(cb) => Some( + cb.to_clients(&ctx) + .with_context(|| "Failed to create clients from client_registry")?, + ), + None => None, + }; + + ctx.client_overrides = client_overrides; + + Ok(ctx) } pub fn create_ctx_with_default>( @@ -135,6 +153,7 @@ impl RuntimeContextManager { RuntimeContext { env: env_vars.collect(), tags: ctx.last().map(|(.., x)| x).cloned().unwrap_or_default(), + client_overrides: Default::default(), class_override: Default::default(), enum_overrides: Default::default(), } diff --git a/engine/baml-runtime/src/types/runtime_context.rs b/engine/baml-runtime/src/types/runtime_context.rs index 16a35ea26..4d704f6bb 100644 --- a/engine/baml-runtime/src/types/runtime_context.rs +++ b/engine/baml-runtime/src/types/runtime_context.rs @@ -4,7 +4,9 @@ use indexmap::IndexMap; use internal_baml_core::ir::{repr::Expression, FieldType}; use serde; use serde_json; -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; + +use crate::internal::llm_client::llm_provider::LLMProvider; #[derive(Debug)] pub struct SpanCtx { @@ -36,6 +38,7 @@ pub struct RuntimeClassOverride { pub struct RuntimeContext { pub env: HashMap, pub tags: HashMap, + pub client_overrides: Option<(Option, HashMap>)>, pub class_override: IndexMap, pub enum_overrides: IndexMap, } diff --git a/engine/baml-runtime/src/types/stream.rs b/engine/baml-runtime/src/types/stream.rs index ae208297a..c7879fef8 100644 --- a/engine/baml-runtime/src/types/stream.rs +++ b/engine/baml-runtime/src/types/stream.rs @@ -2,9 +2,10 @@ use anyhow::Result; use internal_baml_core::ir::repr::IntermediateRepr; -use std::sync::Arc; +use std::{rc, sync::Arc}; use crate::{ + client_registry::ClientRegistry, internal::{ llm_client::orchestrator::{orchestrate_stream, OrchestratorNodeIterator}, prompt_renderer::PromptRenderer, @@ -14,7 +15,6 @@ use crate::{ FunctionResult, RuntimeContextManager, }; - /// Wrapper that holds a stream of responses from a BAML function call. /// /// Needs to hold a reference to the IR so that it can parse each response from the LLM. @@ -58,6 +58,7 @@ impl FunctionResultStream { on_event: Option, ctx: &RuntimeContextManager, tb: Option<&TypeBuilder>, + cb: Option<&ClientRegistry>, ) -> (Result, Option) where F: Fn(FunctionResult) -> (), @@ -68,23 +69,29 @@ impl FunctionResultStream { let mut local_params = crate::BamlMap::new(); std::mem::swap(&mut local_params, &mut self.params); - let (span, rctx) = self + let span = self .tracer - .start_span(&self.function_name, ctx, tb, &local_params); - - let (history, _) = orchestrate_stream( - local_orchestrator, - self.ir.as_ref(), - &rctx, - &self.renderer, - &baml_types::BamlValue::Map(local_params), - |content| self.renderer.parse(content, true), - |content| self.renderer.parse(content, false), - on_event, - ) - .await; - - let res = FunctionResult::new_chain(history); + .start_span(&self.function_name, ctx, &local_params); + + let rctx = ctx.create_ctx(tb, cb); + let res = match rctx { + Ok(rctx) => { + let (history, _) = orchestrate_stream( + local_orchestrator, + self.ir.as_ref(), + &rctx, + &self.renderer, + &baml_types::BamlValue::Map(local_params), + |content| self.renderer.parse(content, true), + |content| self.renderer.parse(content, false), + on_event, + ) + .await; + + FunctionResult::new_chain(history) + } + Err(e) => Err(e), + }; let mut target_id = None; if let Some(span) = span { diff --git a/engine/baml-runtime/tests/test_runtime.rs b/engine/baml-runtime/tests/test_runtime.rs index c1c2204b6..f20b70f50 100644 --- a/engine/baml-runtime/tests/test_runtime.rs +++ b/engine/baml-runtime/tests/test_runtime.rs @@ -107,7 +107,7 @@ mod internal_tests { let ctx = runtime.create_ctx_manager(BamlValue::String("test".to_string())); let (res, _) = runtime - .call_function("GetOrderInfo".to_string(), ¶ms, &ctx, None) + .call_function("GetOrderInfo".to_string(), ¶ms, &ctx, None, None) .await; assert!(res.is_ok(), "Result: {:#?}", res.err()); diff --git a/engine/language-client-codegen/src/python/templates/client.py.j2 b/engine/language-client-codegen/src/python/templates/client.py.j2 index 1ad55f848..e3a8a516e 100644 --- a/engine/language-client-codegen/src/python/templates/client.py.j2 +++ b/engine/language-client-codegen/src/python/templates/client.py.j2 @@ -24,6 +24,7 @@ def coerce(cls: Type[BaseModel], parsed: Any) -> Any: # Define the TypedDict with optional parameters having default values class BamlCallOptions(TypedDict, total=False): tb: NotRequired[TypeBuilder] + client_registry: NotRequired[baml_py.baml_py.ClientRegistry] class BamlClient: __runtime: baml_py.BamlRuntime @@ -52,6 +53,7 @@ class BamlClient: tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "{{fn.name}}", @@ -62,6 +64,7 @@ class BamlClient: }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("{{ fn.name }}ReturnType", inner=({{ fn.return_type }}, ...)) return coerce(mdl, raw.parsed()) @@ -88,6 +91,7 @@ class BamlStreamClient: tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "{{fn.name}}", @@ -99,6 +103,7 @@ class BamlStreamClient: None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("{{ fn.name }}ReturnType", inner=({{ fn.return_type }}, ...)) @@ -109,6 +114,5 @@ class BamlStreamClient: lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) {% endfor %} \ No newline at end of file diff --git a/engine/language-client-codegen/src/typescript/templates/client.ts.j2 b/engine/language-client-codegen/src/typescript/templates/client.ts.j2 index 4157808ca..b6078c56f 100644 --- a/engine/language-client-codegen/src/typescript/templates/client.ts.j2 +++ b/engine/language-client-codegen/src/typescript/templates/client.ts.j2 @@ -1,4 +1,4 @@ -import { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image } from "@boundaryml/baml" +import { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image, ClientBuilder } from "@boundaryml/baml" import { {%- for t in types %}{{ t }}{% if !loop.last %}, {% endif %}{% endfor -%} } from "./types" @@ -30,7 +30,7 @@ export class BamlClient { {% for (name, optional, type) in fn.args -%} {{name}}{% if optional %}?{% endif %}: {{type}}, {%- endfor %} - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise<{{fn.return_type}}> { const raw = await this.runtime.callFunction( "{{fn.name}}", @@ -41,6 +41,7 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as {{fn.return_type}} } @@ -55,7 +56,7 @@ class BamlStreamClient { {% for (name, optional, type) in fn.args -%} {{name}}{% if optional %}?{% endif %}: {{type}}, {%- endfor %} - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, {{ fn.return_type }}> { const raw = this.runtime.streamFunction( "{{fn.name}}", @@ -67,6 +68,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, {{ fn.return_type }}>( raw, diff --git a/engine/language_client_python/python_src/baml_py/__init__.py b/engine/language_client_python/python_src/baml_py/__init__.py index 9728149a5..6e7a3e17e 100644 --- a/engine/language_client_python/python_src/baml_py/__init__.py +++ b/engine/language_client_python/python_src/baml_py/__init__.py @@ -8,12 +8,14 @@ BamlImagePy as Image, BamlAudioPy as Audio, invoke_runtime_cli, + ClientRegistry, ) from .stream import BamlStream from .ctx_manager import CtxManager as BamlCtxManager __all__ = [ "BamlRuntime", + "ClientRegistry", "BamlStream", "BamlCtxManager", "FunctionResult", diff --git a/engine/language_client_python/python_src/baml_py/baml_py.pyi b/engine/language_client_python/python_src/baml_py/baml_py.pyi index 3aa1f5c5a..693c241cd 100644 --- a/engine/language_client_python/python_src/baml_py/baml_py.pyi +++ b/engine/language_client_python/python_src/baml_py/baml_py.pyi @@ -64,6 +64,7 @@ class BamlRuntime: args: Dict[str, Any], ctx: RuntimeContextManager, tb: Optional[TypeBuilder], + cr: Optional[ClientRegistry], ) -> FunctionResult: ... @staticmethod def from_files( @@ -76,6 +77,7 @@ class BamlRuntime: on_event: Optional[Callable[[FunctionResult], None]], ctx: RuntimeContextManager, tb: Optional[TypeBuilder], + cr: Optional[ClientRegistry], ) -> FunctionResultStream: ... def create_context_manager(self) -> RuntimeContextManager: ... def flush(self) -> None: ... @@ -145,6 +147,17 @@ class TypeBuilder: def null(self) -> FieldType: ... def optional(self, inner_type: FieldType) -> FieldType: ... +class ClientRegistry: + def __init__(self) -> None: ... + def add_llm_client( + self, + name: str, + provider: str, + options: Dict[str, Any], + retry_policy: Optional[str] = None, + ) -> None: ... + def set_primary(self, name: str) -> None: ... + class FieldType: def list(self) -> FieldType: ... def optional(self) -> FieldType: ... diff --git a/engine/language_client_python/python_src/baml_py/stream.py b/engine/language_client_python/python_src/baml_py/stream.py index b3abfcf13..91da360cd 100644 --- a/engine/language_client_python/python_src/baml_py/stream.py +++ b/engine/language_client_python/python_src/baml_py/stream.py @@ -3,7 +3,6 @@ FunctionResult, FunctionResultStream, RuntimeContextManager, - TypeBuilder, ) from typing import Callable, Generic, Optional, TypeVar import threading @@ -23,7 +22,6 @@ class BamlStream(Generic[PartialOutputType, FinalOutputType]): __ctx_manager: RuntimeContextManager __task: Optional[threading.Thread] __event_queue: queue.Queue[Optional[FunctionResult]] - __tb: Optional[TypeBuilder] __future: concurrent.futures.Future[FunctionResult] def __init__( @@ -32,7 +30,6 @@ def __init__( partial_coerce: Callable[[FunctionResult], PartialOutputType], final_coerce: Callable[[FunctionResult], FinalOutputType], ctx_manager: RuntimeContextManager, - tb: Optional[TypeBuilder], ): self.__ffi_stream = ffi_stream.on_event(self.__enqueue) self.__partial_coerce = partial_coerce @@ -40,7 +37,6 @@ def __init__( self.__ctx_manager = ctx_manager self.__task = None self.__event_queue = queue.Queue() - self.__tb = tb self.__future = concurrent.futures.Future() # Initialize the future here def __enqueue(self, data: FunctionResult) -> None: diff --git a/engine/language_client_python/src/lib.rs b/engine/language_client_python/src/lib.rs index 4f280f559..ab569961d 100644 --- a/engine/language_client_python/src/lib.rs +++ b/engine/language_client_python/src/lib.rs @@ -48,6 +48,7 @@ fn baml_py(_: Python<'_>, m: Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; diff --git a/engine/language_client_python/src/runtime.rs b/engine/language_client_python/src/runtime.rs index 78c78e7e2..d7e1bd345 100644 --- a/engine/language_client_python/src/runtime.rs +++ b/engine/language_client_python/src/runtime.rs @@ -6,6 +6,7 @@ use crate::BamlError; use crate::types::function_result_stream::FunctionResultStream; use crate::types::runtime_ctx_manager::RuntimeContextManager; use crate::types::type_builder::TypeBuilder; +use crate::types::ClientRegistry; use baml_runtime::runtime_interface::ExperimentalTracingInterface; use baml_runtime::BamlRuntime as CoreBamlRuntime; use pyo3::prelude::{pymethods, PyResult}; @@ -99,7 +100,7 @@ impl BamlRuntime { .into() } - #[pyo3(signature = (function_name, args, ctx, tb))] + #[pyo3(signature = (function_name, args, ctx, tb, cb))] fn call_function( &self, py: Python<'_>, @@ -107,6 +108,7 @@ impl BamlRuntime { args: PyObject, ctx: &RuntimeContextManager, tb: Option<&TypeBuilder>, + cb: Option<&ClientRegistry>, ) -> PyResult { let Some(args) = parse_py_type(args.into_bound(py).to_object(py), false)? else { return Err(BamlError::new_err( @@ -121,11 +123,12 @@ impl BamlRuntime { let baml_runtime = self.inner.clone(); let ctx_mng = ctx.inner.clone(); let tb = tb.map(|tb| tb.inner.clone()); + let cb = cb.map(|cb| cb.inner.clone()); pyo3_asyncio::tokio::future_into_py(py, async move { let ctx_mng = ctx_mng; let result = baml_runtime - .call_function(function_name, &args_map, &ctx_mng, tb.as_ref()) + .call_function(function_name, &args_map, &ctx_mng, tb.as_ref(), cb.as_ref()) .await; result @@ -136,7 +139,7 @@ impl BamlRuntime { .map(|f| f.into()) } - #[pyo3(signature = (function_name, args, on_event, ctx, tb))] + #[pyo3(signature = (function_name, args, on_event, ctx, tb, cb))] fn stream_function( &self, py: Python<'_>, @@ -145,6 +148,7 @@ impl BamlRuntime { on_event: Option, ctx: &RuntimeContextManager, tb: Option<&TypeBuilder>, + cb: Option<&ClientRegistry>, ) -> PyResult { let Some(args) = parse_py_type(args.into_bound(py).to_object(py), false)? else { return Err(BamlError::new_err( @@ -164,6 +168,7 @@ impl BamlRuntime { args_map, &ctx, tb.map(|tb| tb.inner.clone()).as_ref(), + cb.map(|cb| cb.inner.clone()).as_ref(), ) .map_err(BamlError::from_anyhow)?; @@ -171,6 +176,7 @@ impl BamlRuntime { stream, on_event, tb.map(|tb| tb.inner.clone()), + cb.map(|cb| cb.inner.clone()), )) } diff --git a/engine/language_client_python/src/types/client_registry.rs b/engine/language_client_python/src/types/client_registry.rs new file mode 100644 index 000000000..789835abd --- /dev/null +++ b/engine/language_client_python/src/types/client_registry.rs @@ -0,0 +1,56 @@ +use std::collections::HashMap; + +use baml_runtime::client_registry; +use baml_types::BamlValue; +use pyo3::prelude::{pymethods, PyResult}; +use pyo3::{PyObject, Python, ToPyObject}; + +use crate::parse_py_type::parse_py_type; +use crate::BamlError; + +crate::lang_wrapper!(ClientRegistry, client_registry::ClientRegistry); + +#[pymethods] +impl ClientRegistry { + #[new] + pub fn new() -> Self { + Self { + inner: client_registry::ClientRegistry::new(), + } + } + + #[pyo3(signature = (name, provider, options, retry_policy = None))] + pub fn add_llm_client( + &mut self, + py: Python<'_>, + name: String, + provider: String, + options: PyObject, + retry_policy: Option, + ) -> PyResult<()> { + let Some(args) = parse_py_type(options.into_bound(py).to_object(py), false)? else { + return Err(BamlError::new_err( + "Failed to parse args, perhaps you used a non-serializable type?", + )); + }; + let Some(args_map) = args.as_map_owned() else { + return Err(BamlError::new_err( + "Failed to parse args, perhaps you used a non-serializable type?", + )); + }; + + let client_property = baml_runtime::client_registry::ClientProperty { + name, + provider, + retry_policy, + options: args_map, + }; + + self.inner.add_client(client_property); + Ok(()) + } + + pub fn set_primary(&mut self, primary: String) { + self.inner.set_primary(primary); + } +} diff --git a/engine/language_client_python/src/types/function_result_stream.rs b/engine/language_client_python/src/types/function_result_stream.rs index cb868bc78..e90048758 100644 --- a/engine/language_client_python/src/types/function_result_stream.rs +++ b/engine/language_client_python/src/types/function_result_stream.rs @@ -10,7 +10,8 @@ crate::lang_wrapper!( FunctionResultStream, baml_runtime::FunctionResultStream, thread_safe, on_event: Option, - tb: Option + tb: Option, + cb: Option ); impl FunctionResultStream { @@ -18,11 +19,13 @@ impl FunctionResultStream { inner: baml_runtime::FunctionResultStream, event: Option, tb: Option, + cb: Option, ) -> Self { Self { inner: std::sync::Arc::new(tokio::sync::Mutex::new(inner)), on_event: event, tb, + cb, } } } @@ -62,10 +65,13 @@ impl FunctionResultStream { let ctx_mng = ctx.inner.clone(); let tb = self.tb.as_ref().map(|tb| tb.clone()); + let cb = self.cb.as_ref().map(|cb| cb.clone()); pyo3_asyncio::tokio::future_into_py(py, async move { let ctx_mng = ctx_mng; let mut locked = inner.lock().await; - let (res, _) = locked.run(on_event, &ctx_mng, tb.as_ref()).await; + let (res, _) = locked + .run(on_event, &ctx_mng, tb.as_ref(), cb.as_ref()) + .await; res.map(FunctionResult::from) .map_err(BamlError::from_anyhow) }) diff --git a/engine/language_client_python/src/types/mod.rs b/engine/language_client_python/src/types/mod.rs index ab84069c3..024c83f96 100644 --- a/engine/language_client_python/src/types/mod.rs +++ b/engine/language_client_python/src/types/mod.rs @@ -1,6 +1,8 @@ mod lang_wrapper; +pub use client_registry::ClientRegistry; pub(crate) mod audio; +pub(crate) mod client_registry; pub(crate) mod function_result_stream; pub(crate) mod function_results; pub(crate) mod image; diff --git a/engine/language_client_python/src/types/span.rs b/engine/language_client_python/src/types/span.rs index b11478ee5..17cd70c3d 100644 --- a/engine/language_client_python/src/types/span.rs +++ b/engine/language_client_python/src/types/span.rs @@ -31,7 +31,7 @@ impl BamlSpan { return Err(BamlError::new_err("Failed to parse args")); }; - let (span, _) = runtime + let span = runtime .inner .start_span(function_name, &args_map, &ctx.inner); diff --git a/engine/language_client_ruby/ext/ruby_ffi/src/function_result_stream.rs b/engine/language_client_ruby/ext/ruby_ffi/src/function_result_stream.rs index 0eb6329a1..89e4b06a9 100644 --- a/engine/language_client_ruby/ext/ruby_ffi/src/function_result_stream.rs +++ b/engine/language_client_ruby/ext/ruby_ffi/src/function_result_stream.rs @@ -41,10 +41,12 @@ impl FunctionResultStream { None }; - match rb_self - .t - .block_on(rb_self.inner.borrow_mut().run(on_event, &ctx.inner, None)) - { + match rb_self.t.block_on( + rb_self + .inner + .borrow_mut() + .run(on_event, &ctx.inner, None, None), + ) { (Ok(res), _) => Ok(FunctionResult::new(res)), (Err(e), _) => Err(Error::new( ruby.exception_runtime_error(), diff --git a/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs b/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs index f89c9d64b..f967e253e 100644 --- a/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs +++ b/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs @@ -134,6 +134,7 @@ impl BamlRuntimeFfi { &args, &ctx.inner, None, + None, )) { (Ok(res), _) => Ok(FunctionResult::new(res)), (Err(e), _) => Err(Error::new( @@ -167,20 +168,22 @@ impl BamlRuntimeFfi { log::debug!("Streaming {function_name} with:\nargs: {args:#?}\nctx ???"); - let retval = - match rb_self - .inner - .stream_function(function_name.clone(), &args, &ctx.inner, None) - { - Ok(res) => Ok(FunctionResultStream::new(res, rb_self.t.clone())), - Err(e) => Err(Error::new( - ruby.exception_runtime_error(), - format!( - "{:?}", - e.context(format!("error while calling {function_name}")) - ), - )), - }; + let retval = match rb_self.inner.stream_function( + function_name.clone(), + &args, + &ctx.inner, + None, + None, + ) { + Ok(res) => Ok(FunctionResultStream::new(res, rb_self.t.clone())), + Err(e) => Err(Error::new( + ruby.exception_runtime_error(), + format!( + "{:?}", + e.context(format!("error while calling {function_name}")) + ), + )), + }; retval } diff --git a/engine/language_client_typescript/index.d.ts b/engine/language_client_typescript/index.d.ts index d7fb1b238..a983407a8 100644 --- a/engine/language_client_typescript/index.d.ts +++ b/engine/language_client_typescript/index.d.ts @@ -1,4 +1,4 @@ -export { BamlRuntime, FunctionResult, FunctionResultStream, BamlImage as Image, BamlAudio as Audio, invoke_runtime_cli, } from './native'; +export { BamlRuntime, FunctionResult, FunctionResultStream, BamlImage as Image, ClientBuilder, BamlAudio as Audio, invoke_runtime_cli, ClientRegistry, } from './native'; export { BamlStream } from './stream'; export { BamlCtxManager } from './async_context_vars'; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/engine/language_client_typescript/index.d.ts.map b/engine/language_client_typescript/index.d.ts.map index 3640d5f40..e3588fcb7 100644 --- a/engine/language_client_typescript/index.d.ts.map +++ b/engine/language_client_typescript/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["typescript_src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,SAAS,IAAI,KAAK,EAClB,SAAS,IAAI,KAAK,EAClB,kBAAkB,GACnB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["typescript_src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,SAAS,IAAI,KAAK,EAClB,aAAa,EACb,SAAS,IAAI,KAAK,EAClB,kBAAkB,EAClB,cAAc,GACf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"} \ No newline at end of file diff --git a/engine/language_client_typescript/index.js b/engine/language_client_typescript/index.js index 1aac1f0cf..4482b2a90 100644 --- a/engine/language_client_typescript/index.js +++ b/engine/language_client_typescript/index.js @@ -1,13 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.BamlCtxManager = exports.BamlStream = exports.invoke_runtime_cli = exports.Audio = exports.Image = exports.FunctionResultStream = exports.FunctionResult = exports.BamlRuntime = void 0; +exports.BamlCtxManager = exports.BamlStream = exports.ClientRegistry = exports.invoke_runtime_cli = exports.Audio = exports.ClientBuilder = exports.Image = exports.FunctionResultStream = exports.FunctionResult = exports.BamlRuntime = void 0; var native_1 = require("./native"); Object.defineProperty(exports, "BamlRuntime", { enumerable: true, get: function () { return native_1.BamlRuntime; } }); Object.defineProperty(exports, "FunctionResult", { enumerable: true, get: function () { return native_1.FunctionResult; } }); Object.defineProperty(exports, "FunctionResultStream", { enumerable: true, get: function () { return native_1.FunctionResultStream; } }); Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return native_1.BamlImage; } }); +Object.defineProperty(exports, "ClientBuilder", { enumerable: true, get: function () { return native_1.ClientBuilder; } }); Object.defineProperty(exports, "Audio", { enumerable: true, get: function () { return native_1.BamlAudio; } }); Object.defineProperty(exports, "invoke_runtime_cli", { enumerable: true, get: function () { return native_1.invoke_runtime_cli; } }); +Object.defineProperty(exports, "ClientRegistry", { enumerable: true, get: function () { return native_1.ClientRegistry; } }); var stream_1 = require("./stream"); Object.defineProperty(exports, "BamlStream", { enumerable: true, get: function () { return stream_1.BamlStream; } }); var async_context_vars_1 = require("./async_context_vars"); diff --git a/engine/language_client_typescript/native.d.ts b/engine/language_client_typescript/native.d.ts index eb8b4ba74..45e873081 100644 --- a/engine/language_client_typescript/native.d.ts +++ b/engine/language_client_typescript/native.d.ts @@ -22,8 +22,8 @@ export class BamlRuntime { static fromDirectory(directory: string, envVars: Record): BamlRuntime static fromFiles(rootPath: string, files: Record, envVars: Record): BamlRuntime createContextManager(): RuntimeContextManager - callFunction(functionName: string, args: { [string]: any }, ctx: RuntimeContextManager, tb?: TypeBuilder | undefined | null): Promise - streamFunction(functionName: string, args: { [string]: any }, cb: (err: any, param: FunctionResult) => void, ctx: RuntimeContextManager, tb?: TypeBuilder | undefined | null): FunctionResultStream + callFunction(functionName: string, args: { [string]: any }, ctx: RuntimeContextManager, tb?: TypeBuilder | undefined | null, cb?: ClientRegistry | undefined | null): Promise + streamFunction(functionName: string, args: { [string]: any }, cb: (err: any, param: FunctionResult) => void, ctx: RuntimeContextManager, tb?: TypeBuilder | undefined | null, clientRegistry?: ClientRegistry | undefined | null): FunctionResultStream setLogEventCallback(func: (err: any, param: BamlLogEvent) => void): void flush(): void drainStats(): TraceStats @@ -45,6 +45,12 @@ export class ClassPropertyBuilder { description(description?: string | undefined | null): ClassPropertyBuilder } +export class ClientRegistry { + constructor() + addLlmClient(name: string, provider: string, options: { [string]: any }, retryPolicy?: string | undefined | null): void + setPrimary(primary: string): void +} + export class EnumBuilder { value(name: string): EnumValueBuilder alias(alias?: string | undefined | null): EnumBuilder diff --git a/engine/language_client_typescript/native.js b/engine/language_client_typescript/native.js index ea0bd1193..44f680a98 100644 --- a/engine/language_client_typescript/native.js +++ b/engine/language_client_typescript/native.js @@ -367,6 +367,7 @@ module.exports.BamlRuntime = nativeBinding.BamlRuntime module.exports.BamlSpan = nativeBinding.BamlSpan module.exports.ClassBuilder = nativeBinding.ClassBuilder module.exports.ClassPropertyBuilder = nativeBinding.ClassPropertyBuilder +module.exports.ClientRegistry = nativeBinding.ClientRegistry module.exports.EnumBuilder = nativeBinding.EnumBuilder module.exports.EnumValueBuilder = nativeBinding.EnumValueBuilder module.exports.FieldType = nativeBinding.FieldType diff --git a/engine/language_client_typescript/src/runtime.rs b/engine/language_client_typescript/src/runtime.rs index 79804bdb6..96334c1a0 100644 --- a/engine/language_client_typescript/src/runtime.rs +++ b/engine/language_client_typescript/src/runtime.rs @@ -1,4 +1,5 @@ use crate::parse_ts_types; +use crate::types::client_registry::ClientRegistry; use crate::types::function_result_stream::FunctionResultStream; use crate::types::function_results::FunctionResult; use crate::types::runtime_ctx_manager::RuntimeContextManager; @@ -83,6 +84,7 @@ impl BamlRuntime { #[napi(ts_arg_type = "{ [string]: any }")] args: JsObject, ctx: &RuntimeContextManager, tb: Option<&TypeBuilder>, + cb: Option<&ClientRegistry>, ) -> napi::Result { let args = parse_ts_types::js_object_to_baml_value(env, args)?; @@ -100,10 +102,11 @@ impl BamlRuntime { let baml_runtime = self.inner.clone(); let ctx_mng = ctx.inner.clone(); let tb = tb.map(|tb| tb.inner.clone()); + let cb = cb.map(|cb| cb.inner.clone()); let fut = async move { let result = baml_runtime - .call_function(function_name, &args_map, &ctx_mng, tb.as_ref()) + .call_function(function_name, &args_map, &ctx_mng, tb.as_ref(), cb.as_ref()) .await; result @@ -124,6 +127,7 @@ impl BamlRuntime { #[napi(ts_arg_type = "(err: any, param: FunctionResult) => void")] cb: Option, ctx: &RuntimeContextManager, tb: Option<&TypeBuilder>, + client_registry: Option<&ClientRegistry>, ) -> napi::Result { let args: BamlValue = parse_ts_types::js_object_to_baml_value(env, args)?; if !args.is_map() { @@ -139,9 +143,16 @@ impl BamlRuntime { let ctx = ctx.inner.clone(); let tb = tb.map(|tb| tb.inner.clone()); + let client_registry = client_registry.map(|cb| cb.inner.clone()); let stream = self .inner - .stream_function(function_name, &args_map, &ctx, tb.as_ref()) + .stream_function( + function_name, + &args_map, + &ctx, + tb.as_ref(), + client_registry.as_ref(), + ) .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e.to_string()))?; let cb = match cb { @@ -149,7 +160,7 @@ impl BamlRuntime { None => None, }; - Ok(FunctionResultStream::new(stream, cb, tb)) + Ok(FunctionResultStream::new(stream, cb, tb, client_registry)) } #[napi] diff --git a/engine/language_client_typescript/src/types/client_registry.rs b/engine/language_client_typescript/src/types/client_registry.rs new file mode 100644 index 000000000..f285185e0 --- /dev/null +++ b/engine/language_client_typescript/src/types/client_registry.rs @@ -0,0 +1,58 @@ +use std::borrow::BorrowMut; + +use baml_runtime::client_registry; +use baml_types::BamlValue; +use napi::Env; +use napi::JsObject; +use napi_derive::napi; + +use crate::parse_ts_types; + +crate::lang_wrapper!(ClientRegistry, client_registry::ClientRegistry); + +#[napi] +impl ClientRegistry { + #[napi(constructor)] + pub fn new() -> Self { + Self { + inner: client_registry::ClientRegistry::new().into(), + } + } + + #[napi] + pub fn add_llm_client( + &mut self, + env: Env, + name: String, + provider: String, + #[napi(ts_arg_type = "{ [string]: any }")] options: JsObject, + retry_policy: Option, + ) -> napi::Result<()> { + let args = parse_ts_types::js_object_to_baml_value(env, options)?; + if !args.is_map() { + return Err(napi::Error::new( + napi::Status::GenericFailure, + format!( + "Invalid options: Expected a map of arguments, got: {}", + args.r#type() + ), + )); + } + let args_map = args.as_map_owned().unwrap(); + + let client_property = baml_runtime::client_registry::ClientProperty { + name, + provider, + retry_policy, + options: args_map, + }; + + self.inner.add_client(client_property); + Ok(()) + } + + #[napi] + pub fn set_primary(&mut self, primary: String) { + self.inner.set_primary(primary); + } +} diff --git a/engine/language_client_typescript/src/types/function_result_stream.rs b/engine/language_client_typescript/src/types/function_result_stream.rs index 2fdf7fa29..4bade2dae 100644 --- a/engine/language_client_typescript/src/types/function_result_stream.rs +++ b/engine/language_client_typescript/src/types/function_result_stream.rs @@ -13,8 +13,9 @@ crate::lang_wrapper!( custom_finalize, no_from, thread_safe, - cb: Option>, - tb: Option + callback: Option>, + tb: Option, + cb: Option ); impl FunctionResultStream { @@ -22,11 +23,13 @@ impl FunctionResultStream { inner: baml_runtime::FunctionResultStream, event: Option>, tb: Option, + cb: Option, ) -> Self { Self { inner: std::sync::Arc::new(tokio::sync::Mutex::new(inner)), - cb: event, + callback: event, tb, + cb, } } } @@ -40,11 +43,11 @@ impl FunctionResultStream { #[napi(ts_arg_type = "(err: any, param: FunctionResult) => void")] func: JsFunction, ) -> napi::Result { let cb = env.create_reference(func)?; - let prev = self.cb.take(); + let prev = self.callback.take(); if let Some(mut old_cb) = prev { old_cb.unref(env)?; } - self.cb = Some(cb); + self.callback = Some(cb); env.get_undefined() } @@ -52,7 +55,7 @@ impl FunctionResultStream { pub fn done(&self, env: Env, rctx: &RuntimeContextManager) -> napi::Result { let inner = self.inner.clone(); - let on_event = match &self.cb { + let on_event = match &self.callback { Some(cb) => { let cb = env.get_reference_value::(cb)?; let tsfn = env.create_threadsafe_function( @@ -75,17 +78,18 @@ impl FunctionResultStream { let ctx_mng = rctx.inner.clone(); let tb = self.tb.as_ref().map(|tb| tb.clone()); + let cb = self.cb.as_ref().map(|cb| cb.clone()); let fut = async move { let ctx_mng = ctx_mng; let res = inner .lock() .await - .run(on_event, &ctx_mng, tb.as_ref()) + .run(on_event, &ctx_mng, tb.as_ref(), cb.as_ref()) .await; res.0 .map(FunctionResult::from) - .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e.to_string())) + .map_err(|e| napi::Error::new(napi::Status::GenericFailure, format!("{:?}", e))) }; env.execute_tokio_future(fut, |&mut _, data| Ok(data)) @@ -94,7 +98,7 @@ impl FunctionResultStream { impl ObjectFinalize for FunctionResultStream { fn finalize(mut self, env: Env) -> napi::Result<()> { - if let Some(mut cb) = self.cb.take() { + if let Some(mut cb) = self.callback.take() { cb.unref(env)?; } Ok(()) diff --git a/engine/language_client_typescript/src/types/function_results.rs b/engine/language_client_typescript/src/types/function_results.rs index 4b993b974..c6596b173 100644 --- a/engine/language_client_typescript/src/types/function_results.rs +++ b/engine/language_client_typescript/src/types/function_results.rs @@ -14,7 +14,7 @@ impl FunctionResult { let parsed = self .inner .parsed_content() - .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e.to_string()))?; + .map_err(|e| napi::Error::new(napi::Status::GenericFailure, format!("{:?}", e)))?; Ok(serde_json::json!(BamlValue::from(parsed))) } diff --git a/engine/language_client_typescript/src/types/mod.rs b/engine/language_client_typescript/src/types/mod.rs index b5edf3562..553f81de6 100644 --- a/engine/language_client_typescript/src/types/mod.rs +++ b/engine/language_client_typescript/src/types/mod.rs @@ -1,6 +1,7 @@ mod lang_wrappers; pub mod audio; +pub(crate) mod client_registry; pub(crate) mod function_result_stream; pub(crate) mod function_results; pub mod image; diff --git a/engine/language_client_typescript/src/types/span.rs b/engine/language_client_typescript/src/types/span.rs index 1fa5ceafa..10397c14e 100644 --- a/engine/language_client_typescript/src/types/span.rs +++ b/engine/language_client_typescript/src/types/span.rs @@ -21,7 +21,7 @@ impl BamlSpan { ctx: &RuntimeContextManager, ) -> napi::Result { let args: BamlValue = serde_json::from_value(args) - .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e.to_string()))?; + .map_err(|e| napi::Error::new(napi::Status::GenericFailure, format!("{:?}", e)))?; let Some(args_map) = args.as_map() else { return Err(napi::Error::new( napi::Status::GenericFailure, @@ -29,7 +29,7 @@ impl BamlSpan { )); }; - let (span, _) = runtime + let span = runtime .inner .start_span(&function_name, &args_map, &ctx.inner); log::trace!("Starting span: {:#?} for {:?}\n", span, function_name); @@ -48,7 +48,7 @@ impl BamlSpan { ) -> napi::Result { log::trace!("Finishing span: {:?}", self.inner); let result: BamlValue = serde_json::from_value(result) - .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e.to_string()))?; + .map_err(|e| napi::Error::new(napi::Status::GenericFailure, format!("{:?}", e)))?; // log::info!("Finishing span: {:#?}\n", self.inner.lock().await); let span = self @@ -60,6 +60,6 @@ impl BamlSpan { .finish_span(span, Some(result), &ctx.inner) .map(|u| u.map(|id| id.to_string())) .map(|u| serde_json::json!(u)) - .map_err(|e| napi::Error::new(napi::Status::GenericFailure, e.to_string())) + .map_err(|e| napi::Error::new(napi::Status::GenericFailure, format!("{:?}", e))) } } diff --git a/engine/language_client_typescript/typescript_src/index.ts b/engine/language_client_typescript/typescript_src/index.ts index 6e19e66b6..473caedf6 100644 --- a/engine/language_client_typescript/typescript_src/index.ts +++ b/engine/language_client_typescript/typescript_src/index.ts @@ -3,8 +3,10 @@ export { FunctionResult, FunctionResultStream, BamlImage as Image, + ClientBuilder, BamlAudio as Audio, invoke_runtime_cli, + ClientRegistry, } from './native' export { BamlStream } from './stream' export { BamlCtxManager } from './async_context_vars' diff --git a/integ-tests/python/baml_client/client.py b/integ-tests/python/baml_client/client.py index a7d6d886e..e59a9082f 100644 --- a/integ-tests/python/baml_client/client.py +++ b/integ-tests/python/baml_client/client.py @@ -39,6 +39,7 @@ def coerce(cls: Type[BaseModel], parsed: Any) -> Any: # Define the TypedDict with optional parameters having default values class BamlCallOptions(TypedDict, total=False): tb: NotRequired[TypeBuilder] + client_registry: NotRequired[baml_py.baml_py.ClientRegistry] class BamlClient: __runtime: baml_py.BamlRuntime @@ -65,6 +66,7 @@ async def AudioInput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "AudioInput", @@ -73,6 +75,7 @@ async def AudioInput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("AudioInputReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -87,6 +90,7 @@ async def ClassifyMessage( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ClassifyMessage", @@ -95,6 +99,7 @@ async def ClassifyMessage( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ClassifyMessageReturnType", inner=(types.Category, ...)) return coerce(mdl, raw.parsed()) @@ -109,6 +114,7 @@ async def ClassifyMessage2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ClassifyMessage2", @@ -117,6 +123,7 @@ async def ClassifyMessage2( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ClassifyMessage2ReturnType", inner=(types.Category, ...)) return coerce(mdl, raw.parsed()) @@ -131,6 +138,7 @@ async def ClassifyMessage3( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ClassifyMessage3", @@ -139,6 +147,7 @@ async def ClassifyMessage3( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ClassifyMessage3ReturnType", inner=(types.Category, ...)) return coerce(mdl, raw.parsed()) @@ -153,6 +162,7 @@ async def DescribeImage( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DescribeImage", @@ -161,6 +171,7 @@ async def DescribeImage( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImageReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -175,6 +186,7 @@ async def DescribeImage2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DescribeImage2", @@ -183,6 +195,7 @@ async def DescribeImage2( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImage2ReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -197,6 +210,7 @@ async def DescribeImage3( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DescribeImage3", @@ -205,6 +219,7 @@ async def DescribeImage3( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImage3ReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -219,6 +234,7 @@ async def DescribeImage4( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DescribeImage4", @@ -227,6 +243,7 @@ async def DescribeImage4( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImage4ReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -241,6 +258,7 @@ async def DummyOutputFunction( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DummyOutputFunction", @@ -249,6 +267,7 @@ async def DummyOutputFunction( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DummyOutputFunctionReturnType", inner=(types.DummyOutput, ...)) return coerce(mdl, raw.parsed()) @@ -263,6 +282,7 @@ async def DynamicFunc( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DynamicFunc", @@ -271,6 +291,7 @@ async def DynamicFunc( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DynamicFuncReturnType", inner=(types.DynamicClassTwo, ...)) return coerce(mdl, raw.parsed()) @@ -285,6 +306,7 @@ async def DynamicInputOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DynamicInputOutput", @@ -293,6 +315,7 @@ async def DynamicInputOutput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DynamicInputOutputReturnType", inner=(types.DynInputOutput, ...)) return coerce(mdl, raw.parsed()) @@ -307,6 +330,7 @@ async def DynamicListInputOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "DynamicListInputOutput", @@ -315,6 +339,7 @@ async def DynamicListInputOutput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DynamicListInputOutputReturnType", inner=(List[types.DynInputOutput], ...)) return coerce(mdl, raw.parsed()) @@ -329,6 +354,7 @@ async def ExtractNames( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ExtractNames", @@ -337,6 +363,7 @@ async def ExtractNames( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractNamesReturnType", inner=(List[str], ...)) return coerce(mdl, raw.parsed()) @@ -351,6 +378,7 @@ async def ExtractPeople( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ExtractPeople", @@ -359,6 +387,7 @@ async def ExtractPeople( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractPeopleReturnType", inner=(List[types.Person], ...)) return coerce(mdl, raw.parsed()) @@ -373,6 +402,7 @@ async def ExtractReceiptInfo( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ExtractReceiptInfo", @@ -381,6 +411,7 @@ async def ExtractReceiptInfo( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractReceiptInfoReturnType", inner=(types.ReceiptInfo, ...)) return coerce(mdl, raw.parsed()) @@ -395,6 +426,7 @@ async def ExtractResume( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ExtractResume", @@ -403,6 +435,7 @@ async def ExtractResume( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractResumeReturnType", inner=(types.Resume, ...)) return coerce(mdl, raw.parsed()) @@ -417,6 +450,7 @@ async def ExtractResume2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "ExtractResume2", @@ -425,6 +459,7 @@ async def ExtractResume2( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractResume2ReturnType", inner=(types.Resume, ...)) return coerce(mdl, raw.parsed()) @@ -439,6 +474,7 @@ async def FnClassOptionalOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnClassOptionalOutput", @@ -447,6 +483,7 @@ async def FnClassOptionalOutput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnClassOptionalOutputReturnType", inner=(Optional[types.ClassOptionalOutput], ...)) return coerce(mdl, raw.parsed()) @@ -461,6 +498,7 @@ async def FnClassOptionalOutput2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnClassOptionalOutput2", @@ -469,6 +507,7 @@ async def FnClassOptionalOutput2( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnClassOptionalOutput2ReturnType", inner=(Optional[types.ClassOptionalOutput2], ...)) return coerce(mdl, raw.parsed()) @@ -483,6 +522,7 @@ async def FnEnumListOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnEnumListOutput", @@ -491,6 +531,7 @@ async def FnEnumListOutput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnEnumListOutputReturnType", inner=(List[types.EnumOutput], ...)) return coerce(mdl, raw.parsed()) @@ -505,6 +546,7 @@ async def FnEnumOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnEnumOutput", @@ -513,6 +555,7 @@ async def FnEnumOutput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnEnumOutputReturnType", inner=(types.EnumOutput, ...)) return coerce(mdl, raw.parsed()) @@ -527,6 +570,7 @@ async def FnNamedArgsSingleStringOptional( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnNamedArgsSingleStringOptional", @@ -535,6 +579,7 @@ async def FnNamedArgsSingleStringOptional( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnNamedArgsSingleStringOptionalReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -549,6 +594,7 @@ async def FnOutputBool( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnOutputBool", @@ -557,6 +603,7 @@ async def FnOutputBool( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputBoolReturnType", inner=(bool, ...)) return coerce(mdl, raw.parsed()) @@ -571,6 +618,7 @@ async def FnOutputClass( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnOutputClass", @@ -579,6 +627,7 @@ async def FnOutputClass( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassReturnType", inner=(types.TestOutputClass, ...)) return coerce(mdl, raw.parsed()) @@ -593,6 +642,7 @@ async def FnOutputClassList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnOutputClassList", @@ -601,6 +651,7 @@ async def FnOutputClassList( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassListReturnType", inner=(List[types.TestOutputClass], ...)) return coerce(mdl, raw.parsed()) @@ -615,6 +666,7 @@ async def FnOutputClassNested( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnOutputClassNested", @@ -623,6 +675,7 @@ async def FnOutputClassNested( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassNestedReturnType", inner=(types.TestClassNested, ...)) return coerce(mdl, raw.parsed()) @@ -637,6 +690,7 @@ async def FnOutputClassWithEnum( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnOutputClassWithEnum", @@ -645,6 +699,7 @@ async def FnOutputClassWithEnum( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassWithEnumReturnType", inner=(types.TestClassWithEnum, ...)) return coerce(mdl, raw.parsed()) @@ -659,6 +714,7 @@ async def FnOutputStringList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnOutputStringList", @@ -667,6 +723,7 @@ async def FnOutputStringList( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputStringListReturnType", inner=(List[str], ...)) return coerce(mdl, raw.parsed()) @@ -681,6 +738,7 @@ async def FnTestAliasedEnumOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnTestAliasedEnumOutput", @@ -689,6 +747,7 @@ async def FnTestAliasedEnumOutput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnTestAliasedEnumOutputReturnType", inner=(types.TestEnum, ...)) return coerce(mdl, raw.parsed()) @@ -703,6 +762,7 @@ async def FnTestClassAlias( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnTestClassAlias", @@ -711,6 +771,7 @@ async def FnTestClassAlias( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnTestClassAliasReturnType", inner=(types.TestClassAlias, ...)) return coerce(mdl, raw.parsed()) @@ -725,6 +786,7 @@ async def FnTestNamedArgsSingleEnum( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "FnTestNamedArgsSingleEnum", @@ -733,6 +795,7 @@ async def FnTestNamedArgsSingleEnum( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnTestNamedArgsSingleEnumReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -747,6 +810,7 @@ async def GetDataType( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "GetDataType", @@ -755,6 +819,7 @@ async def GetDataType( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("GetDataTypeReturnType", inner=(types.RaysData, ...)) return coerce(mdl, raw.parsed()) @@ -769,6 +834,7 @@ async def GetOrderInfo( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "GetOrderInfo", @@ -777,6 +843,7 @@ async def GetOrderInfo( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("GetOrderInfoReturnType", inner=(types.OrderInfo, ...)) return coerce(mdl, raw.parsed()) @@ -791,6 +858,7 @@ async def GetQuery( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "GetQuery", @@ -799,6 +867,7 @@ async def GetQuery( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("GetQueryReturnType", inner=(types.SearchParams, ...)) return coerce(mdl, raw.parsed()) @@ -813,6 +882,7 @@ async def MyFunc( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "MyFunc", @@ -821,6 +891,7 @@ async def MyFunc( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("MyFuncReturnType", inner=(types.DynamicOutput, ...)) return coerce(mdl, raw.parsed()) @@ -835,6 +906,7 @@ async def OptionalTest_Function( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "OptionalTest_Function", @@ -843,6 +915,7 @@ async def OptionalTest_Function( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("OptionalTest_FunctionReturnType", inner=(List[Optional[types.OptionalTest_ReturnType]], ...)) return coerce(mdl, raw.parsed()) @@ -857,6 +930,7 @@ async def PromptTestClaude( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "PromptTestClaude", @@ -865,6 +939,7 @@ async def PromptTestClaude( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestClaudeReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -879,6 +954,7 @@ async def PromptTestClaudeChat( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "PromptTestClaudeChat", @@ -887,6 +963,7 @@ async def PromptTestClaudeChat( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestClaudeChatReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -901,6 +978,7 @@ async def PromptTestClaudeChatNoSystem( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "PromptTestClaudeChatNoSystem", @@ -909,6 +987,7 @@ async def PromptTestClaudeChatNoSystem( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestClaudeChatNoSystemReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -923,6 +1002,7 @@ async def PromptTestOpenAIChat( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "PromptTestOpenAIChat", @@ -931,6 +1011,7 @@ async def PromptTestOpenAIChat( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestOpenAIChatReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -945,6 +1026,7 @@ async def PromptTestOpenAIChatNoSystem( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "PromptTestOpenAIChatNoSystem", @@ -953,6 +1035,7 @@ async def PromptTestOpenAIChatNoSystem( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestOpenAIChatNoSystemReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -967,6 +1050,7 @@ async def PromptTestStreaming( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "PromptTestStreaming", @@ -975,6 +1059,7 @@ async def PromptTestStreaming( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestStreamingReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -989,6 +1074,7 @@ async def TestAnthropic( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestAnthropic", @@ -997,6 +1083,7 @@ async def TestAnthropic( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestAnthropicReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1011,6 +1098,7 @@ async def TestAws( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestAws", @@ -1019,6 +1107,7 @@ async def TestAws( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestAwsReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1033,6 +1122,7 @@ async def TestAzure( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestAzure", @@ -1041,6 +1131,7 @@ async def TestAzure( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestAzureReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1055,6 +1146,7 @@ async def TestFallbackClient( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFallbackClient", @@ -1063,6 +1155,7 @@ async def TestFallbackClient( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFallbackClientReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1077,6 +1170,7 @@ async def TestFnNamedArgsSingleBool( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleBool", @@ -1085,6 +1179,7 @@ async def TestFnNamedArgsSingleBool( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleBoolReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1099,6 +1194,7 @@ async def TestFnNamedArgsSingleClass( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleClass", @@ -1107,6 +1203,7 @@ async def TestFnNamedArgsSingleClass( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleClassReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1121,6 +1218,7 @@ async def TestFnNamedArgsSingleEnumList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleEnumList", @@ -1129,6 +1227,7 @@ async def TestFnNamedArgsSingleEnumList( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleEnumListReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1143,6 +1242,7 @@ async def TestFnNamedArgsSingleFloat( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleFloat", @@ -1151,6 +1251,7 @@ async def TestFnNamedArgsSingleFloat( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleFloatReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1165,6 +1266,7 @@ async def TestFnNamedArgsSingleInt( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleInt", @@ -1173,6 +1275,7 @@ async def TestFnNamedArgsSingleInt( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleIntReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1187,6 +1290,7 @@ async def TestFnNamedArgsSingleString( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleString", @@ -1195,6 +1299,7 @@ async def TestFnNamedArgsSingleString( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleStringReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1209,6 +1314,7 @@ async def TestFnNamedArgsSingleStringArray( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleStringArray", @@ -1217,6 +1323,7 @@ async def TestFnNamedArgsSingleStringArray( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleStringArrayReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1231,6 +1338,7 @@ async def TestFnNamedArgsSingleStringList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestFnNamedArgsSingleStringList", @@ -1239,6 +1347,7 @@ async def TestFnNamedArgsSingleStringList( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleStringListReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1253,6 +1362,7 @@ async def TestGemini( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestGemini", @@ -1261,6 +1371,7 @@ async def TestGemini( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestGeminiReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1275,6 +1386,7 @@ async def TestImageInput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestImageInput", @@ -1283,6 +1395,7 @@ async def TestImageInput( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestImageInputReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1297,6 +1410,7 @@ async def TestMulticlassNamedArgs( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestMulticlassNamedArgs", @@ -1305,6 +1419,7 @@ async def TestMulticlassNamedArgs( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestMulticlassNamedArgsReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1319,6 +1434,7 @@ async def TestOllama( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestOllama", @@ -1327,6 +1443,7 @@ async def TestOllama( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestOllamaReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1341,6 +1458,7 @@ async def TestOpenAI( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestOpenAI", @@ -1349,6 +1467,7 @@ async def TestOpenAI( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestOpenAIReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1363,6 +1482,7 @@ async def TestOpenAILegacyProvider( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestOpenAILegacyProvider", @@ -1371,6 +1491,7 @@ async def TestOpenAILegacyProvider( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestOpenAILegacyProviderReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1385,6 +1506,7 @@ async def TestRetryConstant( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestRetryConstant", @@ -1393,6 +1515,7 @@ async def TestRetryConstant( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestRetryConstantReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1407,6 +1530,7 @@ async def TestRetryExponential( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "TestRetryExponential", @@ -1415,6 +1539,7 @@ async def TestRetryExponential( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestRetryExponentialReturnType", inner=(str, ...)) return coerce(mdl, raw.parsed()) @@ -1429,6 +1554,7 @@ async def UnionTest_Function( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = await self.__runtime.call_function( "UnionTest_Function", @@ -1437,6 +1563,7 @@ async def UnionTest_Function( }, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("UnionTest_FunctionReturnType", inner=(types.UnionTest_ReturnType, ...)) return coerce(mdl, raw.parsed()) @@ -1461,6 +1588,7 @@ def AudioInput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "AudioInput", @@ -1470,6 +1598,7 @@ def AudioInput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("AudioInputReturnType", inner=(str, ...)) @@ -1480,7 +1609,6 @@ def AudioInput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ClassifyMessage( @@ -1493,6 +1621,7 @@ def ClassifyMessage( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ClassifyMessage", @@ -1502,6 +1631,7 @@ def ClassifyMessage( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ClassifyMessageReturnType", inner=(types.Category, ...)) @@ -1512,7 +1642,6 @@ def ClassifyMessage( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ClassifyMessage2( @@ -1525,6 +1654,7 @@ def ClassifyMessage2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ClassifyMessage2", @@ -1534,6 +1664,7 @@ def ClassifyMessage2( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ClassifyMessage2ReturnType", inner=(types.Category, ...)) @@ -1544,7 +1675,6 @@ def ClassifyMessage2( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ClassifyMessage3( @@ -1557,6 +1687,7 @@ def ClassifyMessage3( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ClassifyMessage3", @@ -1566,6 +1697,7 @@ def ClassifyMessage3( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ClassifyMessage3ReturnType", inner=(types.Category, ...)) @@ -1576,7 +1708,6 @@ def ClassifyMessage3( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DescribeImage( @@ -1589,6 +1720,7 @@ def DescribeImage( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DescribeImage", @@ -1598,6 +1730,7 @@ def DescribeImage( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImageReturnType", inner=(str, ...)) @@ -1608,7 +1741,6 @@ def DescribeImage( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DescribeImage2( @@ -1621,6 +1753,7 @@ def DescribeImage2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DescribeImage2", @@ -1631,6 +1764,7 @@ def DescribeImage2( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImage2ReturnType", inner=(str, ...)) @@ -1641,7 +1775,6 @@ def DescribeImage2( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DescribeImage3( @@ -1654,6 +1787,7 @@ def DescribeImage3( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DescribeImage3", @@ -1664,6 +1798,7 @@ def DescribeImage3( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImage3ReturnType", inner=(str, ...)) @@ -1674,7 +1809,6 @@ def DescribeImage3( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DescribeImage4( @@ -1687,6 +1821,7 @@ def DescribeImage4( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DescribeImage4", @@ -1697,6 +1832,7 @@ def DescribeImage4( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DescribeImage4ReturnType", inner=(str, ...)) @@ -1707,7 +1843,6 @@ def DescribeImage4( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DummyOutputFunction( @@ -1720,6 +1855,7 @@ def DummyOutputFunction( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DummyOutputFunction", @@ -1729,6 +1865,7 @@ def DummyOutputFunction( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DummyOutputFunctionReturnType", inner=(types.DummyOutput, ...)) @@ -1739,7 +1876,6 @@ def DummyOutputFunction( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DynamicFunc( @@ -1752,6 +1888,7 @@ def DynamicFunc( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DynamicFunc", @@ -1761,6 +1898,7 @@ def DynamicFunc( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DynamicFuncReturnType", inner=(types.DynamicClassTwo, ...)) @@ -1771,7 +1909,6 @@ def DynamicFunc( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DynamicInputOutput( @@ -1784,6 +1921,7 @@ def DynamicInputOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DynamicInputOutput", @@ -1793,6 +1931,7 @@ def DynamicInputOutput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DynamicInputOutputReturnType", inner=(types.DynInputOutput, ...)) @@ -1803,7 +1942,6 @@ def DynamicInputOutput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def DynamicListInputOutput( @@ -1816,6 +1954,7 @@ def DynamicListInputOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "DynamicListInputOutput", @@ -1825,6 +1964,7 @@ def DynamicListInputOutput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("DynamicListInputOutputReturnType", inner=(List[types.DynInputOutput], ...)) @@ -1835,7 +1975,6 @@ def DynamicListInputOutput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ExtractNames( @@ -1848,6 +1987,7 @@ def ExtractNames( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ExtractNames", @@ -1857,6 +1997,7 @@ def ExtractNames( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractNamesReturnType", inner=(List[str], ...)) @@ -1867,7 +2008,6 @@ def ExtractNames( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ExtractPeople( @@ -1880,6 +2020,7 @@ def ExtractPeople( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ExtractPeople", @@ -1889,6 +2030,7 @@ def ExtractPeople( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractPeopleReturnType", inner=(List[types.Person], ...)) @@ -1899,7 +2041,6 @@ def ExtractPeople( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ExtractReceiptInfo( @@ -1912,6 +2053,7 @@ def ExtractReceiptInfo( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ExtractReceiptInfo", @@ -1921,6 +2063,7 @@ def ExtractReceiptInfo( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractReceiptInfoReturnType", inner=(types.ReceiptInfo, ...)) @@ -1931,7 +2074,6 @@ def ExtractReceiptInfo( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ExtractResume( @@ -1944,6 +2086,7 @@ def ExtractResume( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ExtractResume", @@ -1954,6 +2097,7 @@ def ExtractResume( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractResumeReturnType", inner=(types.Resume, ...)) @@ -1964,7 +2108,6 @@ def ExtractResume( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def ExtractResume2( @@ -1977,6 +2120,7 @@ def ExtractResume2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "ExtractResume2", @@ -1986,6 +2130,7 @@ def ExtractResume2( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("ExtractResume2ReturnType", inner=(types.Resume, ...)) @@ -1996,7 +2141,6 @@ def ExtractResume2( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnClassOptionalOutput( @@ -2009,6 +2153,7 @@ def FnClassOptionalOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnClassOptionalOutput", @@ -2018,6 +2163,7 @@ def FnClassOptionalOutput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnClassOptionalOutputReturnType", inner=(Optional[types.ClassOptionalOutput], ...)) @@ -2028,7 +2174,6 @@ def FnClassOptionalOutput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnClassOptionalOutput2( @@ -2041,6 +2186,7 @@ def FnClassOptionalOutput2( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnClassOptionalOutput2", @@ -2050,6 +2196,7 @@ def FnClassOptionalOutput2( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnClassOptionalOutput2ReturnType", inner=(Optional[types.ClassOptionalOutput2], ...)) @@ -2060,7 +2207,6 @@ def FnClassOptionalOutput2( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnEnumListOutput( @@ -2073,6 +2219,7 @@ def FnEnumListOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnEnumListOutput", @@ -2082,6 +2229,7 @@ def FnEnumListOutput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnEnumListOutputReturnType", inner=(List[types.EnumOutput], ...)) @@ -2092,7 +2240,6 @@ def FnEnumListOutput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnEnumOutput( @@ -2105,6 +2252,7 @@ def FnEnumOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnEnumOutput", @@ -2114,6 +2262,7 @@ def FnEnumOutput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnEnumOutputReturnType", inner=(types.EnumOutput, ...)) @@ -2124,7 +2273,6 @@ def FnEnumOutput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnNamedArgsSingleStringOptional( @@ -2137,6 +2285,7 @@ def FnNamedArgsSingleStringOptional( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnNamedArgsSingleStringOptional", @@ -2146,6 +2295,7 @@ def FnNamedArgsSingleStringOptional( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnNamedArgsSingleStringOptionalReturnType", inner=(str, ...)) @@ -2156,7 +2306,6 @@ def FnNamedArgsSingleStringOptional( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnOutputBool( @@ -2169,6 +2318,7 @@ def FnOutputBool( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnOutputBool", @@ -2178,6 +2328,7 @@ def FnOutputBool( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputBoolReturnType", inner=(bool, ...)) @@ -2188,7 +2339,6 @@ def FnOutputBool( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnOutputClass( @@ -2201,6 +2351,7 @@ def FnOutputClass( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnOutputClass", @@ -2210,6 +2361,7 @@ def FnOutputClass( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassReturnType", inner=(types.TestOutputClass, ...)) @@ -2220,7 +2372,6 @@ def FnOutputClass( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnOutputClassList( @@ -2233,6 +2384,7 @@ def FnOutputClassList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnOutputClassList", @@ -2242,6 +2394,7 @@ def FnOutputClassList( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassListReturnType", inner=(List[types.TestOutputClass], ...)) @@ -2252,7 +2405,6 @@ def FnOutputClassList( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnOutputClassNested( @@ -2265,6 +2417,7 @@ def FnOutputClassNested( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnOutputClassNested", @@ -2274,6 +2427,7 @@ def FnOutputClassNested( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassNestedReturnType", inner=(types.TestClassNested, ...)) @@ -2284,7 +2438,6 @@ def FnOutputClassNested( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnOutputClassWithEnum( @@ -2297,6 +2450,7 @@ def FnOutputClassWithEnum( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnOutputClassWithEnum", @@ -2306,6 +2460,7 @@ def FnOutputClassWithEnum( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputClassWithEnumReturnType", inner=(types.TestClassWithEnum, ...)) @@ -2316,7 +2471,6 @@ def FnOutputClassWithEnum( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnOutputStringList( @@ -2329,6 +2483,7 @@ def FnOutputStringList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnOutputStringList", @@ -2338,6 +2493,7 @@ def FnOutputStringList( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnOutputStringListReturnType", inner=(List[str], ...)) @@ -2348,7 +2504,6 @@ def FnOutputStringList( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnTestAliasedEnumOutput( @@ -2361,6 +2516,7 @@ def FnTestAliasedEnumOutput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnTestAliasedEnumOutput", @@ -2370,6 +2526,7 @@ def FnTestAliasedEnumOutput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnTestAliasedEnumOutputReturnType", inner=(types.TestEnum, ...)) @@ -2380,7 +2537,6 @@ def FnTestAliasedEnumOutput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnTestClassAlias( @@ -2393,6 +2549,7 @@ def FnTestClassAlias( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnTestClassAlias", @@ -2402,6 +2559,7 @@ def FnTestClassAlias( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnTestClassAliasReturnType", inner=(types.TestClassAlias, ...)) @@ -2412,7 +2570,6 @@ def FnTestClassAlias( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def FnTestNamedArgsSingleEnum( @@ -2425,6 +2582,7 @@ def FnTestNamedArgsSingleEnum( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "FnTestNamedArgsSingleEnum", @@ -2434,6 +2592,7 @@ def FnTestNamedArgsSingleEnum( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("FnTestNamedArgsSingleEnumReturnType", inner=(str, ...)) @@ -2444,7 +2603,6 @@ def FnTestNamedArgsSingleEnum( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def GetDataType( @@ -2457,6 +2615,7 @@ def GetDataType( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "GetDataType", @@ -2466,6 +2625,7 @@ def GetDataType( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("GetDataTypeReturnType", inner=(types.RaysData, ...)) @@ -2476,7 +2636,6 @@ def GetDataType( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def GetOrderInfo( @@ -2489,6 +2648,7 @@ def GetOrderInfo( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "GetOrderInfo", @@ -2498,6 +2658,7 @@ def GetOrderInfo( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("GetOrderInfoReturnType", inner=(types.OrderInfo, ...)) @@ -2508,7 +2669,6 @@ def GetOrderInfo( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def GetQuery( @@ -2521,6 +2681,7 @@ def GetQuery( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "GetQuery", @@ -2530,6 +2691,7 @@ def GetQuery( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("GetQueryReturnType", inner=(types.SearchParams, ...)) @@ -2540,7 +2702,6 @@ def GetQuery( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def MyFunc( @@ -2553,6 +2714,7 @@ def MyFunc( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "MyFunc", @@ -2562,6 +2724,7 @@ def MyFunc( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("MyFuncReturnType", inner=(types.DynamicOutput, ...)) @@ -2572,7 +2735,6 @@ def MyFunc( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def OptionalTest_Function( @@ -2585,6 +2747,7 @@ def OptionalTest_Function( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "OptionalTest_Function", @@ -2594,6 +2757,7 @@ def OptionalTest_Function( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("OptionalTest_FunctionReturnType", inner=(List[Optional[types.OptionalTest_ReturnType]], ...)) @@ -2604,7 +2768,6 @@ def OptionalTest_Function( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def PromptTestClaude( @@ -2617,6 +2780,7 @@ def PromptTestClaude( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "PromptTestClaude", @@ -2626,6 +2790,7 @@ def PromptTestClaude( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestClaudeReturnType", inner=(str, ...)) @@ -2636,7 +2801,6 @@ def PromptTestClaude( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def PromptTestClaudeChat( @@ -2649,6 +2813,7 @@ def PromptTestClaudeChat( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "PromptTestClaudeChat", @@ -2658,6 +2823,7 @@ def PromptTestClaudeChat( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestClaudeChatReturnType", inner=(str, ...)) @@ -2668,7 +2834,6 @@ def PromptTestClaudeChat( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def PromptTestClaudeChatNoSystem( @@ -2681,6 +2846,7 @@ def PromptTestClaudeChatNoSystem( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "PromptTestClaudeChatNoSystem", @@ -2690,6 +2856,7 @@ def PromptTestClaudeChatNoSystem( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestClaudeChatNoSystemReturnType", inner=(str, ...)) @@ -2700,7 +2867,6 @@ def PromptTestClaudeChatNoSystem( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def PromptTestOpenAIChat( @@ -2713,6 +2879,7 @@ def PromptTestOpenAIChat( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "PromptTestOpenAIChat", @@ -2722,6 +2889,7 @@ def PromptTestOpenAIChat( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestOpenAIChatReturnType", inner=(str, ...)) @@ -2732,7 +2900,6 @@ def PromptTestOpenAIChat( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def PromptTestOpenAIChatNoSystem( @@ -2745,6 +2912,7 @@ def PromptTestOpenAIChatNoSystem( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "PromptTestOpenAIChatNoSystem", @@ -2754,6 +2922,7 @@ def PromptTestOpenAIChatNoSystem( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestOpenAIChatNoSystemReturnType", inner=(str, ...)) @@ -2764,7 +2933,6 @@ def PromptTestOpenAIChatNoSystem( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def PromptTestStreaming( @@ -2777,6 +2945,7 @@ def PromptTestStreaming( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "PromptTestStreaming", @@ -2786,6 +2955,7 @@ def PromptTestStreaming( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("PromptTestStreamingReturnType", inner=(str, ...)) @@ -2796,7 +2966,6 @@ def PromptTestStreaming( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestAnthropic( @@ -2809,6 +2978,7 @@ def TestAnthropic( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestAnthropic", @@ -2818,6 +2988,7 @@ def TestAnthropic( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestAnthropicReturnType", inner=(str, ...)) @@ -2828,7 +2999,6 @@ def TestAnthropic( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestAws( @@ -2841,6 +3011,7 @@ def TestAws( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestAws", @@ -2850,6 +3021,7 @@ def TestAws( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestAwsReturnType", inner=(str, ...)) @@ -2860,7 +3032,6 @@ def TestAws( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestAzure( @@ -2873,6 +3044,7 @@ def TestAzure( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestAzure", @@ -2882,6 +3054,7 @@ def TestAzure( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestAzureReturnType", inner=(str, ...)) @@ -2892,7 +3065,6 @@ def TestAzure( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFallbackClient( @@ -2905,6 +3077,7 @@ def TestFallbackClient( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFallbackClient", @@ -2913,6 +3086,7 @@ def TestFallbackClient( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFallbackClientReturnType", inner=(str, ...)) @@ -2923,7 +3097,6 @@ def TestFallbackClient( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleBool( @@ -2936,6 +3109,7 @@ def TestFnNamedArgsSingleBool( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleBool", @@ -2945,6 +3119,7 @@ def TestFnNamedArgsSingleBool( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleBoolReturnType", inner=(str, ...)) @@ -2955,7 +3130,6 @@ def TestFnNamedArgsSingleBool( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleClass( @@ -2968,6 +3142,7 @@ def TestFnNamedArgsSingleClass( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleClass", @@ -2977,6 +3152,7 @@ def TestFnNamedArgsSingleClass( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleClassReturnType", inner=(str, ...)) @@ -2987,7 +3163,6 @@ def TestFnNamedArgsSingleClass( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleEnumList( @@ -3000,6 +3175,7 @@ def TestFnNamedArgsSingleEnumList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleEnumList", @@ -3009,6 +3185,7 @@ def TestFnNamedArgsSingleEnumList( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleEnumListReturnType", inner=(str, ...)) @@ -3019,7 +3196,6 @@ def TestFnNamedArgsSingleEnumList( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleFloat( @@ -3032,6 +3208,7 @@ def TestFnNamedArgsSingleFloat( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleFloat", @@ -3041,6 +3218,7 @@ def TestFnNamedArgsSingleFloat( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleFloatReturnType", inner=(str, ...)) @@ -3051,7 +3229,6 @@ def TestFnNamedArgsSingleFloat( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleInt( @@ -3064,6 +3241,7 @@ def TestFnNamedArgsSingleInt( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleInt", @@ -3073,6 +3251,7 @@ def TestFnNamedArgsSingleInt( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleIntReturnType", inner=(str, ...)) @@ -3083,7 +3262,6 @@ def TestFnNamedArgsSingleInt( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleString( @@ -3096,6 +3274,7 @@ def TestFnNamedArgsSingleString( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleString", @@ -3105,6 +3284,7 @@ def TestFnNamedArgsSingleString( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleStringReturnType", inner=(str, ...)) @@ -3115,7 +3295,6 @@ def TestFnNamedArgsSingleString( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleStringArray( @@ -3128,6 +3307,7 @@ def TestFnNamedArgsSingleStringArray( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleStringArray", @@ -3137,6 +3317,7 @@ def TestFnNamedArgsSingleStringArray( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleStringArrayReturnType", inner=(str, ...)) @@ -3147,7 +3328,6 @@ def TestFnNamedArgsSingleStringArray( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestFnNamedArgsSingleStringList( @@ -3160,6 +3340,7 @@ def TestFnNamedArgsSingleStringList( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestFnNamedArgsSingleStringList", @@ -3169,6 +3350,7 @@ def TestFnNamedArgsSingleStringList( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestFnNamedArgsSingleStringListReturnType", inner=(str, ...)) @@ -3179,7 +3361,6 @@ def TestFnNamedArgsSingleStringList( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestGemini( @@ -3192,6 +3373,7 @@ def TestGemini( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestGemini", @@ -3201,6 +3383,7 @@ def TestGemini( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestGeminiReturnType", inner=(str, ...)) @@ -3211,7 +3394,6 @@ def TestGemini( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestImageInput( @@ -3224,6 +3406,7 @@ def TestImageInput( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestImageInput", @@ -3233,6 +3416,7 @@ def TestImageInput( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestImageInputReturnType", inner=(str, ...)) @@ -3243,7 +3427,6 @@ def TestImageInput( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestMulticlassNamedArgs( @@ -3256,6 +3439,7 @@ def TestMulticlassNamedArgs( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestMulticlassNamedArgs", @@ -3266,6 +3450,7 @@ def TestMulticlassNamedArgs( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestMulticlassNamedArgsReturnType", inner=(str, ...)) @@ -3276,7 +3461,6 @@ def TestMulticlassNamedArgs( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestOllama( @@ -3289,6 +3473,7 @@ def TestOllama( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestOllama", @@ -3298,6 +3483,7 @@ def TestOllama( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestOllamaReturnType", inner=(str, ...)) @@ -3308,7 +3494,6 @@ def TestOllama( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestOpenAI( @@ -3321,6 +3506,7 @@ def TestOpenAI( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestOpenAI", @@ -3330,6 +3516,7 @@ def TestOpenAI( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestOpenAIReturnType", inner=(str, ...)) @@ -3340,7 +3527,6 @@ def TestOpenAI( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestOpenAILegacyProvider( @@ -3353,6 +3539,7 @@ def TestOpenAILegacyProvider( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestOpenAILegacyProvider", @@ -3362,6 +3549,7 @@ def TestOpenAILegacyProvider( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestOpenAILegacyProviderReturnType", inner=(str, ...)) @@ -3372,7 +3560,6 @@ def TestOpenAILegacyProvider( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestRetryConstant( @@ -3385,6 +3572,7 @@ def TestRetryConstant( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestRetryConstant", @@ -3393,6 +3581,7 @@ def TestRetryConstant( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestRetryConstantReturnType", inner=(str, ...)) @@ -3403,7 +3592,6 @@ def TestRetryConstant( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def TestRetryExponential( @@ -3416,6 +3604,7 @@ def TestRetryExponential( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "TestRetryExponential", @@ -3424,6 +3613,7 @@ def TestRetryExponential( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("TestRetryExponentialReturnType", inner=(str, ...)) @@ -3434,7 +3624,6 @@ def TestRetryExponential( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) def UnionTest_Function( @@ -3447,6 +3636,7 @@ def UnionTest_Function( tb = __tb__._tb else: tb = None + __cr__ = baml_options.get("client_registry", None) raw = self.__runtime.stream_function( "UnionTest_Function", @@ -3456,6 +3646,7 @@ def UnionTest_Function( None, self.__ctx_manager.get(), tb, + __cr__, ) mdl = create_model("UnionTest_FunctionReturnType", inner=(types.UnionTest_ReturnType, ...)) @@ -3466,6 +3657,5 @@ def UnionTest_Function( lambda x: coerce(partial_mdl, x), lambda x: coerce(mdl, x), self.__ctx_manager.get(), - tb, ) \ No newline at end of file diff --git a/integ-tests/python/tests/test_functions.py b/integ-tests/python/tests/test_functions.py index e32542add..d03de32cb 100644 --- a/integ-tests/python/tests/test_functions.py +++ b/integ-tests/python/tests/test_functions.py @@ -564,6 +564,19 @@ async def test_nested_class_streaming(): print("final ", final.model_dump(mode="json")) +@pytest.mark.asyncio +async def test_dynamic_clients(): + cb = baml_py.ClientRegistry() + cb.add_llm_client("MyClient", "openai", {"model": "gpt-3.5-turbo"}) + cb.set_primary("MyClient") + + final = await b.TestOllama( + input="My name is Harrison. My hair is black and I'm 6 feet tall.", + baml_options={"client_registry": cb}, + ) + print("final ", final) + + @pytest.mark.asyncio async def test_event_log_hook(): def event_log_hook(event: baml_py.baml_py.BamlLogEvent): diff --git a/integ-tests/typescript/baml_client/client.ts b/integ-tests/typescript/baml_client/client.ts index fa7f44534..ed8c6ec70 100644 --- a/integ-tests/typescript/baml_client/client.ts +++ b/integ-tests/typescript/baml_client/client.ts @@ -15,7 +15,7 @@ $ pnpm add @boundaryml/baml // @ts-nocheck // biome-ignore format: autogenerated code /* eslint-disable */ -import { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image } from "@boundaryml/baml" +import { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image, ClientBuilder } from "@boundaryml/baml" import {Blah, ClassOptionalOutput, ClassOptionalOutput2, ClassWithImage, DummyOutput, DynInputOutput, DynamicClassOne, DynamicClassTwo, DynamicOutput, Education, Email, Event, FakeImage, InnerClass, InnerClass2, NamedArgsSingleClass, OptionalTest_Prop1, OptionalTest_ReturnType, OrderInfo, Person, RaysData, ReceiptInfo, ReceiptItem, Resume, SearchParams, SomeClassNestedDynamic, TestClassAlias, TestClassNested, TestClassWithEnum, TestOutputClass, UnionTest_ReturnType, WithReasoning, Category, Category2, Category3, Color, DataType, DynEnumOne, DynEnumTwo, EnumInClass, EnumOutput, Hobby, NamedArgsSingleEnum, NamedArgsSingleEnumList, OptionalTest_CategoryType, OrderStatus, Tag, TestEnum} from "./types" import TypeBuilder from "./type_builder" @@ -43,7 +43,7 @@ export class BamlClient { async AudioInput( aud: Audio, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "AudioInput", @@ -52,13 +52,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async ClassifyMessage( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ClassifyMessage", @@ -67,13 +68,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as Category } async ClassifyMessage2( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ClassifyMessage2", @@ -82,13 +84,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as Category } async ClassifyMessage3( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ClassifyMessage3", @@ -97,13 +100,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as Category } async DescribeImage( img: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DescribeImage", @@ -112,13 +116,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async DescribeImage2( classWithImage: ClassWithImage,img2: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DescribeImage2", @@ -127,13 +132,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async DescribeImage3( classWithImage: ClassWithImage,img2: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DescribeImage3", @@ -142,13 +148,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async DescribeImage4( classWithImage: ClassWithImage,img2: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DescribeImage4", @@ -157,13 +164,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async DummyOutputFunction( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DummyOutputFunction", @@ -172,13 +180,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as DummyOutput } async DynamicFunc( input: DynamicClassOne, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DynamicFunc", @@ -187,13 +196,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as DynamicClassTwo } async DynamicInputOutput( input: DynInputOutput, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DynamicInputOutput", @@ -202,13 +212,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as DynInputOutput } async DynamicListInputOutput( input: DynInputOutput[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "DynamicListInputOutput", @@ -217,13 +228,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as DynInputOutput[] } async ExtractNames( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ExtractNames", @@ -232,13 +244,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string[] } async ExtractPeople( text: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ExtractPeople", @@ -247,13 +260,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as Person[] } async ExtractReceiptInfo( email: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ExtractReceiptInfo", @@ -262,13 +276,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as ReceiptInfo } async ExtractResume( resume: string,img?: Image | null, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ExtractResume", @@ -277,13 +292,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as Resume } async ExtractResume2( resume: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "ExtractResume2", @@ -292,13 +308,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as Resume } async FnClassOptionalOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnClassOptionalOutput", @@ -307,13 +324,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as ClassOptionalOutput | null } async FnClassOptionalOutput2( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnClassOptionalOutput2", @@ -322,13 +340,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as ClassOptionalOutput2 | null } async FnEnumListOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnEnumListOutput", @@ -337,13 +356,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as EnumOutput[] } async FnEnumOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnEnumOutput", @@ -352,13 +372,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as EnumOutput } async FnNamedArgsSingleStringOptional( myString?: string | null, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnNamedArgsSingleStringOptional", @@ -367,13 +388,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async FnOutputBool( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnOutputBool", @@ -382,13 +404,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as boolean } async FnOutputClass( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnOutputClass", @@ -397,13 +420,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as TestOutputClass } async FnOutputClassList( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnOutputClassList", @@ -412,13 +436,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as TestOutputClass[] } async FnOutputClassNested( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnOutputClassNested", @@ -427,13 +452,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as TestClassNested } async FnOutputClassWithEnum( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnOutputClassWithEnum", @@ -442,13 +468,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as TestClassWithEnum } async FnOutputStringList( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnOutputStringList", @@ -457,13 +484,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string[] } async FnTestAliasedEnumOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnTestAliasedEnumOutput", @@ -472,13 +500,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as TestEnum } async FnTestClassAlias( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnTestClassAlias", @@ -487,13 +516,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as TestClassAlias } async FnTestNamedArgsSingleEnum( myArg: NamedArgsSingleEnum, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "FnTestNamedArgsSingleEnum", @@ -502,13 +532,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async GetDataType( text: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "GetDataType", @@ -517,13 +548,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as RaysData } async GetOrderInfo( email: Email, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "GetOrderInfo", @@ -532,13 +564,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as OrderInfo } async GetQuery( query: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "GetQuery", @@ -547,13 +580,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as SearchParams } async MyFunc( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "MyFunc", @@ -562,13 +596,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as DynamicOutput } async OptionalTest_Function( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise<(OptionalTest_ReturnType | null)[]> { const raw = await this.runtime.callFunction( "OptionalTest_Function", @@ -577,13 +612,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as (OptionalTest_ReturnType | null)[] } async PromptTestClaude( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "PromptTestClaude", @@ -592,13 +628,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async PromptTestClaudeChat( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "PromptTestClaudeChat", @@ -607,13 +644,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async PromptTestClaudeChatNoSystem( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "PromptTestClaudeChatNoSystem", @@ -622,13 +660,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async PromptTestOpenAIChat( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "PromptTestOpenAIChat", @@ -637,13 +676,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async PromptTestOpenAIChatNoSystem( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "PromptTestOpenAIChatNoSystem", @@ -652,13 +692,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async PromptTestStreaming( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "PromptTestStreaming", @@ -667,13 +708,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestAnthropic( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestAnthropic", @@ -682,13 +724,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestAws( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestAws", @@ -697,13 +740,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestAzure( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestAzure", @@ -712,13 +756,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFallbackClient( - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFallbackClient", @@ -727,13 +772,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleBool( myBool: boolean, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleBool", @@ -742,13 +788,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleClass( myArg: NamedArgsSingleClass, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleClass", @@ -757,13 +804,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleEnumList( myArg: NamedArgsSingleEnumList[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleEnumList", @@ -772,13 +820,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleFloat( myFloat: number, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleFloat", @@ -787,13 +836,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleInt( myInt: number, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleInt", @@ -802,13 +852,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleString( myString: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleString", @@ -817,13 +868,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleStringArray( myStringArray: string[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleStringArray", @@ -832,13 +884,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestFnNamedArgsSingleStringList( myArg: string[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestFnNamedArgsSingleStringList", @@ -847,13 +900,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestGemini( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestGemini", @@ -862,13 +916,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestImageInput( img: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestImageInput", @@ -877,13 +932,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestMulticlassNamedArgs( myArg: NamedArgsSingleClass,myArg2: NamedArgsSingleClass, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestMulticlassNamedArgs", @@ -892,13 +948,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestOllama( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestOllama", @@ -907,13 +964,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestOpenAI( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestOpenAI", @@ -922,13 +980,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestOpenAILegacyProvider( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestOpenAILegacyProvider", @@ -937,13 +996,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestRetryConstant( - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestRetryConstant", @@ -952,13 +1012,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async TestRetryExponential( - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "TestRetryExponential", @@ -967,13 +1028,14 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as string } async UnionTest_Function( input: string | boolean, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): Promise { const raw = await this.runtime.callFunction( "UnionTest_Function", @@ -982,6 +1044,7 @@ export class BamlClient { }, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return raw.parsed() as UnionTest_ReturnType } @@ -994,7 +1057,7 @@ class BamlStreamClient { AudioInput( aud: Audio, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "AudioInput", @@ -1004,6 +1067,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1016,7 +1080,7 @@ class BamlStreamClient { ClassifyMessage( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, Category> { const raw = this.runtime.streamFunction( "ClassifyMessage", @@ -1026,6 +1090,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, Category>( raw, @@ -1038,7 +1103,7 @@ class BamlStreamClient { ClassifyMessage2( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, Category> { const raw = this.runtime.streamFunction( "ClassifyMessage2", @@ -1048,6 +1113,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, Category>( raw, @@ -1060,7 +1126,7 @@ class BamlStreamClient { ClassifyMessage3( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, Category> { const raw = this.runtime.streamFunction( "ClassifyMessage3", @@ -1070,6 +1136,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, Category>( raw, @@ -1082,7 +1149,7 @@ class BamlStreamClient { DescribeImage( img: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "DescribeImage", @@ -1092,6 +1159,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1104,7 +1172,7 @@ class BamlStreamClient { DescribeImage2( classWithImage: ClassWithImage,img2: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "DescribeImage2", @@ -1114,6 +1182,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1126,7 +1195,7 @@ class BamlStreamClient { DescribeImage3( classWithImage: ClassWithImage,img2: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "DescribeImage3", @@ -1136,6 +1205,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1148,7 +1218,7 @@ class BamlStreamClient { DescribeImage4( classWithImage: ClassWithImage,img2: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "DescribeImage4", @@ -1158,6 +1228,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1170,7 +1241,7 @@ class BamlStreamClient { DummyOutputFunction( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, DummyOutput> { const raw = this.runtime.streamFunction( "DummyOutputFunction", @@ -1180,6 +1251,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, DummyOutput>( raw, @@ -1192,7 +1264,7 @@ class BamlStreamClient { DynamicFunc( input: DynamicClassOne, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, DynamicClassTwo> { const raw = this.runtime.streamFunction( "DynamicFunc", @@ -1202,6 +1274,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, DynamicClassTwo>( raw, @@ -1214,7 +1287,7 @@ class BamlStreamClient { DynamicInputOutput( input: DynInputOutput, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, DynInputOutput> { const raw = this.runtime.streamFunction( "DynamicInputOutput", @@ -1224,6 +1297,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, DynInputOutput>( raw, @@ -1236,7 +1310,7 @@ class BamlStreamClient { DynamicListInputOutput( input: DynInputOutput[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, DynInputOutput[]> { const raw = this.runtime.streamFunction( "DynamicListInputOutput", @@ -1246,6 +1320,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, DynInputOutput[]>( raw, @@ -1258,7 +1333,7 @@ class BamlStreamClient { ExtractNames( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string[]> { const raw = this.runtime.streamFunction( "ExtractNames", @@ -1268,6 +1343,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string[]>( raw, @@ -1280,7 +1356,7 @@ class BamlStreamClient { ExtractPeople( text: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, Person[]> { const raw = this.runtime.streamFunction( "ExtractPeople", @@ -1290,6 +1366,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, Person[]>( raw, @@ -1302,7 +1379,7 @@ class BamlStreamClient { ExtractReceiptInfo( email: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, ReceiptInfo> { const raw = this.runtime.streamFunction( "ExtractReceiptInfo", @@ -1312,6 +1389,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, ReceiptInfo>( raw, @@ -1324,7 +1402,7 @@ class BamlStreamClient { ExtractResume( resume: string,img?: Image | null, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, Resume> { const raw = this.runtime.streamFunction( "ExtractResume", @@ -1334,6 +1412,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, Resume>( raw, @@ -1346,7 +1425,7 @@ class BamlStreamClient { ExtractResume2( resume: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, Resume> { const raw = this.runtime.streamFunction( "ExtractResume2", @@ -1356,6 +1435,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, Resume>( raw, @@ -1368,7 +1448,7 @@ class BamlStreamClient { FnClassOptionalOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, ClassOptionalOutput | null> { const raw = this.runtime.streamFunction( "FnClassOptionalOutput", @@ -1378,6 +1458,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, ClassOptionalOutput | null>( raw, @@ -1390,7 +1471,7 @@ class BamlStreamClient { FnClassOptionalOutput2( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, ClassOptionalOutput2 | null> { const raw = this.runtime.streamFunction( "FnClassOptionalOutput2", @@ -1400,6 +1481,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, ClassOptionalOutput2 | null>( raw, @@ -1412,7 +1494,7 @@ class BamlStreamClient { FnEnumListOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, EnumOutput[]> { const raw = this.runtime.streamFunction( "FnEnumListOutput", @@ -1422,6 +1504,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, EnumOutput[]>( raw, @@ -1434,7 +1517,7 @@ class BamlStreamClient { FnEnumOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, EnumOutput> { const raw = this.runtime.streamFunction( "FnEnumOutput", @@ -1444,6 +1527,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, EnumOutput>( raw, @@ -1456,7 +1540,7 @@ class BamlStreamClient { FnNamedArgsSingleStringOptional( myString?: string | null, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "FnNamedArgsSingleStringOptional", @@ -1466,6 +1550,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1478,7 +1563,7 @@ class BamlStreamClient { FnOutputBool( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, boolean> { const raw = this.runtime.streamFunction( "FnOutputBool", @@ -1488,6 +1573,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, boolean>( raw, @@ -1500,7 +1586,7 @@ class BamlStreamClient { FnOutputClass( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, TestOutputClass> { const raw = this.runtime.streamFunction( "FnOutputClass", @@ -1510,6 +1596,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, TestOutputClass>( raw, @@ -1522,7 +1609,7 @@ class BamlStreamClient { FnOutputClassList( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, TestOutputClass[]> { const raw = this.runtime.streamFunction( "FnOutputClassList", @@ -1532,6 +1619,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, TestOutputClass[]>( raw, @@ -1544,7 +1632,7 @@ class BamlStreamClient { FnOutputClassNested( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, TestClassNested> { const raw = this.runtime.streamFunction( "FnOutputClassNested", @@ -1554,6 +1642,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, TestClassNested>( raw, @@ -1566,7 +1655,7 @@ class BamlStreamClient { FnOutputClassWithEnum( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, TestClassWithEnum> { const raw = this.runtime.streamFunction( "FnOutputClassWithEnum", @@ -1576,6 +1665,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, TestClassWithEnum>( raw, @@ -1588,7 +1678,7 @@ class BamlStreamClient { FnOutputStringList( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string[]> { const raw = this.runtime.streamFunction( "FnOutputStringList", @@ -1598,6 +1688,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string[]>( raw, @@ -1610,7 +1701,7 @@ class BamlStreamClient { FnTestAliasedEnumOutput( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, TestEnum> { const raw = this.runtime.streamFunction( "FnTestAliasedEnumOutput", @@ -1620,6 +1711,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, TestEnum>( raw, @@ -1632,7 +1724,7 @@ class BamlStreamClient { FnTestClassAlias( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, TestClassAlias> { const raw = this.runtime.streamFunction( "FnTestClassAlias", @@ -1642,6 +1734,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, TestClassAlias>( raw, @@ -1654,7 +1747,7 @@ class BamlStreamClient { FnTestNamedArgsSingleEnum( myArg: NamedArgsSingleEnum, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "FnTestNamedArgsSingleEnum", @@ -1664,6 +1757,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1676,7 +1770,7 @@ class BamlStreamClient { GetDataType( text: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, RaysData> { const raw = this.runtime.streamFunction( "GetDataType", @@ -1686,6 +1780,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, RaysData>( raw, @@ -1698,7 +1793,7 @@ class BamlStreamClient { GetOrderInfo( email: Email, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, OrderInfo> { const raw = this.runtime.streamFunction( "GetOrderInfo", @@ -1708,6 +1803,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, OrderInfo>( raw, @@ -1720,7 +1816,7 @@ class BamlStreamClient { GetQuery( query: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, SearchParams> { const raw = this.runtime.streamFunction( "GetQuery", @@ -1730,6 +1826,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, SearchParams>( raw, @@ -1742,7 +1839,7 @@ class BamlStreamClient { MyFunc( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, DynamicOutput> { const raw = this.runtime.streamFunction( "MyFunc", @@ -1752,6 +1849,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, DynamicOutput>( raw, @@ -1764,7 +1862,7 @@ class BamlStreamClient { OptionalTest_Function( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, (OptionalTest_ReturnType | null)[]> { const raw = this.runtime.streamFunction( "OptionalTest_Function", @@ -1774,6 +1872,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, (OptionalTest_ReturnType | null)[]>( raw, @@ -1786,7 +1885,7 @@ class BamlStreamClient { PromptTestClaude( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "PromptTestClaude", @@ -1796,6 +1895,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1808,7 +1908,7 @@ class BamlStreamClient { PromptTestClaudeChat( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "PromptTestClaudeChat", @@ -1818,6 +1918,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1830,7 +1931,7 @@ class BamlStreamClient { PromptTestClaudeChatNoSystem( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "PromptTestClaudeChatNoSystem", @@ -1840,6 +1941,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1852,7 +1954,7 @@ class BamlStreamClient { PromptTestOpenAIChat( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "PromptTestOpenAIChat", @@ -1862,6 +1964,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1874,7 +1977,7 @@ class BamlStreamClient { PromptTestOpenAIChatNoSystem( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "PromptTestOpenAIChatNoSystem", @@ -1884,6 +1987,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1896,7 +2000,7 @@ class BamlStreamClient { PromptTestStreaming( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "PromptTestStreaming", @@ -1906,6 +2010,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1918,7 +2023,7 @@ class BamlStreamClient { TestAnthropic( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestAnthropic", @@ -1928,6 +2033,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1940,7 +2046,7 @@ class BamlStreamClient { TestAws( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestAws", @@ -1950,6 +2056,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1962,7 +2069,7 @@ class BamlStreamClient { TestAzure( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestAzure", @@ -1972,6 +2079,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -1984,7 +2092,7 @@ class BamlStreamClient { TestFallbackClient( - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFallbackClient", @@ -1994,6 +2102,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2006,7 +2115,7 @@ class BamlStreamClient { TestFnNamedArgsSingleBool( myBool: boolean, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleBool", @@ -2016,6 +2125,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2028,7 +2138,7 @@ class BamlStreamClient { TestFnNamedArgsSingleClass( myArg: NamedArgsSingleClass, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleClass", @@ -2038,6 +2148,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2050,7 +2161,7 @@ class BamlStreamClient { TestFnNamedArgsSingleEnumList( myArg: NamedArgsSingleEnumList[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleEnumList", @@ -2060,6 +2171,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2072,7 +2184,7 @@ class BamlStreamClient { TestFnNamedArgsSingleFloat( myFloat: number, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleFloat", @@ -2082,6 +2194,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2094,7 +2207,7 @@ class BamlStreamClient { TestFnNamedArgsSingleInt( myInt: number, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleInt", @@ -2104,6 +2217,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2116,7 +2230,7 @@ class BamlStreamClient { TestFnNamedArgsSingleString( myString: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleString", @@ -2126,6 +2240,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2138,7 +2253,7 @@ class BamlStreamClient { TestFnNamedArgsSingleStringArray( myStringArray: string[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleStringArray", @@ -2148,6 +2263,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2160,7 +2276,7 @@ class BamlStreamClient { TestFnNamedArgsSingleStringList( myArg: string[], - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestFnNamedArgsSingleStringList", @@ -2170,6 +2286,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2182,7 +2299,7 @@ class BamlStreamClient { TestGemini( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestGemini", @@ -2192,6 +2309,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2204,7 +2322,7 @@ class BamlStreamClient { TestImageInput( img: Image, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestImageInput", @@ -2214,6 +2332,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2226,7 +2345,7 @@ class BamlStreamClient { TestMulticlassNamedArgs( myArg: NamedArgsSingleClass,myArg2: NamedArgsSingleClass, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestMulticlassNamedArgs", @@ -2236,6 +2355,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2248,7 +2368,7 @@ class BamlStreamClient { TestOllama( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestOllama", @@ -2258,6 +2378,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2270,7 +2391,7 @@ class BamlStreamClient { TestOpenAI( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestOpenAI", @@ -2280,6 +2401,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2292,7 +2414,7 @@ class BamlStreamClient { TestOpenAILegacyProvider( input: string, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestOpenAILegacyProvider", @@ -2302,6 +2424,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2314,7 +2437,7 @@ class BamlStreamClient { TestRetryConstant( - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestRetryConstant", @@ -2324,6 +2447,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2336,7 +2460,7 @@ class BamlStreamClient { TestRetryExponential( - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, string> { const raw = this.runtime.streamFunction( "TestRetryExponential", @@ -2346,6 +2470,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, string>( raw, @@ -2358,7 +2483,7 @@ class BamlStreamClient { UnionTest_Function( input: string | boolean, - __baml_options__?: { tb?: TypeBuilder } + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } ): BamlStream, UnionTest_ReturnType> { const raw = this.runtime.streamFunction( "UnionTest_Function", @@ -2368,6 +2493,7 @@ class BamlStreamClient { undefined, this.ctx_manager.cloneContext(), __baml_options__?.tb?.__tb(), + __baml_options__?.cr, ) return new BamlStream, UnionTest_ReturnType>( raw, diff --git a/integ-tests/typescript/tests/integ-tests.test.ts b/integ-tests/typescript/tests/integ-tests.test.ts index 042cd1b72..3a4608a66 100644 --- a/integ-tests/typescript/tests/integ-tests.test.ts +++ b/integ-tests/typescript/tests/integ-tests.test.ts @@ -1,7 +1,8 @@ import assert from 'assert' +import { Image, ClientRegistry } from '@boundaryml/baml' +import TypeBuilder from '../baml_client/type_builder' import { scheduler } from 'node:timers/promises' import { image_b64, audio_b64 } from './base64_test_data' -import { Image } from '@boundaryml/baml' import { Audio } from '@boundaryml/baml' import { b, @@ -13,7 +14,6 @@ import { TestClassNested, onLogEvent, } from '../baml_client' -import TypeBuilder from '../baml_client/type_builder' import { RecursivePartialNull } from '../baml_client/client' import { config } from 'dotenv' import { BamlLogEvent, BamlRuntime } from '@boundaryml/baml/native' @@ -399,6 +399,18 @@ describe('Integ tests', () => { expect(msgs.at(-1)).toEqual(final) }) + it('should work with dynamic client', async () => { + const clientRegistry = new ClientRegistry() + clientRegistry.addLlmClient('myClient', 'openai', { + model: 'gpt-3.5-turbo', + }) + clientRegistry.setPrimary('myClient') + + await b.TestOllama('hi', { + clientRegistry, + }) + }) + it("should work with 'onLogEvent'", async () => { onLogEvent((param2) => { console.log('onLogEvent', param2)