Skip to main content

invoke_llm

Function invoke_llm 

Source
pub fn invoke_llm(
    model: &dyn BaseChatModel,
    input: &Value,
    system_prompt: &str,
) -> Result<Value, RunnableError>
Expand description

Invoke an LLM and return a state update.

This is the complete LLM node logic in one call:

  1. Extracts messages from input state
  2. Prepends system prompt
  3. Calls the model
  4. Wraps response in state update format

§Example

let model_clone = model.clone();
graph.add_node("chatbot", move |input: JsonValue, _config: RunnableConfig| {
    let model = model_clone.clone();
    async move { invoke_llm(model.as_ref(), &input, "You are a helpful assistant.") }
})?;