Skip to content

ExtractReasoningMiddleware

Namespace: Vercel.AI

public sealed class ExtractReasoningMiddleware : LanguageModelMiddleware, ILanguageModelMiddleware

Splits delimited reasoning, such as <think>...</think>, out of text. Maps to extractReasoningMiddleware.

Inheritance: object → LanguageModelMiddleware

Implements: ILanguageModelMiddleware

View source

ExtractReasoningMiddleware(string, string, bool)

Section titled “ExtractReasoningMiddleware(string, string, bool)”
public ExtractReasoningMiddleware(string tagName = "think", string separator = "\n", bool startWithReasoning = false)

Creates middleware for the XML tags <tagName> and </tagName>.

Parameters

Name Type Description
tagName string Tag name without angle brackets.
separator string Joins reasoning blocks, and the text around them.
startWithReasoning bool Prepends the opening tag when the model omits it.

View source

ExtractReasoningMiddleware((string Opening, string Closing), string, bool)

Section titled “ExtractReasoningMiddleware((string Opening, string Closing), string, bool)”
public ExtractReasoningMiddleware((string Opening, string Closing) tagName, string separator = "\n", bool startWithReasoning = false)

Creates middleware for literal delimiters, such as Gemma’s thought channel.

Parameters

Name Type Description
tagName (string Opening, string Closing) Literal opening and closing delimiters.
separator string Joins reasoning blocks, and the text around them.
startWithReasoning bool Prepends the opening delimiter when the model omits it.

View source

WrapGenerateAsync(LanguageModelCallOptions, Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelGenerateResult>>, CancellationToken)

Section titled “WrapGenerateAsync(LanguageModelCallOptions, Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelGenerateResult>>, CancellationToken)”
public override Task<LanguageModelGenerateResult> WrapGenerateAsync(LanguageModelCallOptions options, Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelGenerateResult>> next, CancellationToken cancellationToken)

Wraps a generate call.

Parameters

Name Type Description
options LanguageModelCallOptions
next Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelGenerateResult>>
cancellationToken CancellationToken

Returns: Task<LanguageModelGenerateResult>

View source

WrapStreamAsync(LanguageModelCallOptions, Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelStreamResult>>, CancellationToken)

Section titled “WrapStreamAsync(LanguageModelCallOptions, Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelStreamResult>>, CancellationToken)”
public override Task<LanguageModelStreamResult> WrapStreamAsync(LanguageModelCallOptions options, Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelStreamResult>> next, CancellationToken cancellationToken)

Wraps a stream call.

Parameters

Name Type Description
options LanguageModelCallOptions
next Func<LanguageModelCallOptions, CancellationToken, Task<LanguageModelStreamResult>>
cancellationToken CancellationToken

Returns: Task<LanguageModelStreamResult>

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product