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
2 changes: 1 addition & 1 deletion Apps.OpenAI/Apps.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Product>OpenAI</Product>
<Description>Creating safe artificial general intelligence that benefits all of humanity</Description>
<Version>2.8.8</Version>
<Version>2.8.9</Version>
<AssemblyName>Apps.OpenAI</AssemblyName>
</PropertyGroup>

Expand Down
38 changes: 37 additions & 1 deletion Apps.OpenAI/Services/ContentGlossaryService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -33,7 +35,10 @@ private class GlossaryJson
}

var glossaryStream = await fileManagementClient.DownloadAsync(glossary);
var blackbirdGlossary = await glossaryStream.ConvertFromTbx();

using var sanitizedGlossaryStream = await glossaryStream.SanitizeTbxXmlAsync();

var blackbirdGlossary = await sanitizedGlossaryStream.ConvertFromTbx();

var jsonGlossary = new GlossaryJson();
var entriesIncluded = false;
Expand Down Expand Up @@ -111,3 +116,34 @@ private bool IsEntryRelevantToSources(IEnumerable<string> terms, IEnumerable<str
Regex.IsMatch(source, $@"\b{Regex.Escape(term)}\b", RegexOptions.IgnoreCase)));
}
}

public static class TbxStreamExtensions
{
public static async Task<Stream> SanitizeTbxXmlAsync(this Stream original)
{
if (original == null)
throw new ArgumentNullException(nameof(original));

if (original.CanSeek)
original.Position = 0;

using var reader = new StreamReader(
original,
Encoding.UTF8,
detectEncodingFromByteOrderMarks: true);

var text = await reader.ReadToEndAsync();

text = text.TrimStart(
'\uFEFF',
'\u200B',
'\u0000',
'\u00A0',
' ', '\t', '\r', '\n');

var bytes = Encoding.UTF8.GetBytes(text);
var ms = new MemoryStream(bytes);
ms.Position = 0;
return ms;
}
}
2 changes: 1 addition & 1 deletion Apps.OpenAI/Services/PostEditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private async Task<BatchProcessingResult> ProcessAllBatchesAsync(
errors.AddRange(batchResult.ErrorMessages);
usages.Add(batchResult.Usage);

if (!batchResult.IsSuccess && !neverFail)
if (!neverFail && (!batchResult.IsSuccess || batchResult.ErrorMessages.Any()))
{
throw new PluginApplicationException(
$"Failed to process batch {batchCounter} (size: {batchSize}). Errors: {string.Join(", ", batchResult.ErrorMessages)}");
Expand Down
77 changes: 0 additions & 77 deletions Tests.OpenAI/Input/glossary.tbx

This file was deleted.

20 changes: 9 additions & 11 deletions Tests.OpenAI/TranslationActionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@ namespace Tests.OpenAI;
[TestClass]
public class TranslationActionsTests : TestBaseWithContext
{
[TestMethod, ContextDataSource]
[TestMethod, ContextDataSource(ConnectionTypes.OpenAi)]
public async Task Translate_html(InvocationContext context)
{
var actions = new TranslationActions(context, FileManagementClient);
var modelIdentifier = new TextChatModelIdentifier { ModelId = "gpt-5" };
var modelIdentifier = new TextChatModelIdentifier { ModelId = "gpt-5-mini" };
var translateRequest = new TranslateContentRequest
{
File = new FileReference { Name = "contentful.html" },
TargetLanguage = "nl"
};
var reasoningEffortRequest = new ReasoningEffortRequest
{
ReasoningEffort = "low"
File = new FileReference { Name = "" },
TargetLanguage = "zh-Hans-CN",
OutputFileHandling = "original"
};
string? systemMessage = null;
var glossaryRequest = new GlossaryRequest();
var reasoningEffortRequest = new ReasoningEffortRequest();
string systemMessage = "";
var glossaryRequest = new GlossaryRequest { Glossary = new FileReference { Name = "Glossary.tbx" } };

var result = await actions.TranslateContent(modelIdentifier, translateRequest, systemMessage, glossaryRequest, reasoningEffortRequest);
Assert.IsNotNull(result);
Assert.Contains("contentful", result.File.Name);
//Assert.Contains("contentful", result.File.Name);

Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
}
Expand Down