Skip to content

Commit

Permalink
Refactor testChatCompletion function in tests.bal
Browse files Browse the repository at this point in the history
  • Loading branch information
manodyaSenevirathne committed Aug 13, 2024
1 parent 6ccc037 commit 3ffa8c8
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 3ffa8c8

Please sign in to comment.