Skip to content

Commit

Permalink
Use GPT-4 Turbo in tests
Browse files Browse the repository at this point in the history
The ChatGptTranslatorServiceTests were refactored to initialize the OpenAiClient at variable declaration and specify a model type when invoking translation methods. The constructor was removed as the client is now initialized at declaration. A model constant was added and it's used in all translation method calls to leverage Gpt4Turbo model for translations, which provides more efficient and accurate results.
  • Loading branch information
rodion-m committed Nov 8, 2023
1 parent c83365a commit bfc518c
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ namespace OpenAI.ChatGpt.IntegrationTests;

public class ChatGptTranslatorServiceTests
{
private readonly IOpenAiClient _client;
private readonly IOpenAiClient _client = new OpenAiClient(Helpers.GetOpenAiKey());

private const string GtpModel = ChatCompletionModels.Gpt4Turbo;

public ChatGptTranslatorServiceTests()
{
_client = new OpenAiClient(Helpers.GetOpenAiKey());
}

[Fact]
public async Task Translate_from_English_to_Russian()
{
Expand All @@ -19,7 +16,8 @@ public async Task Translate_from_English_to_Russian()
var targetLanguage = "Russian";
var textToTranslate = "Hello, world!";
// Act
var translatedText = await _client.TranslateText(textToTranslate, sourceLanguage, targetLanguage);
var translatedText = await _client.TranslateText(
textToTranslate, sourceLanguage, targetLanguage, model: GtpModel);

// Assert
translatedText.Should().NotBeNullOrEmpty();
Expand Down Expand Up @@ -56,7 +54,8 @@ public async Task Translate_object_from_English_to_Russian()
};

// Act
var translatedObject = await _client.TranslateObject(objectToTranslate, sourceLanguage, targetLanguage);
var translatedObject = await _client.TranslateObject(
objectToTranslate, sourceLanguage, targetLanguage, model: GtpModel);

// Assert
translatedObject.Should().NotBeNull();
Expand Down Expand Up @@ -93,7 +92,7 @@ public async void Batch_translate()

var translationService = new ChatGPTTranslatorService(_client);
var service = new EconomicalChatGPTTranslatorService(
translationService, "English", "Russian", maxTokensPerRequest: 50);
translationService, "English", "Russian", maxTokensPerRequest: 50, model: GtpModel);

var tasks = words.Select(async word =>
{
Expand Down

0 comments on commit bfc518c

Please sign in to comment.