lllm.testing
Fake models for running native agents without a provider. Import from
lllm.testing; see Testing for how to use them.
ScriptedModel
ScriptedModel(replies: Iterable[Reply])
FunctionModel
FunctionModel(function: Callable[[ModelRequest], Reply])
Answer every model call with function(request).
The function receives a :class:ModelRequest and returns the reply
text, a :class:ToolCall, or a list of tool calls. Every request is kept
in requests, so tests can check what the model was asked.
ModelRequest
dataclass
ModelRequest(model: str, messages: list[dict[str, Any]], tools: list[str], response_format: Any = None)
What the model was asked: the messages, the tools on offer, and the format.
text
property
text: str
The content of the last message, as text.
system
property
system: str
The system prompt, if the dialog has one.
Some providers' requests (OpenAI's, for example) carry it with the
developer role instead of system.
tool_results
tool_results() -> list[str]
Contents of the tool results since the last user message.
ToolCall
dataclass
ToolCall(name: str, arguments: dict[str, Any] = dict())
A reply that calls a tool: ToolCall("search", {"query": "lllm"}).