From bfc518cb50378cf23171aa835b80839beec5de5b Mon Sep 17 00:00:00 2001 From: Rodion Mostovoi Date: Wed, 8 Nov 2023 17:08:13 +0800 Subject: [PATCH] Use GPT-4 Turbo in tests 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. --- .../ChatGptTranslatorServiceTests.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/OpenAI.ChatGpt.IntegrationTests/ChatGptTranslatorServiceTests.cs b/tests/OpenAI.ChatGpt.IntegrationTests/ChatGptTranslatorServiceTests.cs index 6e8897e..57ce0fb 100644 --- a/tests/OpenAI.ChatGpt.IntegrationTests/ChatGptTranslatorServiceTests.cs +++ b/tests/OpenAI.ChatGpt.IntegrationTests/ChatGptTranslatorServiceTests.cs @@ -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() { @@ -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(); @@ -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(); @@ -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 => {