Skip to content

Image

Namespace: TypeSafe.AI.Sdk

public sealed class Image

A PNG or JPEG image for CancellationToken). Image support is experimental: send the TypeSafe-Danger-Zone-Images: true header to opt in.

Inheritance: object

Place the image in State or in question instructions or criteria, or interpolate it into From(FormattableString); either way it is sent under its own reference, ToString(). To reference it by a name of your choice, add it to Assets. The API detects the format from the file bytes and rejects formats other than PNG and JPEG with a BadRequestException.

View source

public Image(ReadOnlyMemory<byte> data)

Create an image from file bytes. The bytes are copied.

Parameters

Name Type Description
data ReadOnlyMemory<byte>

Exceptions

Type Condition
TypeSafeException <code class=“paramref”>data</code> is empty.

View source

public ReadOnlyMemory<byte> Data { get; }

The image file bytes.

Value: ReadOnlyMemory<byte>

View source

public static Image FromBase64(string text)

Create an image from base64-encoded file bytes, without a data: URL prefix.

Parameters

Name Type Description
text string

Returns: Image

Exceptions

Type Condition
TypeSafeException <code class=“paramref”>text</code> isn’t valid base64 or decodes to no bytes.

View source

public static Image FromFile(string path)

Create an image from the bytes of a file, read now.

Parameters

Name Type Description
path string

Returns: Image

Exceptions

Type Condition
TypeSafeException The file is empty or can’t be read.
ArgumentException <code class=“paramref”>path</code> is null or empty.

View source

public override string ToString()

The unique reference this image is sent under, for referencing it inside text.

Returns: string

View source

MIT · Copyright (c) Dario Kondratiuk. · not affiliated with TypeSafe beyond being a client of the public API