-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ChatGPT translator to support economical batching
This commit involves major refactoring of the `ChatGPTTranslatorServiceEconomical.cs` file. This change replaces single translation process with a more economical batching. The primary element Buffer has been replaced by Batch and changed the usage accordingly. This optimization allows multitudes of text to be translated in one session, thus saving resources and improving performance. Additional changes include the implementation of a new interface `IChatGPTTranslatorService` for translation services and some changes to method signatures. Tests were updated to imitate a batch translation scenario to ensure the successful functionality of the updates.
- Loading branch information
Showing
4 changed files
with
166 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/modules/OpenAI.ChatGpt.Modules.Translator/IChatGPTTranslatorService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Text.Json; | ||
using OpenAI.ChatGpt.Models.ChatCompletion; | ||
|
||
namespace OpenAI.ChatGpt.Modules.Translator; | ||
|
||
public interface IChatGPTTranslatorService | ||
{ | ||
Task<string> TranslateText( | ||
string text, | ||
string? sourceLanguage = null, | ||
string? targetLanguage = null, | ||
int? maxTokens = null, | ||
string? model = null, | ||
float temperature = ChatCompletionTemperatures.Default, | ||
string? user = null, | ||
Action<ChatCompletionRequest>? requestModifier = null, | ||
Action<ChatCompletionResponse>? rawResponseGetter = null, | ||
CancellationToken cancellationToken = default); | ||
|
||
Task<TObject> TranslateObject<TObject>( | ||
TObject objectToTranslate, | ||
bool isBatch = false, | ||
string? sourceLanguage = null, | ||
string? targetLanguage = null, | ||
int? maxTokens = null, | ||
string? model = null, | ||
float temperature = ChatCompletionTemperatures.Default, | ||
string? user = null, | ||
Action<ChatCompletionRequest>? requestModifier = null, | ||
Action<ChatCompletionResponse>? rawResponseGetter = null, | ||
JsonSerializerOptions? jsonSerializerOptions = null, | ||
JsonSerializerOptions? jsonDeserializerOptions = null, | ||
CancellationToken cancellationToken = default) where TObject : class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters