Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,4 @@ healthchecksdb
/OpenAITests/appsettings.json
/Tests.OpenAI/appsettings.json
/Tests.OpenAI/Output
/Tests.OpenAI/appsettings.json
29 changes: 27 additions & 2 deletions Apps.OpenAI/Actions/Base/BaseActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,36 @@ protected async Task<string> 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<MemoryStream> 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<XliffDocument> DownloadXliffDocumentAsync(FileReference file)
{
var fileStream = await FileManagementClient.DownloadAsync(file);
Expand Down
4 changes: 2 additions & 2 deletions Apps.OpenAI/Apps.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<TargetFramework>net8.0</TargetFramework>
<Product>OpenAI</Product>
<Description>Creating safe artificial general intelligence that benefits all of humanity</Description>
<Version>2.8.14</Version>
<Version>2.8.15</Version>
<AssemblyName>Apps.OpenAI</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blackbird.Applications.SDK.Blueprints" Version="1.0.1" />
<PackageReference Include="Blackbird.Applications.SDK.Extensions.FileManagement" Version="1.1.0" />
<PackageReference Include="Blackbird.Applications.Sdk.Glossaries.Utils" Version="1.0.1" />
<PackageReference Include="Blackbird.Applications.Sdk.Glossaries.Utils" Version="1.1.1-rc.11154" />
<PackageReference Include="Blackbird.Applications.Sdk.Utils" Version="1.0.26" />
<PackageReference Include="Blackbird.Filters" Version="1.1.44" />
<PackageReference Include="Blackbird.Xliff.Utils" Version="1.1.14" />
Expand Down
10 changes: 6 additions & 4 deletions Tests.OpenAI/ConnectionValidatorTests.cs
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
2 changes: 1 addition & 1 deletion Tests.OpenAI/Tests.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion Tests.OpenAI/TranslationActionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down