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:
- Extracts messages from input state
- Prepends system prompt
- Calls the model
- 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.") }
})?;