namespace AIStudio.Models;
///
/// How much a model can read and write in one conversation, in tokens.
///
///
/// Two numbers, because the model cards name two. There is what the model does as it ships, and
/// there is what an operator can raise it to by configuring the engine, usually through one of the
/// rope-scaling settings. A self-hosted model runs at whatever its operator chose, so the second
/// number is a ceiling, not a promise.
///
/// Nothing here says "unknown" with a zero. The default value of this type is unknown, which is the
/// right answer for a model nobody has written anything about yet, and a known window can never be
/// zero tokens wide because the factory below refuses to build one.
///
public readonly record struct ContextWindow
{
///
/// The window of a model we have no statement about.
///
public static readonly ContextWindow UNKNOWN = new();
///
/// Whether anything is known about this window at all. When false, both numbers are meaningless.
///
public bool IsKnown { get; private init; }
///
/// What the model reads and writes without anyone configuring it.
///
public int DefaultTokens { get; private init; }
///
/// What an operator can raise the window to, or null when it cannot be raised or nobody knows.
///
public int? RaisableToTokens { get; private init; }
///
/// States a known context window.
///
/// What the model does as it ships. Has to be greater than zero.
/// What an operator can raise it to. Has to be at least the default.
/// The window.
public static ContextWindow Of(int defaultTokens, int? raisableTo = null)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(defaultTokens);
if (raisableTo is not null)
ArgumentOutOfRangeException.ThrowIfLessThan(raisableTo.Value, defaultTokens);
return new()
{
IsKnown = true,
DefaultTokens = defaultTokens,
RaisableToTokens = raisableTo,
};
}
}