namespace AIStudio.Tools.Rust; /// /// An image as the Rust runtime prepared it for an AI model, or why it could not. /// /// /// The base64 and its MIME type travel side by side, so a provider which wants a data URL builds /// one and a provider which wants them apart, such as Anthropic, never parses one. /// /// NONE when the image was prepared; then the other values describe it. /// The encoded image as base64, without a data URI prefix. /// The MIME type of the encoded image: image/jpeg or image/png. /// The width of the prepared image in pixels. /// The height of the prepared image in pixels. /// Whether the runtime scaled the image down. public sealed record PreparedModelImage(ModelImageErrorCode ErrorCode, string Base64, string MimeType, uint Width, uint Height, bool WasResized) { /// /// Whether the image can go to the model. /// /// /// The image itself has to be there as well: a success without one would become an empty image /// in the request, which providers refuse along with the whole request. /// public bool IsPrepared => this.ErrorCode is ModelImageErrorCode.NONE && !string.IsNullOrEmpty(this.Base64); /// /// The image as a data URL, as the OpenAI-compatible APIs take it. /// /// The data URL. public string ToDataUrl() => $"data:{this.MimeType};base64,{this.Base64}"; /// /// An image which could not be prepared. /// /// Why it could not be prepared. /// The failed image. public static PreparedModelImage Failed(ModelImageErrorCode errorCode) => new(errorCode, string.Empty, string.Empty, 0, 0, false); }