Skip to content

Commit

Permalink
Merge pull request #47 from matlab-deep-learning/codeCoverageIncrease…
Browse files Browse the repository at this point in the history
…OllamaAzure

Adding extra tests to increase code coverage in ollamaChat and azureChat
  • Loading branch information
vpapanasta authored Jun 27, 2024
2 parents 5882528 + e43cb20 commit f8acb3a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit f8acb3a

Please sign in to comment.