Skip to content

Commit

Permalink
test: Added Ideogram test files.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 21, 2024
1 parent 8b18263 commit 37bec29
Show file tree
Hide file tree
Showing 187 changed files with 10,823 additions and 419 deletions.
2 changes: 1 addition & 1 deletion src/libs/AutoSDK/Models/EndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static EndPoint FromSchema(OperationContext operation)
? requestProperty.Name
: $"request{requestProperty.Name.ToPropertyName()}",
Type = requestProperty.Type,
IsRequired = requestProperty.IsRequired,
IsRequired = requestProperty.IsRequired,// is { IsRequired: true, IsReadOnly: false },
IsMultiPartFormDataFilename = requestProperty.IsMultiPartFormDataFilename,
DefaultValue = requestProperty.DefaultValue,
IsDeprecated = requestProperty.IsDeprecated,
Expand Down
11 changes: 9 additions & 2 deletions src/libs/AutoSDK/Models/PropertyData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.OpenApi.Models;
using AutoSDK.Extensions;
using AutoSDK.Serialization.Json;

Expand All @@ -9,6 +8,8 @@ public readonly record struct PropertyData(
string Name,
TypeData Type,
bool IsRequired,
bool IsReadOnly,
bool IsWriteOnly,
bool IsMultiPartFormDataFilename,
Settings Settings,
string? DefaultValue,
Expand All @@ -21,6 +22,8 @@ public readonly record struct PropertyData(
Name: string.Empty,
Type: TypeData.Default,
IsRequired: false,
IsReadOnly: false,
IsWriteOnly: false,
IsMultiPartFormDataFilename: false,
DefaultValue: null,
IsDeprecated: false,
Expand Down Expand Up @@ -49,7 +52,9 @@ public static PropertyData FromSchemaContext(SchemaContext context)
? new HashSet<string>(context.Parent.Schema.Required)
: [];

var isRequired = requiredProperties.Contains(propertyName);
var isRequired =
requiredProperties.Contains(propertyName);// &&
//context.Schema is { WriteOnly: false };
// Special case for enums with a single value.
if (isRequired && type is { IsEnum: true, EnumValues.Length: 1 })
{
Expand All @@ -61,6 +66,8 @@ public static PropertyData FromSchemaContext(SchemaContext context)
Name: name,
Type: type,
IsRequired: isRequired,
IsReadOnly: context.Schema.ReadOnly,
IsWriteOnly: context.Schema.WriteOnly,
IsMultiPartFormDataFilename: false,
Settings: context.Settings,
IsDeprecated: context.Schema.Deprecated,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//HintName: G.Api.Authorizations..g.cs

#nullable enable

namespace G
{
public sealed partial class Api
{
/// <summary>
/// Authorize using ApiKey authentication.
/// </summary>
/// <param name="apiKey"></param>
public void AuthorizeUsingApiKey(
string apiKey)
{
apiKey = apiKey ?? throw new global::System.ArgumentNullException(nameof(apiKey));

_httpClient.DefaultRequestHeaders.Add("Api-Key", apiKey);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//HintName: G.Api.Constructors..g.cs

#nullable enable

namespace G
{
public sealed partial class Api
{
/// <inheritdoc cref="Api(global::System.Net.Http.HttpClient?, global::System.Uri?)"/>
public Api(
string apiKey,
global::System.Net.Http.HttpClient? httpClient = null,
global::System.Uri? baseUri = null) : this(httpClient, baseUri)
{
Authorizing(_httpClient, ref apiKey);

AuthorizeUsingApiKey(apiKey);

Authorized(_httpClient);
}

partial void Authorizing(
global::System.Net.Http.HttpClient client,
ref string apiKey);
partial void Authorized(
global::System.Net.Http.HttpClient client);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//HintName: G.Api.g.cs

#nullable enable

namespace G
{
/// <summary>
/// This is the API definition for Ideogram AI.<br/>
/// If no httpClient is provided, a new one will be created.<br/>
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
public sealed partial class Api : global::G.IApi, global::System.IDisposable
{
/// <summary>
///
/// </summary>
public const string BaseUrl = "";

private readonly global::System.Net.Http.HttpClient _httpClient;

/// <summary>
///
/// </summary>
public global::Newtonsoft.Json.JsonSerializerSettings JsonSerializerOptions { get; set; } = new global::Newtonsoft.Json.JsonSerializerSettings();


/// <summary>
/// All things related to generating content.
/// </summary>
public GenerateClient Generate => new GenerateClient(_httpClient)
{
JsonSerializerOptions = JsonSerializerOptions,
};

/// <summary>
/// Content related to managing API account and API access
/// </summary>
public ManageClient Manage => new ManageClient(_httpClient)
{
JsonSerializerOptions = JsonSerializerOptions,
};

/// <summary>
/// Operations related to understanding visual content
/// </summary>
public VisionClient Vision => new VisionClient(_httpClient)
{
JsonSerializerOptions = JsonSerializerOptions,
};

/// <summary>
/// Creates a new instance of the Api.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
/// <param name="httpClient"></param>
/// <param name="baseUri"></param>
/// <param name="jsonSerializerOptions"></param>
public Api(
global::System.Net.Http.HttpClient? httpClient = null,
global::System.Uri? baseUri = null)
{
_httpClient = httpClient ?? new global::System.Net.Http.HttpClient();
_httpClient.BaseAddress ??= baseUri ?? new global::System.Uri(BaseUrl);

Initialized(_httpClient);
}

/// <inheritdoc/>
public void Dispose()
{
_httpClient.Dispose();
}

partial void Initialized(
global::System.Net.Http.HttpClient client);
partial void PrepareArguments(
global::System.Net.Http.HttpClient client);
partial void PrepareRequest(
global::System.Net.Http.HttpClient client,
global::System.Net.Http.HttpRequestMessage request);
partial void ProcessResponse(
global::System.Net.Http.HttpClient client,
global::System.Net.Http.HttpResponseMessage response);
partial void ProcessResponseContent(
global::System.Net.Http.HttpClient client,
global::System.Net.Http.HttpResponseMessage response,
ref string content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//HintName: G.GenerateClient.PostGenerateImage.g.cs

#nullable enable

namespace G
{
public partial class GenerateClient
{
partial void PreparePostGenerateImageArguments(
global::System.Net.Http.HttpClient httpClient,
global::G.GenerateImageRequest request);
partial void PreparePostGenerateImageRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
global::G.GenerateImageRequest request);
partial void ProcessPostGenerateImageResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

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

/// <summary>
/// Generates images synchronously based on a given prompt and optional parameters.<br/>
/// A request to generate an image with Ideogram.
/// </summary>
/// <param name="request"></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::G.GenerateImageResponse> PostGenerateImageAsync(
global::G.GenerateImageRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));

PrepareArguments(
client: _httpClient);
PreparePostGenerateImageArguments(
httpClient: _httpClient,
request: request);

var __pathBuilder = new PathBuilder(
path: "/generate",
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));
var __httpRequestContentBody = global::Newtonsoft.Json.JsonConvert.SerializeObject(request, JsonSerializerOptions);
var __httpRequestContent = new global::System.Net.Http.StringContent(
content: __httpRequestContentBody,
encoding: global::System.Text.Encoding.UTF8,
mediaType: "application/json");
httpRequest.Content = __httpRequestContent;

PrepareRequest(
client: _httpClient,
request: httpRequest);
PreparePostGenerateImageRequest(
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);
ProcessPostGenerateImageResponse(
httpClient: _httpClient,
httpResponseMessage: response);

var __content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

ProcessResponseContent(
client: _httpClient,
response: response,
content: ref __content);
ProcessPostGenerateImageResponseContent(
httpClient: _httpClient,
httpResponseMessage: response,
content: ref __content);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::G.GenerateImageResponse?>(__content, JsonSerializerOptions) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}

/// <summary>
/// Generates images synchronously based on a given prompt and optional parameters.<br/>
/// A request to generate an image with Ideogram.
/// </summary>
/// <param name="imageRequest"></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::G.GenerateImageResponse> PostGenerateImageAsync(
global::G.ImageRequest imageRequest,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new global::G.GenerateImageRequest
{
ImageRequest = imageRequest,
};

return await PostGenerateImageAsync(
request: request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Loading

0 comments on commit 37bec29

Please sign in to comment.