Skip to content

Commit

Permalink
Skip failed TUs
Browse files Browse the repository at this point in the history
  • Loading branch information
ce-nistal committed Aug 27, 2024
1 parent fca6665 commit 7204143
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions Apps.AzueOpenAI/Actions/XliffActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,36 +372,13 @@ private string GetSystemPrompt(bool translator)
filteredText = Regex.Match(filteredText, "\\[[\\s\\S]+(\\])").Value;
var result = JsonConvert.DeserializeObject<string[]>(filteredText);

results.AddRange(result);
results.AddRange(result);
}
catch
{
try
{
(response, promptUsage) = await ExecuteSystemPrompt(promptRequest, userPrompt, systemPrompt);

usageDto += promptUsage;
translatedText = response.Trim();


var filteredText = Regex.Match(translatedText, "\\[[\\s\\S]+(\\])").Value;
if (String.IsNullOrEmpty(filteredText))
{
var index = translatedText.LastIndexOf("\",") == -1 ? translatedText.LastIndexOf("\"\n,") : translatedText.LastIndexOf("\",");
filteredText = translatedText.Remove(index) + "\"]";
}
filteredText = Regex.Match(filteredText, "\\[[\\s\\S]+(\\])").Value;
var result = JsonConvert.DeserializeObject<string[]>(filteredText);

results.AddRange(result);
}
catch (Exception e)
catch (Exception e)
{
throw new Exception(
$"Failed to parse the translated text. Exception message: {e.Message}; Exception type: {e.GetType()}");

continue;
}
}
}

return (results.Where(z => Regex.Match(z ,"\\{ID:(.*?)\\}(.+)$").Groups[1].Value != "").ToDictionary(x => Regex.Match(x, "\\{ID:(.*?)\\}(.+)$").Groups[1].Value, y => Regex.Match(y, "\\{ID:(.*?)\\}(.+)$").Groups[2].Value), usageDto);
Expand Down

0 comments on commit 7204143

Please sign in to comment.