pub struct BamlRuntime { /* private fields */ }Expand description
Handle to the BAML runtime
Implementations§
Source§impl BamlRuntime
impl BamlRuntime
Sourcepub fn new(
baml_src_dir: &str,
files: &HashMap<String, String>,
env: &HashMap<String, String>,
) -> Result<Self, BamlError>
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 sourcesfiles- Map of relative file paths to file contentsenv- Environment variables
Sourcepub fn call_function<T: BamlDecode>(
&self,
name: &str,
args: &FunctionArgs,
) -> Result<T, BamlError>
pub fn call_function<T: BamlDecode>( &self, name: &str, args: &FunctionArgs, ) -> Result<T, BamlError>
Call a function synchronously (blocks until complete)
Sourcepub fn call_function_stream<TPartial, TFinal>(
&self,
name: &str,
args: &FunctionArgs,
) -> Result<StreamingCall<TPartial, TFinal>, BamlError>
pub fn call_function_stream<TPartial, TFinal>( &self, name: &str, args: &FunctionArgs, ) -> Result<StreamingCall<TPartial, TFinal>, BamlError>
Call a function with streaming results
Sourcepub async fn call_function_async<T: BamlDecode>(
&self,
name: &str,
args: &FunctionArgs,
) -> Result<T, BamlError>
pub async fn call_function_async<T: BamlDecode>( &self, name: &str, args: &FunctionArgs, ) -> Result<T, BamlError>
Call a function asynchronously (non-blocking)
Sourcepub fn call_function_stream_async<TPartial, TFinal>(
&self,
name: &str,
args: &FunctionArgs,
) -> Result<AsyncStreamingCall<TPartial, TFinal>, BamlError>
pub fn call_function_stream_async<TPartial, TFinal>( &self, name: &str, args: &FunctionArgs, ) -> Result<AsyncStreamingCall<TPartial, TFinal>, BamlError>
Call a function with async streaming results
Sourcepub fn parse<T: BamlDecode>(
&self,
function_name: &str,
llm_response: &str,
stream: bool,
) -> Result<T, BamlError>
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 typellm_response- Raw text response from the LLM
§Example
let raw_response = "Hello, World!";
let result: String = runtime.parse("SayHello", raw_response)?;Sourcepub fn new_image_from_url(&self, url: &str, mime_type: Option<&str>) -> Image
pub fn new_image_from_url(&self, url: &str, mime_type: Option<&str>) -> Image
Create an Image from a URL
Sourcepub fn new_image_from_base64(
&self,
base64: &str,
mime_type: Option<&str>,
) -> Image
pub fn new_image_from_base64( &self, base64: &str, mime_type: Option<&str>, ) -> Image
Create an Image from base64-encoded data
Sourcepub fn new_audio_from_url(&self, url: &str, mime_type: Option<&str>) -> Audio
pub fn new_audio_from_url(&self, url: &str, mime_type: Option<&str>) -> Audio
Create Audio from a URL
Sourcepub fn new_audio_from_base64(
&self,
base64: &str,
mime_type: Option<&str>,
) -> Audio
pub fn new_audio_from_base64( &self, base64: &str, mime_type: Option<&str>, ) -> Audio
Create Audio from base64-encoded data
Sourcepub fn new_pdf_from_url(&self, url: &str, mime_type: Option<&str>) -> Pdf
pub fn new_pdf_from_url(&self, url: &str, mime_type: Option<&str>) -> Pdf
Create a PDF from a URL
Sourcepub fn new_pdf_from_base64(&self, base64: &str, mime_type: Option<&str>) -> Pdf
pub fn new_pdf_from_base64(&self, base64: &str, mime_type: Option<&str>) -> Pdf
Create a PDF from base64-encoded data
Sourcepub fn new_video_from_url(&self, url: &str, mime_type: Option<&str>) -> Video
pub fn new_video_from_url(&self, url: &str, mime_type: Option<&str>) -> Video
Create a Video from a URL
Sourcepub fn new_video_from_base64(
&self,
base64: &str,
mime_type: Option<&str>,
) -> Video
pub fn new_video_from_base64( &self, base64: &str, mime_type: Option<&str>, ) -> Video
Create a Video from base64-encoded data
Sourcepub fn new_collector(&self, name: &str) -> Collector
pub fn new_collector(&self, name: &str) -> Collector
Create a new collector for telemetry
Sourcepub fn new_type_builder(&self) -> TypeBuilder
pub fn new_type_builder(&self) -> TypeBuilder
Create a new TypeBuilder for dynamic type construction