diff --git a/README.md b/README.md index 070e3a14a4bb..9abdc137ad78 100644 --- a/README.md +++ b/README.md @@ -97,12 +97,14 @@ Here is a quick example of how to use Semantic Kernel from a C# console app. ```csharp using Microsoft.SemanticKernel; +using Microsoft.SemanticKernel.KernelExtensions; +using Microsoft.SemanticKernel.Configuration; var kernel = Kernel.Builder.Build(); // For Azure Open AI details please see // https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api -kernel.Config.AddAzureOpenAITextCompletionService( +kernel.Config.AddAzureOpenAITextCompletion( "davinci-azure", // Alias used by the kernel "text-davinci-003", // Azure OpenAI *Deployment ID* "https://contoso.openai.azure.com/", // Azure OpenAI *Endpoint* diff --git a/dotnet/src/SemanticKernel/Connectors/OpenAI/OpenAIClientAbstract.cs b/dotnet/src/SemanticKernel/Connectors/OpenAI/OpenAIClientAbstract.cs index 9097208ba03f..e2ded71b868f 100644 --- a/dotnet/src/SemanticKernel/Connectors/OpenAI/OpenAIClientAbstract.cs +++ b/dotnet/src/SemanticKernel/Connectors/OpenAI/OpenAIClientAbstract.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. using System; using System.Collections.Generic; diff --git a/dotnet/src/SemanticKernel/Connectors/OpenAI/Tokenizers/Settings/EmbeddedResource.cs b/dotnet/src/SemanticKernel/Connectors/OpenAI/Tokenizers/Settings/EmbeddedResource.cs index 30d59479b6a3..a3e3b5a4de12 100644 --- a/dotnet/src/SemanticKernel/Connectors/OpenAI/Tokenizers/Settings/EmbeddedResource.cs +++ b/dotnet/src/SemanticKernel/Connectors/OpenAI/Tokenizers/Settings/EmbeddedResource.cs @@ -2,6 +2,7 @@ using System; using System.IO; +using System.Reflection; namespace Microsoft.SemanticKernel.Connectors.OpenAI.Tokenizers.Settings; @@ -37,16 +38,46 @@ internal static string ReadEncodingTable() /// Error in case the file doesn't exist private static string ReadFile(string fileName) { - // Assume the class namespace matches the directory structure to find the file - var dir = s_namespace + // Assume the class namespace matches the directory structure + var currentClassDir = s_namespace .Replace(PrefixToIgnore, "", StringComparison.OrdinalIgnoreCase) .Trim('.') .Replace('.', Path.DirectorySeparatorChar); - var file = Path.Join(dir, fileName); + // Check the execution assembly directory first + var assembly1 = Assembly.GetExecutingAssembly(); + var assembly1Dir = Path.GetDirectoryName(Path.GetFullPath(assembly1.Location)); - if (!File.Exists(file)) { throw new FileNotFoundException(file); } + // Concatenate assembly location with class namespace with file name + var filePath1 = Path.Join(assembly1Dir, currentClassDir, fileName); + if (File.Exists(filePath1)) + { + return File.ReadAllText(filePath1); + } - return File.ReadAllText(file); + // Check the current assembly, in case that's a different file on a different directory + Assembly? assembly2 = Assembly.GetAssembly(typeof(EmbeddedResource)); + if (assembly2 == null) + { + throw new FileNotFoundException($"{fileName} not found, path: '{filePath1}'"); + } + + // Path where the assembly is + var assembly2Dir = Path.GetDirectoryName(Path.GetFullPath(assembly2.Location)); + + // No need to continue if the path is the same + if (assembly2Dir == assembly1Dir) + { + throw new FileNotFoundException($"{fileName} not found, path: '{filePath1}'"); + } + + // Concatenate assembly location with class namespace with file name + var filePath2 = Path.Join(assembly2Dir, currentClassDir, fileName); + if (File.Exists(filePath2)) + { + return File.ReadAllText(filePath2); + } + + throw new FileNotFoundException($"{fileName} not found, paths: '{filePath1}', '{filePath2}'"); } } diff --git a/dotnet/src/SemanticKernel/Memory/Collections/ScoredValue.cs b/dotnet/src/SemanticKernel/Memory/Collections/ScoredValue.cs index 916a26299d3c..e86a8e9a2018 100644 --- a/dotnet/src/SemanticKernel/Memory/Collections/ScoredValue.cs +++ b/dotnet/src/SemanticKernel/Memory/Collections/ScoredValue.cs @@ -92,7 +92,6 @@ public override int GetHashCode() return left.CompareTo(right) >= 0; } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "Min value convenience method")] public static ScoredValue Min() { diff --git a/dotnet/src/SemanticKernel/SemanticKernel.csproj b/dotnet/src/SemanticKernel/SemanticKernel.csproj index a96cb89f16c8..5d5f314d3817 100644 --- a/dotnet/src/SemanticKernel/SemanticKernel.csproj +++ b/dotnet/src/SemanticKernel/SemanticKernel.csproj @@ -71,4 +71,17 @@ PreserveNewest + + + + + PreserveNewest + true + + + + PreserveNewest + true + + \ No newline at end of file diff --git a/samples/apps/github-qna-webapp-react/.env b/samples/apps/github-qna-webapp-react/.env deleted file mode 100644 index 46a6fd989d3a..000000000000 --- a/samples/apps/github-qna-webapp-react/.env +++ /dev/null @@ -1,17 +0,0 @@ -REACT_APP_FUNCTION_URI=http://localhost:7071 - -REACT_APP_OPEN_AI_EMBEDDING_KEY= -REACT_APP_OPEN_AI_EMBEDDING_MODEL= - -REACT_APP_AZURE_OPEN_AI_EMBEDDING_KEY= -REACT_APP_AZURE_OPEN_AI_EMBEDDING_MODEL= -REACT_APP_AZURE_OPEN_AI_EMBEDDING_DEPLOYMENT= -REACT_APP_AZURE_OPEN_AI_EMBEDDING_ENDPOINT= - -REACT_APP_OPEN_AI_COMPLETION_KEY= -REACT_APP_OPEN_AI_COMPLETION_MODEL= - -REACT_APP_AZURE_OPEN_AI_COMPLETION_KEY= -REACT_APP_AZURE_OPEN_AI_COMPLETION_MODEL= -REACT_APP_AZURE_OPEN_AI_COMPLETION_DEPLOYMENT= -REACT_APP_AZURE_OPEN_AI_COMPLETION_ENDPOINT= \ No newline at end of file diff --git a/samples/dotnet/FileCompression/FileCompressionSkill.cs b/samples/dotnet/FileCompression/FileCompressionSkill.cs index d4b7489dafd4..ec7ff93d74d4 100644 --- a/samples/dotnet/FileCompression/FileCompressionSkill.cs +++ b/samples/dotnet/FileCompression/FileCompressionSkill.cs @@ -67,11 +67,11 @@ public FileCompressionSkill(IFileCompressor fileCompressor, ILogger CompressFileAsync(string sourceFilePath, SKContext context) { - this._logger.LogTrace($"{nameof(CompressFileAsync)} got called"); + this._logger.LogTrace($"{nameof(this.CompressFileAsync)} got called"); if (!context.Variables.Get(Parameters.DestinationFilePath, out string destinationFilePath)) { - const string errorMessage = $"Missing context variable {Parameters.DestinationFilePath} in {nameof(CompressFileAsync)}"; + const string errorMessage = $"Missing context variable {Parameters.DestinationFilePath} in {nameof(this.CompressFileAsync)}"; this._logger.LogError(errorMessage); context.Fail(errorMessage); @@ -97,11 +97,11 @@ await this._fileCompressor.CompressFileAsync(Environment.ExpandEnvironmentVariab [SKFunctionContextParameter(Name = Parameters.DestinationFilePath, Description = "Path of compressed file to create")] public async Task CompressDirectoryAsync(string sourceDirectoryPath, SKContext context) { - this._logger.LogTrace($"{nameof(CompressDirectoryAsync)} got called"); + this._logger.LogTrace($"{nameof(this.CompressDirectoryAsync)} got called"); if (!context.Variables.Get(Parameters.DestinationFilePath, out string destinationFilePath)) { - const string errorMessage = $"Missing context variable {Parameters.DestinationFilePath} in {nameof(CompressDirectoryAsync)}"; + const string errorMessage = $"Missing context variable {Parameters.DestinationFilePath} in {nameof(this.CompressDirectoryAsync)}"; this._logger.LogError(errorMessage); context.Fail(errorMessage); @@ -127,11 +127,11 @@ await this._fileCompressor.CompressDirectoryAsync(Environment.ExpandEnvironmentV [SKFunctionContextParameter(Name = Parameters.DestinationDirectoryPath, Description = "Directory into which to extract the decompressed content")] public async Task DecompressFileAsync(string sourceFilePath, SKContext context) { - this._logger.LogTrace($"{nameof(DecompressFileAsync)} got called"); + this._logger.LogTrace($"{nameof(this.DecompressFileAsync)} got called"); if (!context.Variables.Get(Parameters.DestinationDirectoryPath, out string destinationDirectoryPath)) { - const string errorMessage = $"Missing context variable {Parameters.DestinationDirectoryPath} in {nameof(DecompressFileAsync)}"; + const string errorMessage = $"Missing context variable {Parameters.DestinationDirectoryPath} in {nameof(this.DecompressFileAsync)}"; this._logger.LogError(errorMessage); context.Fail(errorMessage);