Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,345 @@

#nullable enable

namespace Ideogram
{
public partial class GenerateClient
{
partial void PreparePostLayerizeTextV3Arguments(
global::System.Net.Http.HttpClient httpClient,
global::Ideogram.LayerizeTextRequest request);
partial void PreparePostLayerizeTextV3Request(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
global::Ideogram.LayerizeTextRequest request);
partial void ProcessPostLayerizeTextV3Response(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessPostLayerizeTextV3ResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);

/// <summary>
/// Detect and extract text layers from an image<br/>
/// Analyzes an image to detect text regions, then returns each detected text block with its position, content, font information, and styling.<br/>
/// The response includes a text-erased base image (background with all text removed) and a flat list of detected text blocks.<br/>
/// Supported image formats include JPEG, PNG, and WebP (max size 10MB).<br/>
/// Image links are available for a limited period of time; if you would like to keep the image, you must download it.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::Ideogram.ApiException"></exception>
public async global::System.Threading.Tasks.Task<global::Ideogram.LayerizeTextResponse> PostLayerizeTextV3Async(

global::Ideogram.LayerizeTextRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));

PrepareArguments(
client: HttpClient);
PreparePostLayerizeTextV3Arguments(
httpClient: HttpClient,
request: request);

var __pathBuilder = new global::Ideogram.PathBuilder(
path: "/v1/ideogram-v3/layerize-text",
baseUri: HttpClient.BaseAddress);
var __path = __pathBuilder.ToString();
using var __httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));
#if NET6_0_OR_GREATER
__httpRequest.Version = global::System.Net.HttpVersion.Version11;
__httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher;
#endif

foreach (var __authorization in Authorizations)
{
if (__authorization.Type == "Http" ||
__authorization.Type == "OAuth2")
{
__httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: __authorization.Name,
parameter: __authorization.Value);
}
else if (__authorization.Type == "ApiKey" &&
__authorization.Location == "Header")
{
__httpRequest.Headers.Add(__authorization.Name, __authorization.Value);
}
}
using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent();
var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty<byte>());
__httpRequestContent.Add(
content: __contentImage,
name: "\"image\"",
fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty);
if (__contentImage.Headers.ContentDisposition != null)
{
__contentImage.Headers.ContentDisposition.FileNameStar = null;
}
if (request.Prompt != default)
{

__httpRequestContent.Add(
content: new global::System.Net.Http.StringContent($"{request.Prompt}"),
name: "\"prompt\"");
}
if (request.Seed != default)
{

__httpRequestContent.Add(
content: new global::System.Net.Http.StringContent($"{request.Seed}"),
name: "\"seed\"");
}
__httpRequest.Content = __httpRequestContent;

PrepareRequest(
client: HttpClient,
request: __httpRequest);
PreparePostLayerizeTextV3Request(
httpClient: HttpClient,
httpRequestMessage: __httpRequest,
request: request);

