PlainLLM
This crate offers a small client for interacting with a language model API. It focuses on three operations:
ask– single question returning plain text.call_llm– general chat interface returning anLLMResponseand supporting streaming and tool calls.call_llm_structured– likecall_llmbut automatically parses the answer into your own type.
All methods return Result<T, plainllm::Error> where the error describes HTTP or JSON failures and issues executing tools.
Basic usage
use ;
async
General calls
call_llm takes a model name, a list of messages and optional LLMOptions.
It returns an LLMResponse with the full data from the server.
use ;
let llm = new;
let messages = vec!;
let opts = new
.streaming
.temperature
.max_tokens;
let resp = llm.call_llm.await?;
LLMOptions lets you enable streaming and tweak parameters like
temperature, top_p or max_tokens. You can also attach event handlers such as
on_token, on_start_thinking, on_stop_thinking, on_thinking,
on_tool_call and on_tool_result.
Structured output
call_llm_structured requires a type that implements Deserialize and
JsonSchema. The response is parsed directly into that type.
use ;
use JsonSchema;
use ;
let llm = new;
let messages = vec!;
let res: Answer = llm.call_llm_structured.await?;
Tools
Functions can be exposed to the model through a ToolRegistry.
Tools are built with FunctionTool::from_type or FunctionToolBuilder and
registered on the registry. call_llm will automatically execute tool
requests when a registry is provided in LLMOptions.
use ;
use JsonSchema;
use ;
async
let mut registry = new;
registry.register;
let llm = new;
let messages = vec!;
let opts = new.with_tools;
let resp = llm.call_llm.await?;
License
MIT 2025 - Victor Bjelkholm