Skip to main content

with_llm_context

Function with_llm_context 

Source
pub fn with_llm_context<F, R>(model: &str, component: &str, f: F) -> R
where F: FnOnce() -> R,
Expand description

Execute a closure with LLM context, automatically clearing when done

This is the most secure pattern as it guarantees context cleanup even if the closure panics or returns early.

§Example

ⓘ
let result = with_llm_context("gpt-4", "openai_client", || {
    log::info!("This has LLM context");
    process_llm_request()
});