Skip to content

Commit

Permalink
Fix merge conflicts in feature-openapi (microsoft#285)
Browse files Browse the repository at this point in the history
### Motivation and Context
Conflict resolutions in preparation for feature-openapi merge to main.
  • Loading branch information
adrianwyatt authored Apr 3, 2023
2 parents a5f2390 + 6b488ef commit ca42f67
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 31 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.IO;
using System.Reflection;

namespace Microsoft.SemanticKernel.Connectors.OpenAI.Tokenizers.Settings;

Expand Down Expand Up @@ -37,16 +38,46 @@ internal static string ReadEncodingTable()
/// <exception cref="FileNotFoundException">Error in case the file doesn't exist</exception>
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}'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> Min()
{
Expand Down
13 changes: 13 additions & 0 deletions dotnet/src/SemanticKernel/SemanticKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<None Remove="Connectors\OpenAI\Tokenizers\Settings\encoder.json" />
<Content Include="Connectors\OpenAI\Tokenizers\Settings\encoder.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
<None Remove="Connectors\OpenAI\Tokenizers\Settings\vocab.bpe" />
<Content Include="Connectors\OpenAI\Tokenizers\Settings\vocab.bpe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>
</Project>
17 changes: 0 additions & 17 deletions samples/apps/github-qna-webapp-react/.env

This file was deleted.

12 changes: 6 additions & 6 deletions samples/dotnet/FileCompression/FileCompressionSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public FileCompressionSkill(IFileCompressor fileCompressor, ILogger<FileCompress
[SKFunctionContextParameter(Name = Parameters.DestinationFilePath, Description = "Path of compressed file to create")]
public async Task<string?> 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);

Expand All @@ -97,11 +97,11 @@ await this._fileCompressor.CompressFileAsync(Environment.ExpandEnvironmentVariab
[SKFunctionContextParameter(Name = Parameters.DestinationFilePath, Description = "Path of compressed file to create")]
public async Task<string?> 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);

Expand All @@ -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<string?> 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);

Expand Down

0 comments on commit ca42f67

Please sign in to comment.