SwiftInferChatModel class

A dartantic ChatModel that speaks swift-infer's Anthropic-compatible /v1/messages wire (ADR 0003, lenny-4dhv.1).

Why a custom model instead of dartantic's stock AnthropicChatModel:

  • swift-infer/Qwen streams thinking content blocks without Anthropic's cryptographic signature. anthropic_sdk_dart's strict parser hard-casts signature as a non-null String and throws every turn. This model parses the SSE leniently and never requires a signature.
  • swift-infer accepts Qwen-tuned sampling knobs (top_k, presence_penalty, repetition_penalty, reasoning_effort, preserve_thinking) that AnthropicChatOptions cannot express. Unset knobs are omitted so the node's model-card defaults apply.

Streaming convention mirrors dartantic's own Anthropic mapper: each emitted ChatResult's output is a delta ChatMessage carrying the incremental part(s) — a ThinkingPart for reasoning deltas, a TextPart for answer text, and a single ToolPart.call emitted at content_block_stop once its input_json has fully accumulated. finishReason rides the message_delta. A higher layer (dartantic's Agent/accumulator, or lenny's ModelProvider seam) consolidates the deltas.

swift-infer / Qwen quirk: reasoning can arrive either as native Anthropic thinking/thinking_delta blocks OR inlined as <think>...</think> markers inside text_delta. Both are routed to ThinkingPart; the <think> scan is stateful across chunks (including markers split across chunk boundaries). The marker handling is inbound only — prior reasoning is always replayed outbound as a native thinking content block.

Tool names are passed through verbatim and must match Anthropic's ^[a-zA-Z0-9_-]{1,64}$ (no dots). lenny's dotted tool namespacing (core.tap) is encoded/decoded by the ModelProvider seam, not here, so this generic model stays backend-agnostic.

Web-compatible: pure Dart over package:http, no dart:io. Does not retry internally — it uses the supplied client directly, so the caller owns retry/timing (the lenny SchemaRejection/runaway-cap policy lives in the seam, not here).

Constructors

SwiftInferChatModel({required String name, required Uri baseUrl, List<Tool<Object>>? tools, double? temperature, String? bearerToken, Map<String, String> headers = const {}, Client? client, SwiftInferChatOptions? defaultOptions})
Creates a swift-infer chat model.

Properties

defaultOptions SwiftInferChatOptions
The default options for the chat model.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
name String
The model name to use.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
temperature double?
The temperature for the model.
finalinherited
tools List<Tool<Object>>?
The tools the model may call.
finalinherited

Methods

dispose() → void
Disposes the chat model.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendStream(List<ChatMessage> messages, {SwiftInferChatOptions? options, Schema? outputSchema}) Stream<ChatResult<ChatMessage>>
Streaming method that returns Message objects.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited