From 3ffa8c8db40c7b5e7669c35d43d4bd6099440feb Mon Sep 17 00:00:00 2001 From: manodyaSenevirathne Date: Tue, 13 Aug 2024 21:54:01 +0530 Subject: [PATCH] Refactor testChatCompletion function in tests.bal --- ballerina/tests/tests.bal | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index 8088243..0a5276a 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -33,19 +33,12 @@ function initClient() returns Client|error { groups: ["live_tests", "mock_tests"] } isolated function testChatCompletion() returns error? { - CreateChatCompletionRequest request = { model: "gpt-4o-mini", messages: [{"role": "user", "content": "This is a test message"}] }; - - do { - CreateChatCompletionResponse response = check openAIChat->/chat/completions.post(request); - - string? content = response.choices[0].message.content; - test:assertTrue(content !is (), msg = "An error occurred with response content"); - - } on fail error e { - test:assertFail(msg = "An error occurred: " + e.message()); - } + CreateChatCompletionResponse response = check openAIChat->/chat/completions.post(request); + test:assertTrue(response.choices.length() > 0, msg = "Expected at least one completion choice"); + string? content = response.choices[0].message.content; + test:assertTrue(content !is (), msg = "Expected content in the completion response"); }