Skip to content

Commit

Permalink
fix: Fixed generation for implicit array enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed May 21, 2024
1 parent c21dceb commit b222ce3
Show file tree
Hide file tree
Showing 147 changed files with 2,554 additions and 3,642 deletions.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</ItemGroup>

<PropertyGroup Label="Versioning">
<Version>0.6.7</Version>
<Version>0.6.8</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
3 changes: 3 additions & 0 deletions src/libs/OpenApiGenerator.Core/Models/ModelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public static ModelData FromSchema(
.ToImmutableArray(),
Enumerations = schema.Value.Properties
.Select(x => FromSchema(x, settings, innerParents))
.Concat(schema.Value.Properties.SelectMany(x => x.Value.Items != null && x.Value.Items.IsEnum()
? [FromSchema(x.Value.Items.WithKey(x.Key), settings, innerParents)]
: Array.Empty<ModelData>()))
.Where(static x => x.Schema.Value.IsEnum())
.Concat(schema.Value.Properties
.SelectMany(x => WithModelName(x.Value.AnyOf, x.Key, settings, addTypeName: false, innerParents))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//HintName: G.Api.EndPoints.CancelPredictions.g.cs

#nullable enable

namespace G
{
public partial class Api
{
/// <summary>
/// Cancel a prediction
/// </summary>
/// <param name="predictionId"></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 CancelPredictionsAsync(
string predictionId,
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri + $"/predictions/{predictionId}/cancel", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//HintName: G.Api.EndPoints.CancelTrainings.g.cs

#nullable enable

namespace G
{
public partial class Api
{
/// <summary>
/// Cancel a training
/// </summary>
/// <param name="trainingId"></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 CancelTrainingsAsync(
string trainingId,
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri + $"/trainings/{trainingId}/cancel", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Api(
global::System.Uri? baseUri = null)
{
_httpClient = httpClient ?? new global::System.Net.Http.HttpClient();
_httpClient.BaseAddress ??= baseUri ?? new global::System.Uri("http://localhost:11434/api");
_httpClient.BaseAddress ??= baseUri ?? new global::System.Uri("https://api.replicate.com/v1");
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//HintName: G.Api.EndPoints.CreateDeployments.g.cs

#nullable enable

namespace G
{
public partial class Api
{
/// <summary>
/// Create a deployment
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task CreateDeploymentsAsync(
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri + "/deployments", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//HintName: G.Api.EndPoints.CreateModels.g.cs

#nullable enable

namespace G
{
public partial class Api
{
/// <summary>
/// Create a model
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task CreateModelsAsync(
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri + "/models", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: G.Api.EndPoints.PullModel.g.cs
//HintName: G.Api.EndPoints.CreatePredictions.g.cs

#nullable enable

Expand All @@ -7,20 +7,20 @@ namespace G
public partial class Api
{
/// <summary>
/// Download a model from the ollama library.
/// Create a prediction
/// </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<PullModelResponse> PullModelAsync(
PullModelRequest request,
public async global::System.Threading.Tasks.Task CreatePredictionsAsync(
VersionPredictionRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));

using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri + "/pull", global::System.UriKind.RelativeOrAbsolute));
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri + "/predictions", global::System.UriKind.RelativeOrAbsolute));
httpRequest.Content = new global::System.Net.Http.StringContent(
content: global::Newtonsoft.Json.JsonConvert.SerializeObject(request),
encoding: global::System.Text.Encoding.UTF8,
Expand All @@ -31,36 +31,36 @@ public partial class Api
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();

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

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<PullModelResponse>(content) ??
throw new global::System.InvalidOperationException("Response deserialization failed for \"{content}\" ");
}

/// <summary>
/// Download a model from the ollama library.
/// Create a prediction
/// </summary>
/// <param name="name"></param>
/// <param name="insecure"></param>
/// <param name="input"></param>
/// <param name="stream"></param>
/// <param name="version"></param>
/// <param name="webhook"></param>
/// <param name="webhookEventsFilter"></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<PullModelResponse> PullModelAsync(
string name,
bool insecure = default,
public async global::System.Threading.Tasks.Task CreatePredictionsAsync(
VersionPredictionRequestInput input,
string version,
bool stream = default,
string? webhook = default,
global::System.Collections.Generic.IList<VersionPredictionRequestWebhookEventsFilter?>? webhookEventsFilter = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new PullModelRequest
var request = new VersionPredictionRequest
{
Name = name,
Insecure = insecure,
Input = input,
Stream = stream,
Version = version,
Webhook = webhook,
WebhookEventsFilter = webhookEventsFilter,
};

return await PullModelAsync(
await CreatePredictionsAsync(
request: request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//HintName: G.Api.EndPoints.CreatePredictionsDeployments.g.cs

#nullable enable

namespace G
{
public partial class Api
{
/// <summary>
/// Create a prediction using a deployment
/// </summary>
/// <param name="deploymentOwner"></param>
/// <param name="deploymentName"></param>
/// <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 CreatePredictionsDeploymentsAsync(
string deploymentOwner,
string deploymentName,
PredictionRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));

using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri + $"/deployments/{deploymentOwner}/{deploymentName}/predictions", global::System.UriKind.RelativeOrAbsolute));
httpRequest.Content = new global::System.Net.Http.StringContent(
content: global::Newtonsoft.Json.JsonConvert.SerializeObject(request),
encoding: global::System.Text.Encoding.UTF8,
mediaType: "application/json");

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}

/// <summary>
/// Create a prediction using a deployment
/// </summary>
/// <param name="deploymentOwner"></param>
/// <param name="deploymentName"></param>
/// <param name="input"></param>
/// <param name="stream"></param>
/// <param name="webhook"></param>
/// <param name="webhookEventsFilter"></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 CreatePredictionsDeploymentsAsync(
string deploymentOwner,
string deploymentName,
PredictionRequestInput input,
bool stream = default,
string? webhook = default,
global::System.Collections.Generic.IList<PredictionRequestWebhookEventsFilter?>? webhookEventsFilter = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new PredictionRequest
{
Input = input,
Stream = stream,
Webhook = webhook,
WebhookEventsFilter = webhookEventsFilter,
};

await CreatePredictionsDeploymentsAsync(
deploymentOwner: deploymentOwner,
deploymentName: deploymentName,
request: request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Loading

0 comments on commit b222ce3

Please sign in to comment.