-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: P3 code quality improvements across translation services #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,14 +82,13 @@ protected override async Task<TranslationResult> TranslateInternalAsync( | |
| TranslationRequest request, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var chunks = new List<string>(); | ||
| var sb = new StringBuilder(); | ||
| await foreach (var chunk in TranslateStreamAsync(request, cancellationToken)) | ||
| { | ||
| chunks.Add(chunk); | ||
| sb.Append(chunk); | ||
| } | ||
|
|
||
| var translatedText = string.Join("", chunks).Trim(); | ||
| translatedText = RemoveSurroundingQuotes(translatedText); | ||
| var translatedText = CleanupResult(sb.ToString()); | ||
|
|
||
| return new TranslationResult | ||
| { | ||
|
|
@@ -314,9 +313,9 @@ private static async IAsyncEnumerable<string> ParseDoubaoStreamAsync( | |
| }; | ||
|
|
||
| /// <summary> | ||
| /// Remove surrounding quotes from translated text if present. | ||
| /// Clean up translated text by trimming and removing surrounding quotes. | ||
| /// </summary> | ||
| private static string RemoveSurroundingQuotes(string text) | ||
| private static string CleanupResult(string text) | ||
| { | ||
| if (string.IsNullOrEmpty(text)) | ||
| return text; | ||
|
Comment on lines
+316
to
321
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a unit test that covers whitespace-only differences (e.g., a streamed result with trailing newlines/spaces and no surrounding quotes) to ensure
CleanupResult/TranslateAsyncpreserves the intended trimming behavior going forward.