BamlElixir.Client (baml_elixir v1.0.0-pre.4)

A client for interacting with BAML functions.

This module provides functionality to call BAML functions either synchronously or as a stream.

Examples

# Create a client
client = %BamlElixir.Client{}

# Call a function synchronously
{:ok, result} = BamlElixir.Client.call(client, "MyFunction", %{arg1: "value"})

# Stream function results
stream = BamlElixir.Client.stream!(client, "MyFunction", %{arg1: "value"})
Enum.each(stream, fn result -> IO.inspect(result) end)

Summary

Functions

Calls a BAML function synchronously.

Calls a BAML function and returns a stream of results as tokens are generated by an LLM.

Functions

add_collector(client, collector)

call(client, function_name, args)

@spec call(
  %BamlElixir.Client{client_registry: term(), collectors: term(), from: term()},
  String.t(),
  map()
) :: {:ok, term()} | {:error, String.t()}

Calls a BAML function synchronously.

Parameters

  • client: The BAML client struct
  • function_name: The name of the BAML function to call
  • args: A map of arguments to pass to the function

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

from(client, path)

new()

stream!(client, function_name, args)

@spec stream!(
  %BamlElixir.Client{client_registry: term(), collectors: term(), from: term()},
  String.t(),
  map()
) :: Enumerable.t()

Calls a BAML function and returns a stream of results as tokens are generated by an LLM.

Parameters

  • client: The BAML client struct
  • function_name: The name of the BAML function to call
  • args: A map of arguments to pass to the function

Returns

  • A stream of results

Examples

stream = BamlElixir.Client.stream!(client, "MyFunction", %{arg1: "value"})
Enum.each(stream, fn result -> IO.inspect(result) end)

use_llm_client(client, name)