Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate support for OpenAPI 3.1 #354

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Addressing comments
  • Loading branch information
SergeyMenshykh committed Apr 7, 2023
commit 302ab6442187db5d7a1c05850d484d6c17f78cf4
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ public static async Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSk
//using HttpClient client = new HttpClient(retryHandler, false);
using HttpClient client = new HttpClient();

response = await client.GetAsync(url, cancellationToken);
response = await client.GetAsync(url, cancellationToken).ConfigureAwait(false);
}
else
{
response = await httpClient.GetAsync(url, cancellationToken);
response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
}
response.EnsureSuccessStatusCode();

string gptPluginJson = await response.Content.ReadAsStringAsync();
string gptPluginJson = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
string? openApiUrl = ParseOpenApiUrl(gptPluginJson);

return await kernel.ImportOpenApiSkillFromUrlAsync(skillName, new Uri(openApiUrl), httpClient, authCallback, cancellationToken);
return await kernel.ImportOpenApiSkillFromUrlAsync(skillName, new Uri(openApiUrl), httpClient, authCallback, cancellationToken).ConfigureAwait(false);
}
finally
{
Expand Down Expand Up @@ -99,11 +99,11 @@ public static async Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSk
}

using StreamReader reader = new StreamReader(stream);
string gptPluginJson = await reader.ReadToEndAsync();
string gptPluginJson = await reader.ReadToEndAsync().ConfigureAwait(false);

string? openApiUrl = ParseOpenApiUrl(gptPluginJson);

