Function: extractReasoningFields()
ts
function extractReasoningFields(
src: Partial<Record<ReasoningField, string | null | undefined>> | undefined,
precedence: ReasoningFieldPrecedence,
): ReasoningExtract[];Defined in: batteries/llm/openai_chat_completions/helpers.ts:80
Pulls model reasoning/thinking text out of a Chat Completions response message or stream delta, reading every wire field named in precedence that carries a non-empty string.
Parameters
| Parameter | Type | Description |
|---|---|---|
src | | Partial<Record<ReasoningField, string | null | undefined>> | undefined | The response message or stream delta to read from. |
precedence | ReasoningFieldPrecedence | Ordered, de-duplicated field names to read (see reasoningFieldPrecedence). |
Returns
The present, content-deduplicated reasoning traces in precedence order.
Remarks
Reasoning is not part of OpenAI's official Chat Completions spec, so OpenAI-compatible providers disagree on the field name (reasoning for Ollama and current vLLM; reasoning_content for legacy vLLM and DeepSeek). This reads the union, in precedence order, and de-duplicates by content value: a field whose text exactly matches one already kept is dropped.
The result length encodes the emission rule the callers follow:
0— no reasoning present.1— a single thought (covers "only one field present" AND "several present but identical").≥2— divergent fields; each surfaces as its own thought rather than silently dropping one.