BamlElixir.Client (baml_elixir v1.0.0-pre.8)
A client for interacting with BAML functions. Data structures and functions are generated from BAML source files.
use BamlElixir.Client, path: "priv/baml_src"
When you use BamlElixir.Client, it will define:
- A module for each function in the BAML source files with
call/2andstream/3functions along with the types. - A module with
defstruct/1and@type t/0for each class in the BAML source file. - A module with
@type t/0for each enum in the BAML source file.
The path option is optional and defaults to "baml_src", you may want to set it to "priv/baml_src".
This module also provides functionality to call BAML functions either sync/async.
Summary
Functions
Calls a BAML function synchronously.
Parameters
function_name: The name of the BAML function to callargs: A map of arguments to pass to the functionopts: A map of optionspath: The path to the BAML source filecollectors: A list of collectors to usellm_client: The name of the LLM client to use
Returns
{:ok, term()}on success, where the term is the function's return value{:error, String.t()}on failure, with an error message
Examples
{:ok, result} = BamlElixir.Client.call(client, "MyFunction", %{arg1: "value"})
Streams a BAML function asynchronously.
Parameters
function_name: The name of the BAML function to streamargs: A map of arguments to pass to the functioncallback: A function that will be called with the result of the functionopts: A map of optionspath: The path to the BAML source filecollectors: A list of collectors to usellm_client: The name of the LLM client to use