Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc committed May 4, 2023
1 parent 46e4440 commit a478fdb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private async Task<T> ExecutePostRequestAsync<T>(string url, string requestBody,
using HttpContent content = new StringContent(requestBody, Encoding.UTF8, "application/json");

HttpResponseMessage response = await this.HTTPClient.PostAsync(url, content, cancellationToken).ConfigureAwait(false)
?? throw new AIException(AIException.ErrorCodes.NoResponse);
?? throw new AIException(AIException.ErrorCodes.NoResponse);

this.Log.LogTrace("HTTP response: {0} {1}", (int)response.StatusCode, response.StatusCode.ToString("G"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public async Task<Plan> CreatePlanAsync(string goal)
return plan;
}


// TODO: use goal to find relevant functions in a skill store
/// <summary>
/// Native function returning a list of all the functions in the current context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.SemanticKernel.SkillDefinition;
/// <summary>
/// Skill collection interface.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "It is a collection")]
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "It is a collection")]
public interface ISkillCollection : IReadOnlySkillCollection
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public async Task<IEnumerable<TaskManagementTask>> GetTasksAsync(string listId,
{
filterValue = "status ne 'completed'";
}

ITodoTaskListTasksCollectionPage tasksPage = await this._graphServiceClient.Me
.Todo.Lists[listId]
.Tasks.Request().Filter(filterValue).GetAsync(cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public static class KernelChatGptPluginExtensions
string gptPluginJson = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
string? openApiUrl = ParseOpenApiUrl(gptPluginJson);

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

/// <summary>
Expand Down Expand Up @@ -85,14 +87,16 @@ public static class KernelChatGptPluginExtensions
var resourceName = $"{skillName}.ai-plugin.json";

var stream = type.Assembly.GetManifestResourceStream(type, resourceName)
?? throw new MissingManifestResourceException($"Unable to load OpenApi skill from assembly resource '{resourceName}'.");
?? throw new MissingManifestResourceException($"Unable to load OpenApi skill from assembly resource '{resourceName}'");

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

string? openApiUrl = ParseOpenApiUrl(gptPluginJson);

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

/// <summary>
Expand Down Expand Up @@ -132,7 +136,9 @@ public static class KernelChatGptPluginExtensions

using var stream = File.OpenRead(chatGptPluginPath);

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

/// <summary>
Expand All @@ -155,14 +161,16 @@ public static class KernelChatGptPluginExtensions
{
if (!File.Exists(filePath))
{
throw new FileNotFoundException($"No ChatGPT plugin for the specified path - {filePath} is found.");
throw new FileNotFoundException($"No ChatGPT plugin for the specified path - {filePath} is found");
}

kernel.Log.LogTrace("Registering Rest functions from {0} ChatGPT Plugin.", filePath);
kernel.Log.LogTrace("Registering Rest functions from {0} ChatGPT Plugin", filePath);

using var stream = File.OpenRead(filePath);

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

private static string ParseOpenApiUrl(string gptPluginJson)
Expand All @@ -178,7 +186,7 @@ private static string ParseOpenApiUrl(string gptPluginJson)
string? openApiUrl = gptPlugin?["api"]?["url"]?.ToString();
if (string.IsNullOrWhiteSpace(openApiUrl))
{
throw new InvalidOperationException($"Invalid ChatGPT plugin document. OpenAPI url is missing");
throw new InvalidOperationException($"Invalid ChatGPT plugin document, OpenAPI URL is missing");
}

return openApiUrl!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.Graph;
using Microsoft.Graph.CallRecords;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.AI;
using Microsoft.SemanticKernel.Orchestration;
Expand All @@ -20,6 +18,7 @@
using SemanticKernel.Service.Model;
using SemanticKernel.Service.Skills;
using SemanticKernel.Service.Storage;
using Directory = System.IO.Directory;

namespace SemanticKernel.Service.Controllers;

Expand Down Expand Up @@ -146,10 +145,14 @@ public class SemanticKernelController : ControllerBase, IDisposable
private async Task RegisterPlannerSkillsAsync(CopilotChatPlanner planner, PlannerOptions options, OpenApiSkillsAuthHeaders openApiSkillsAuthHeaders)
{
// Register the Klarna shopping ChatGPT plugin with the planner's kernel.
using DefaultHttpRetryHandler retryHandler = new(new HttpRetryConfig(), this._logger) { InnerHandler = new HttpClientHandler() { CheckCertificateRevocationList = true } };
using DefaultHttpRetryHandler retryHandler = new(new HttpRetryConfig(), this._logger)
{
InnerHandler = new HttpClientHandler() { CheckCertificateRevocationList = true }
};
using HttpClient importHttpClient = new HttpClient(retryHandler, false);
importHttpClient.DefaultRequestHeaders.Add("User-Agent", "Microsoft.CopilotChat");
await planner.Kernel.ImportChatGptPluginSkillFromUrlAsync("KlarnaShoppingSkill", new Uri("https://www.klarna.com/.well-known/ai-plugin.json"), importHttpClient);
await planner.Kernel.ImportChatGptPluginSkillFromUrlAsync("KlarnaShoppingSkill", new Uri("https://www.klarna.com/.well-known/ai-plugin.json"),
importHttpClient);

//
// Register authenticated skills with the planner's kernel only if the request includes an auth header for the skill.
Expand All @@ -162,7 +165,7 @@ private async Task RegisterPlannerSkillsAsync(CopilotChatPlanner planner, Planne
BearerAuthenticationProvider authenticationProvider = new(() => Task.FromResult(openApiSkillsAuthHeaders.GithubAuthentication));
await planner.Kernel.ImportOpenApiSkillFromFileAsync(
skillName: "GitHubSkill",
filePath: Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"Skills/OpenApiSkills/GitHubSkill/openapi.json"),
filePath: Path.Combine(Directory.GetCurrentDirectory(), @"Skills/OpenApiSkills/GitHubSkill/openapi.json"),
authCallback: authenticationProvider.AuthenticateRequestAsync);
}

Expand Down Expand Up @@ -211,7 +214,7 @@ protected virtual void Dispose(bool disposing)
}
}

// <inheritdoc />
/// <inheritdoc />
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static async Task RunAsync()
return Task.FromResult(s);
});


using HttpClient httpClient = new HttpClient();

// The bool useLocalFile can be used to toggle the ingestion method for the openapi schema between a file path and a URL
Expand Down

0 comments on commit a478fdb

Please sign in to comment.