return await kernel.ImportOpenApiSkillFromUrlAsync(skillName, new Uri(openApiUrl), httpClient, authCallback, cancellationToken);
return await kernel.ImportOpenApiSkillFromUrlAsync(skillName, new Uri(openApiUrl), httpClient, authCallback, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -116,7 +116,7 @@ public static async Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSk
/// <param name="authCallback">Optional callback for adding auth data to the API requests.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A list of all the semantic functions representing the skill.</returns>
public static async Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSkillSkillFromDirectoryAsync(
public async static Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSkillSkillFromDirectoryAsync(
this IKernel kernel,
string parentDirectory,
string skillDirectoryName,
Expand Down Expand Up @@ -155,7 +155,7 @@ public static async Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSk
/// <param name="authCallback">Optional callback for adding auth data to the API requests.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A list of all the semantic functions representing the skill.</returns>
public static async Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSkillSkillFromFileAsync(
public async static Task<IDictionary<string, ISKFunction>> ImportChatGptPluginSkillSkillFromFileAsync(
this IKernel kernel,
string skillName,
string filePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro
//using HttpClient client = new HttpClient(retryHandler, false);
using HttpClient client = new HttpClient();

response = await client.GetAsync(url, cancellationToken);
response = await client.GetAsync(url, cancellationToken).ConfigureAwait(false);
}
else
{
response = await httpClient.GetAsync(url, cancellationToken);
response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
}
response.EnsureSuccessStatusCode();

Stream stream = await response.Content.ReadAsStreamAsync();
Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
if (stream == null)
{
throw new MissingManifestResourceException($"Unable to load OpenApi skill from url '{url}'.");
}

return await kernel.RegisterOpenApiSkillAsync(stream, skillName, authCallback, cancellationToken);
return await kernel.RegisterOpenApiSkillAsync(stream, skillName, authCallback, cancellationToken).ConfigureAwait(false);
}
finally
{
Expand All @@ -91,7 +91,7 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro
/// <param name="authCallback">Optional callback for adding auth data to the API requests.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A list of all the semantic functions representing the skill.</returns>
public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFromResourceAsync(this IKernel kernel, string skillName, AuthenticateRequestAsyncCallback? authCallback = null, CancellationToken cancellationToken = default)
public static Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFromResourceAsync(this IKernel kernel, string skillName, AuthenticateRequestAsyncCallback? authCallback = null, CancellationToken cancellationToken = default)
{
Verify.ValidSkillName(skillName);

Expand All @@ -105,7 +105,7 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro
throw new MissingManifestResourceException($"Unable to load OpenApi skill from assembly resource '{resourceName}'.");
}

return await kernel.RegisterOpenApiSkillAsync(stream, skillName, authCallback, cancellationToken);
return kernel.RegisterOpenApiSkillAsync(stream, skillName, authCallback, cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -142,7 +142,7 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro

using var stream = File.OpenRead(openApiDocumentPath);

return await kernel.RegisterOpenApiSkillAsync(stream, skillDirectoryName, authCallback, cancellationToken);
return await kernel.RegisterOpenApiSkillAsync(stream, skillDirectoryName, authCallback, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -166,7 +166,7 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro

using var stream = File.OpenRead(filePath);

return await kernel.RegisterOpenApiSkillAsync(stream, skillName, authCallback, cancellationToken);
return await kernel.RegisterOpenApiSkillAsync(stream, skillName, authCallback, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -186,7 +186,7 @@ public static async Task<IDictionary<string, ISKFunction>> RegisterOpenApiSkillA
//Parse
var parser = new OpenApiDocumentParser();

var operations = await parser.ParseAsync(documentStream, cancellationToken);
var operations = await parser.ParseAsync(documentStream, cancellationToken).ConfigureAwait(false);

var skill = new Dictionary<string, ISKFunction>();

Expand Down Expand Up @@ -253,7 +253,7 @@ async Task<SKContext> ExecuteAsync(SKContext context)
}
}

var result = await runner.RunAsync(operation, arguments, context.CancellationToken);
var result = await runner.RunAsync(operation, arguments, context.CancellationToken).ConfigureAwait(false);
if (result != null)
{
context.Variables.Update(result.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ internal class OpenApiDocumentParser : IOpenApiDocumentParser
/// <inheritdoc/>
public async Task<IList<RestApiOperation>> ParseAsync(Stream stream, CancellationToken cancellationToken = default)
{
var jsonObject = await this.DowngradeDocumentVersionToSuportedOneAsync(stream, cancellationToken);
var jsonObject = await this.DowngradeDocumentVersionToSuportedOneAsync(stream, cancellationToken).ConfigureAwait(false);
adrianwyatt marked this conversation as resolved.
Show resolved Hide resolved

using var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonObject.ToJson()));

var result = await this._openApiReader.ReadAsync(memoryStream, cancellationToken);
var result = await this._openApiReader.ReadAsync(memoryStream, cancellationToken).ConfigureAwait(false);

if (result.OpenApiDiagnostic.Errors.Any())
{
Expand Down Expand Up @@ -105,7 +105,7 @@ private async Task<JsonObject> DowngradeDocumentVersionToSuportedOneAsync(Stream

using var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(obj)));

return await JsonSerializer.DeserializeAsync<JsonObject>(memoryStream, cancellationToken: cancellationToken);
return await JsonSerializer.DeserializeAsync<JsonObject>(memoryStream, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public RestApiOperationRunner(HttpClient httpClient, AuthenticateRequestAsyncCal
}

/// <inheritdoc/>
public async Task<JsonNode?> RunAsync(RestApiOperation operation, IDictionary<string, string> arguments, CancellationToken cancellationToken = default)
public Task<JsonNode?> RunAsync(RestApiOperation operation, IDictionary<string, string> arguments, CancellationToken cancellationToken = default)
{
var url = operation.BuildOperationUrl(arguments);

var headers = operation.RenderHeaders(arguments);

var payload = BuildOperationPayload(operation.Payload, arguments);

return await this.SendAsync(url, operation.Method, headers, payload, cancellationToken);
return this.SendAsync(url, operation.Method, headers, payload, cancellationToken);
}

#region private
Expand Down Expand Up @@ -90,9 +90,9 @@ public RestApiOperationRunner(HttpClient httpClient, AuthenticateRequestAsyncCal
}
}

using var responseMessage = await this._httpClient.SendAsync(requestMessage, cancellationToken);
using var responseMessage = await this._httpClient.SendAsync(requestMessage, cancellationToken).ConfigureAwait(false);

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

responseMessage.EnsureSuccessStatusCode();

Expand Down