BamlRuntime

Struct BamlRuntime 

Source
pub struct BamlRuntime { /* private fields */ }
Expand description

Handle to the BAML runtime

Implementations§

Source§

impl BamlRuntime

Source

pub fn new( baml_src_dir: &str, files: &HashMap<String, String>, env: &HashMap<String, String>, ) -> Result<Self, BamlError>

Create a new runtime from embedded BAML source files

§Arguments
  • baml_src_dir - Base directory path for BAML sources
  • files - Map of relative file paths to file contents
  • env - Environment variables
Source

pub fn call_function<T: BamlDecode>( &self, name: &str, args: &FunctionArgs, ) -> Result<T, BamlError>

Call a function synchronously (blocks until complete)

Source

pub fn call_function_stream<TPartial, TFinal>( &self, name: &str, args: &FunctionArgs, ) -> Result<StreamingCall<TPartial, TFinal>, BamlError>
where TPartial: BamlDecode + Send + 'static, TFinal: Clone + BamlDecode + Send + 'static,

Call a function with streaming results

Source

pub async fn call_function_async<T: BamlDecode>( &self, name: &str, args: &FunctionArgs, ) -> Result<T, BamlError>

Call a function asynchronously (non-blocking)

Source

pub fn call_function_stream_async<TPartial, TFinal>( &self, name: &str, args: &FunctionArgs, ) -> Result<AsyncStreamingCall<TPartial, TFinal>, BamlError>
where TPartial: BamlDecode + Send + 'static, TFinal: Clone + BamlDecode + Send + 'static,

Call a function with async streaming results

Source

pub fn parse<T: BamlDecode>( &self, function_name: &str, llm_response: &str, stream: bool, ) -> Result<T, BamlError>

Parse raw LLM output into typed result

Given the name of a BAML function and the raw text response from an LLM, this method parses the response according to the function’s output type.

§Arguments
  • function_name - Name of the BAML function that defines the output type
  • llm_response - Raw text response from the LLM
§Example
let raw_response = "Hello, World!";
let result: String = runtime.parse("SayHello", raw_response)?;
Source

pub fn new_image_from_url(&self, url: &str, mime_type: Option<&str>) -> Image

Create an Image from a URL

Source

pub fn new_image_from_base64( &self, base64: &str, mime_type: Option<&str>, ) -> Image

Create an Image from base64-encoded data

Source

pub fn new_audio_from_url(&self, url: &str, mime_type: Option<&str>) -> Audio

Create Audio from a URL

Source

pub fn new_audio_from_base64( &self, base64: &str, mime_type: Option<&str>, ) -> Audio

Create Audio from base64-encoded data

Source

pub fn new_pdf_from_url(&self, url: &str, mime_type: Option<&str>) -> Pdf

Create a PDF from a URL

Source

pub fn new_pdf_from_base64(&self, base64: &str, mime_type: Option<&str>) -> Pdf

Create a PDF from base64-encoded data

Source

pub fn new_video_from_url(&self, url: &str, mime_type: Option<&str>) -> Video

Create a Video from a URL

Source

pub fn new_video_from_base64( &self, base64: &str, mime_type: Option<&str>, ) -> Video

Create a Video from base64-encoded data

Source

pub fn new_collector(&self, name: &str) -> Collector

Create a new collector for telemetry

Source

pub fn new_type_builder(&self) -> TypeBuilder

Create a new TypeBuilder for dynamic type construction

Trait Implementations§

Source§

impl Drop for BamlRuntime

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for BamlRuntime

Source§

impl Sync for BamlRuntime

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.