diff --git a/.gitignore b/.gitignore index 547f5bb..cbfa393 100644 --- a/.gitignore +++ b/.gitignore @@ -360,3 +360,4 @@ healthchecksdb /OpenAITests/appsettings.json /Tests.OpenAI/appsettings.json /Tests.OpenAI/Output +/Tests.OpenAI/appsettings.json diff --git a/Apps.OpenAI/Actions/Base/BaseActions.cs b/Apps.OpenAI/Actions/Base/BaseActions.cs index 8dd868d..0d7d358 100644 --- a/Apps.OpenAI/Actions/Base/BaseActions.cs +++ b/Apps.OpenAI/Actions/Base/BaseActions.cs @@ -185,11 +185,36 @@ protected async Task GetGlossaryPromptPart(FileReference glossary, strin } var glossaryStream = await FileManagementClient.DownloadAsync(glossary); - var blackbirdGlossary = await glossaryStream.ConvertFromTbx(); + using var sanitizedStream = await ToSanitizedMemoryStreamAsync(glossaryStream); + + var blackbirdGlossary = await sanitizedStream.ConvertFromTbx(); return GetGlossaryPromptPart(blackbirdGlossary, sourceContent, filter); } - + + private static async Task ToSanitizedMemoryStreamAsync(Stream input) + { + var memoryStream = new MemoryStream(); + await input.CopyToAsync(memoryStream); + memoryStream.Position = 0; + + if (memoryStream.Length >= 3) + { + var bom = new byte[3]; + var read = await memoryStream.ReadAsync(bom, 0, 3); + if (read == 3 && bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) + { + var cleaned = new MemoryStream(); + await memoryStream.CopyToAsync(cleaned); + cleaned.Position = 0; + return cleaned; + } + memoryStream.Position = 0; + } + + return memoryStream; + } + protected async Task DownloadXliffDocumentAsync(FileReference file) { var fileStream = await FileManagementClient.DownloadAsync(file); diff --git a/Apps.OpenAI/Apps.OpenAI.csproj b/Apps.OpenAI/Apps.OpenAI.csproj index ee7c131..4fa3daf 100644 --- a/Apps.OpenAI/Apps.OpenAI.csproj +++ b/Apps.OpenAI/Apps.OpenAI.csproj @@ -4,14 +4,14 @@ net8.0 OpenAI Creating safe artificial general intelligence that benefits all of humanity - 2.8.14 + 2.8.15 Apps.OpenAI - + diff --git a/Tests.OpenAI/ConnectionValidatorTests.cs b/Tests.OpenAI/ConnectionValidatorTests.cs index ceb556c..d2143a7 100644 --- a/Tests.OpenAI/ConnectionValidatorTests.cs +++ b/Tests.OpenAI/ConnectionValidatorTests.cs @@ -1,14 +1,16 @@ -using Tests.OpenAI.Base; using Apps.OpenAI.Connections; +using Apps.OpenAI.Constants; using Blackbird.Applications.Sdk.Common.Authentication; +using Blackbird.Applications.Sdk.Common.Invocation; +using Tests.OpenAI.Base; namespace Tests.OpenAI; [TestClass] -public class ConnectionValidatorTests : TestBase +public class ConnectionValidatorTests : TestBaseWithContext { - [TestMethod] - public async Task ValidateConnection_WithCorrectCredentials_ReturnsValidResult() + [TestMethod, ContextDataSource(ConnectionTypes.OpenAi)] + public async Task ValidateConnection_WithCorrectCredentials_ReturnsValidResult(InvocationContext context) { var validator = new ConnectionValidator(); diff --git a/Tests.OpenAI/Tests.OpenAI.csproj b/Tests.OpenAI/Tests.OpenAI.csproj index b93333e..acb204a 100644 --- a/Tests.OpenAI/Tests.OpenAI.csproj +++ b/Tests.OpenAI/Tests.OpenAI.csproj @@ -23,7 +23,7 @@ - PreserveNewest + Always diff --git a/Tests.OpenAI/TranslationActionsTests.cs b/Tests.OpenAI/TranslationActionsTests.cs index 59ad93a..78c2b57 100644 --- a/Tests.OpenAI/TranslationActionsTests.cs +++ b/Tests.OpenAI/TranslationActionsTests.cs @@ -115,7 +115,9 @@ public async Task TranslateText_WithSerbianLocale_ReturnsLocalizedText(Invocatio TargetLanguage = "sr-Latn-RS" }; - var glossaryRequest = new GlossaryRequest(); + var glossaryRequest = new GlossaryRequest { + Glossary = new FileReference { Name= "Glossary for Serbian JD projects.tbx" } + }; var result = await actions.LocalizeText(modelIdentifier, localizeRequest, glossaryRequest);