Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding extra tests to increase code coverage in ollamaChat and azureChat #47

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/tazureChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ function doGenerate(testCase,StringInputs)
testCase.verifyGreaterThan(strlength(response),0);
end

function doGenerateUsingSystemPrompt(testCase)
testCase.assumeTrue(isenv("AZURE_OPENAI_API_KEY"),"end-to-end test requires environment variables AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, and AZURE_OPENAI_DEPLOYMENT.");
chat = azureChat("You are a helpful assistant");
response = testCase.verifyWarningFree(@() generate(chat,"Hi"));
testCase.verifyClass(response,'string');
testCase.verifyGreaterThan(strlength(response),0);
end

function generateMultipleResponses(testCase)
chat = azureChat;
[~,~,response] = generate(chat,"What is a cat?",NumCompletions=3);
Expand Down Expand Up @@ -162,7 +170,26 @@ function canUseAPIVersions(testCase, APIVersions)
response = testCase.verifyWarningFree(@() generate(chat,"How similar is the DNA of a cat and a tiger?"));
testCase.verifyClass(response,'string');
testCase.verifyGreaterThan(strlength(response),0);
end

function endpointNotFound(testCase)
% to verify the error, we need to unset the environment variable
% AZURE_OPENAI_ENDPOINT, if given. Use a fixture to restore the
% value on leaving the test point
import matlab.unittest.fixtures.EnvironmentVariableFixture
testCase.applyFixture(EnvironmentVariableFixture("AZURE_OPENAI_ENDPOINT","dummy"));
unsetenv("AZURE_OPENAI_ENDPOINT");
testCase.verifyError(@()azureChat, "llms:endpointMustBeSpecified");
end

function deploymentNotFound(testCase)
% to verify the error, we need to unset the environment variable
% AZURE_OPENAI_DEPLOYMENT, if given. Use a fixture to restore the
% value on leaving the test point
import matlab.unittest.fixtures.EnvironmentVariableFixture
testCase.applyFixture(EnvironmentVariableFixture("AZURE_OPENAI_DEPLOYMENT","dummy"));
unsetenv("AZURE_OPENAI_DEPLOYMENT");
testCase.verifyError(@()azureChat, "llms:deploymentMustBeSpecified");
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions tests/tollamaChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ function doGenerate(testCase,StringInputs)
testCase.verifyGreaterThan(strlength(response),0);
end

function doGenerateUsingSystemPrompt(testCase)
chat = ollamaChat("mistral","You are a helpful assistant");
response = testCase.verifyWarningFree(@() generate(chat,"Hi"));
testCase.verifyClass(response,'string');
testCase.verifyGreaterThan(strlength(response),0);
end

function extremeTopK(testCase)
% setting top-k to k=1 leaves no random choice,
% so we expect to get a fixed response.
Expand Down