Table of Contents

Struct ThinkValue

Namespace
OllamaSharp.Models.Chat
Assembly
OllamaSharp.dll

Represents a "think" value that can either be a boolean or a string indication, such as "high", "medium", "low" (e.g., gpt-oss).

[JsonConverter(typeof(ThinkValueConverter))]
public readonly struct ThinkValue : IEquatable<ThinkValue>
Implements
Inherited Members

Constructors

ThinkValue(bool?)

Represents a struct that encapsulates a value for "think" which can be either a boolean or a predefined string value indicating levels such as "high", "medium", or "low".

public ThinkValue(bool? value)

Parameters

value bool?

Remarks

This type provides implicit and explicit conversion operators to enable flexible usage with nullable booleans, booleans, and strings. It supports equality comparisons and ensures case-insensitive comparisons for string values.

ThinkValue(object?)

Represents a struct that encapsulates a "think" value, which can be a boolean (e.g., true or false) or a string representation of levels, such as "high", "medium", or "low", commonly used in scenarios like gpt-oss models.

public ThinkValue(object? value)

Parameters

value object

Remarks

This type provides flexibility in the representation of values by supporting implicit and explicit conversions between string, bool, and bool?. The design facilitates usage in logic requiring predefined string levels or boolean states.

ThinkValue(string?)

Represents a struct that encapsulates a value for "think" that can either be a boolean (true/false) or a string like ("high", "medium", "low") used for gpt-oss models.

public ThinkValue(string? value)

Parameters

value string

Examples

Example conversion scenarios include initializing this value from a boolean, nullable boolean, or string, or interpreting its string representation.

Remarks

This type provides implicit and explicit conversion operators between bool, bool?, and string, enabling flexible usage for boolean logic or predefined string-based levels.

Fields

High

Represents a high level for the think value.

public const string High = "high"

Field Value

string

Low

Represents a low level for the think value.

public const string Low = "low"

Field Value

string

Medium

Represents a medium level for the think value.

public const string Medium = "medium"

Field Value

string

Methods

Equals(ThinkValue)

Determines whether the specified ThinkValue instance is equal to the current instance.

public bool Equals(ThinkValue other)

Parameters

other ThinkValue

The ThinkValue instance to compare with the current instance.

Returns

bool

true if the specified ThinkValue is equal to the current instance; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to the current ThinkValue instance.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if the specified object is equal to the current instance; otherwise, false.

GetHashCode()

Serves as the default hash function. Computes a hash code for the current instance based on its value.

public override int GetHashCode()

Returns

int

An integer hash code that is case-insensitive and consistent with the string value of the instance.

IsBoolean()

Determines whether the current ThinkValue represents a boolean value.

public bool IsBoolean()

Returns

bool

True if the value represents a boolean (true/false), otherwise false.

ToBoolean()

Converts the current ThinkValue instance to a nullable boolean value.

public bool? ToBoolean()

Returns

bool?

A nullable boolean value representing the "think" state. Returns true, false, or null depending on the encapsulated value.

Remarks

The conversion is based on the internal representation of the value within the ThinkValue instance. If the underlying value is a string that can be interpreted as a boolean, it will be converted. Otherwise, null may be returned.

ToString()

Returns the string representation of the value.

public override string? ToString()

Returns

string

The string value.

Operators

operator ==(ThinkValue, ThinkValue)

Defines an equality operator for the ThinkValue structure, allowing comparison of two ThinkValue instances to determine if they are equal.

public static bool operator ==(ThinkValue left, ThinkValue right)

Parameters

left ThinkValue

The first ThinkValue instance to compare.

right ThinkValue

The second ThinkValue instance to compare.

Returns

bool

True if both ThinkValue instances are equal; otherwise, false.

explicit operator string?(ThinkValue)

Explicitly converts a ThinkValue instance to a nullable string.

public static explicit operator string?(ThinkValue value)

Parameters

value ThinkValue

The ThinkValue instance to convert.

Returns

string

The string representation of the ThinkValue instance if defined; otherwise, null.

implicit operator bool?(ThinkValue)

Defines a user-defined conversion from a ThinkValue to a nullable boolean. This operator attempts to convert the internal value of the ThinkValue instance to a nullable boolean. If the internal value is null, the result will be null. If the value can be parsed as a boolean, it will return the parsed boolean value. If it cannot be parsed, it returns false, ensuring safe handling of the conversion.

public static implicit operator bool?(ThinkValue value)

Parameters

value ThinkValue

The ThinkValue instance to convert.

Returns

bool?

A nullable boolean representation of the ThinkValue.

implicit operator ThinkValue(bool)

Allows implicit conversion from a boolean value to a ThinkValue.

public static implicit operator ThinkValue(bool value)

Parameters

value bool

The boolean value to be converted.

Returns

ThinkValue

A ThinkValue instance representing the given boolean value.

implicit operator ThinkValue(bool?)

Defines an implicit operator for converting a nullable boolean value to an instance of the ThinkValue struct. This allows a nullable boolean to be directly assigned to a ThinkValue without explicit conversion.

public static implicit operator ThinkValue(bool? value)

Parameters

value bool?

The nullable boolean value to be converted.

Returns

ThinkValue

A ThinkValue instance representing the provided boolean value.

implicit operator ThinkValue(string?)

Defines an implicit conversion operator to allow a string to be implicitly converted into a ThinkValue structure.

public static implicit operator ThinkValue(string? value)

Parameters

value string

The string value to convert.

Returns

ThinkValue

A new instance of ThinkValue initialized with the provided string.

operator !=(ThinkValue, ThinkValue)

Implements an inequality operator for the ThinkValue struct. Returns true if the two ThinkValue instances are not equal, otherwise false.

public static bool operator !=(ThinkValue left, ThinkValue right)

Parameters

left ThinkValue

The first ThinkValue instance for comparison.

right ThinkValue

The second ThinkValue instance for comparison.

Returns

bool

A boolean indicating whether the two ThinkValue instances are not equal.