Skip to content

DecisionState

Namespace: Vercel.AI.Operations

public sealed class DecisionState

Shared state of a decision: text, a JSON object, or ordered parts. Maps to DecisionState. A JSON array is not valid state. Wrap it in an object or in a DecisionJsonPart. CancellationToken) maps to prepareDecisionState.

Inheritance: object

View source

public JsonElement? Json { get; }

The JSON object, when the state is an object.

Value: JsonElement?

View source

public IReadOnlyList<DecisionStatePart>? Parts { get; }

The parts, when the state is a list of parts.

Value: IReadOnlyList<DecisionStatePart>

View source

public string? Text { get; }

The text, when the state is a string.

Value: string

View source

public static DecisionState From(IReadOnlyList<DecisionStatePart> parts)

Creates state from ordered parts.

Parameters

Name Type Description
parts IReadOnlyList<DecisionStatePart>

Returns: DecisionState

View source

public static DecisionState From(string text)

Creates state from text.

Parameters

Name Type Description
text string

Returns: DecisionState

View source

public static DecisionState FromJson(JsonElement value)

Creates state from a JSON object. Any other JSON value throws InvalidArgumentException.

Parameters

Name Type Description
value JsonElement

Returns: DecisionState

View source

PrepareDecisionStateAsync(DecisionState, CancellationToken)

Section titled “PrepareDecisionStateAsync(DecisionState, CancellationToken)”
public static Task<IReadOnlyList<DecisionModelStatePart>> PrepareDecisionStateAsync(DecisionState state, CancellationToken cancellationToken = default)

Turns public state into the list of parts the model receives. URL files are downloaded. File media types are resolved to a full type.

Parameters

Name Type Description
state DecisionState
cancellationToken CancellationToken

Returns: Task<IReadOnlyList<DecisionModelStatePart>>

View source

public static implicit operator DecisionState(string text)

Converts text to state.

Parameters

Name Type Description
text string

Returns: DecisionState

View source

implicit operator DecisionState(DecisionStatePart[])

Section titled “implicit operator DecisionState(DecisionStatePart[])”
public static implicit operator DecisionState(DecisionStatePart[] parts)

Converts an array of parts to state.

Parameters

Name Type Description
parts DecisionStatePart\[\]

Returns: DecisionState

View source

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