using var __response = await HttpClient.SendAsync(
request: __httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

ProcessResponse(
client: HttpClient,
response: __response);
ProcessPostLayerizeTextV3Response(
httpClient: HttpClient,
httpResponseMessage: __response);
//
if ((int)__response.StatusCode == 400)
{
string? __content_400 = null;
global::System.Exception? __exception_400 = null;
try
{
if (ReadResponseAsString)
{
__content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
__content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
}
catch (global::System.Exception __ex)
{
__exception_400 = __ex;
}

throw new global::Ideogram.ApiException(
message: __content_400 ?? __response.ReasonPhrase ?? string.Empty,
innerException: __exception_400,
statusCode: __response.StatusCode)
{
ResponseBody = __content_400,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
//
if ((int)__response.StatusCode == 401)
{
string? __content_401 = null;
global::System.Exception? __exception_401 = null;
try
{
if (ReadResponseAsString)
{
__content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
__content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
}
catch (global::System.Exception __ex)
{
__exception_401 = __ex;
}

throw new global::Ideogram.ApiException(
message: __content_401 ?? __response.ReasonPhrase ?? string.Empty,
innerException: __exception_401,
statusCode: __response.StatusCode)
{
ResponseBody = __content_401,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
//
if ((int)__response.StatusCode == 429)
{
string? __content_429 = null;
global::System.Exception? __exception_429 = null;
try
{
if (ReadResponseAsString)
{
__content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
__content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
}
catch (global::System.Exception __ex)
{
__exception_429 = __ex;
}

throw new global::Ideogram.ApiException(
message: __content_429 ?? __response.ReasonPhrase ?? string.Empty,
innerException: __exception_429,
statusCode: __response.StatusCode)
{
ResponseBody = __content_429,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

if (ReadResponseAsString)
{
var __content = await __response.Content.ReadAsStringAsync(
#if NET5_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ProcessResponseContent(
client: HttpClient,
response: __response,
content: ref __content);
ProcessPostLayerizeTextV3ResponseContent(
httpClient: HttpClient,
httpResponseMessage: __response,
content: ref __content);

try
{
__response.EnsureSuccessStatusCode();

return
global::Ideogram.LayerizeTextResponse.FromJson(__content, JsonSerializerContext) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
catch (global::System.Exception __ex)
{
throw new global::Ideogram.ApiException(
message: __content ?? __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseBody = __content,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
}
else
{
try
{
__response.EnsureSuccessStatusCode();
using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

return
await global::Ideogram.LayerizeTextResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ??
throw new global::System.InvalidOperationException("Response deserialization failed.");
}
catch (global::System.Exception __ex)
{
string? __content = null;
try
{
__content = await __response.Content.ReadAsStringAsync(
#if NET5_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);
}
catch (global::System.Exception)
{
}

throw new global::Ideogram.ApiException(
message: __content ?? __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseBody = __content,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
}
}
/// <summary>
/// Detect and extract text layers from an image<br/>
/// Analyzes an image to detect text regions, then returns each detected text block with its position, content, font information, and styling.<br/>
/// The response includes a text-erased base image (background with all text removed) and a flat list of detected text blocks.<br/>
/// Supported image formats include JPEG, PNG, and WebP (max size 10MB).<br/>
/// Image links are available for a limited period of time; if you would like to keep the image, you must download it.
/// </summary>
/// <param name="image">
/// The image to analyze for text detection. The image should be in JPEG, PNG, or WebP format (max size 10MB).
/// </param>
/// <param name="imagename">
/// The image to analyze for text detection. The image should be in JPEG, PNG, or WebP format (max size 10MB).
/// </param>
/// <param name="prompt">
/// An optional text description of the image. If not provided, a description will be auto-generated from the image.
/// </param>
/// <param name="seed">
/// Random seed. Set for reproducible generation.<br/>
/// Example: 12345
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::Ideogram.LayerizeTextResponse> PostLayerizeTextV3Async(
byte[] image,
string imagename,
string? prompt = default,
int? seed = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var __request = new global::Ideogram.LayerizeTextRequest
{
Image = image,
Imagename = imagename,
Prompt = prompt,
Seed = seed,
};

return await PostLayerizeTextV3Async(
request: __request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#nullable enable

namespace Ideogram
{
public partial interface IGenerateClient
{
/// <summary>
/// Detect and extract text layers from an image<br/>
/// Analyzes an image to detect text regions, then returns each detected text block with its position, content, font information, and styling.<br/>
/// The response includes a text-erased base image (background with all text removed) and a flat list of detected text blocks.<br/>
/// Supported image formats include JPEG, PNG, and WebP (max size 10MB).<br/>
/// Image links are available for a limited period of time; if you would like to keep the image, you must download it.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::Ideogram.ApiException"></exception>
global::System.Threading.Tasks.Task<global::Ideogram.LayerizeTextResponse> PostLayerizeTextV3Async(

global::Ideogram.LayerizeTextRequest request,
global::System.Threading.CancellationToken cancellationToken = default);
/// <summary>
/// Detect and extract text layers from an image<br/>
/// Analyzes an image to detect text regions, then returns each detected text block with its position, content, font information, and styling.<br/>
/// The response includes a text-erased base image (background with all text removed) and a flat list of detected text blocks.<br/>
/// Supported image formats include JPEG, PNG, and WebP (max size 10MB).<br/>
/// Image links are available for a limited period of time; if you would like to keep the image, you must download it.
/// </summary>
/// <param name="image">
/// The image to analyze for text detection. The image should be in JPEG, PNG, or WebP format (max size 10MB).
/// </param>
/// <param name="imagename">
/// The image to analyze for text detection. The image should be in JPEG, PNG, or WebP format (max size 10MB).
/// </param>
/// <param name="prompt">
/// An optional text description of the image. If not provided, a description will be auto-generated from the image.
/// </param>
/// <param name="seed">
/// Random seed. Set for reproducible generation.<br/>
/// Example: 12345
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
global::System.Threading.Tasks.Task<global::Ideogram.LayerizeTextResponse> PostLayerizeTextV3Async(
byte[] image,
string imagename,
string? prompt = default,
int? seed = default,
global::System.Threading.CancellationToken cancellationToken = default);
}
}
Loading