Skip to content

nodestep.chat.integrations

Built-in chat integrations: ScriptedChat for tests, and OpenAIChat in the openai extra.

Anthropic (Claude) and Ollama are planned. See Agents and tools for the table of chat integrations, and Test with ScriptedChat.

Scripted model

ScriptedChat

ScriptedChat(responses=(), *, default=None)

Chat model that returns scripted responses, for tests and examples.

Parameters
responsesIterable[ChatResponse | str]

Responses returned in order, one per request. A str means ChatResponse(content=...).

defaultChatResponse | str | None

Response returned for every request after the script runs out. Without it, such a request raises ModelProviderError.

Raises
TypeError

If a response or default is neither a ChatResponse nor a str.

Attributes
modelstr

Always "scripted".

responseslist[ChatResponse]

Responses not returned yet, in order. A response without a model reports "scripted".

requestslist[ChatRequest]

Every request received, in order.

Methods

async complete(request)

Record the request and return the next scripted response.

async complete(request) -> ChatResponse

Parameters
requestChatRequest
Raises
ModelProviderError

If the script ran out and no default was given.

async stream(request)

Return the next scripted response as stream chunks.

async stream(request) -> AsyncIterator[ChatStreamChunk]

The chunks are the content word by word, whitespace kept, then the refusal, one tool_call_delta per tool call, the finish reason and the usage when set.

Parameters
requestChatRequest
Raises
ModelProviderError

If the script ran out and no default was given.

ValueError

If the response sets raw or has a tool call with arguments_error; assemble_stream cannot rebuild those.