From a7f76341c2565e831c2d7962842c2265d9af9614 Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Thu, 27 Jun 2024 16:49:01 +0100 Subject: [PATCH 1/4] Add test for azureChat.generate for the case when azureChat is called with a system prompt defined --- tests/tazureChat.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/tazureChat.m b/tests/tazureChat.m index f56e04b..bc26762 100644 --- a/tests/tazureChat.m +++ b/tests/tazureChat.m @@ -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); From a22bdd82f293366a144657f0bfb0a2a32cf75819 Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Thu, 27 Jun 2024 17:00:19 +0100 Subject: [PATCH 2/4] Adding test for azureChat when deployment and endpoint cannot be found/are not available --- tests/tazureChat.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/tazureChat.m b/tests/tazureChat.m index bc26762..e3087e0 100644 --- a/tests/tazureChat.m +++ b/tests/tazureChat.m @@ -170,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, "deploymentMustBeSpecified"); end end end From d7f194cb98197864a66aa151ce25f53963279d0c Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Thu, 27 Jun 2024 17:02:22 +0100 Subject: [PATCH 3/4] Update wrong errorID in new test tazureChat/deploymentNotFound --- tests/tazureChat.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tazureChat.m b/tests/tazureChat.m index e3087e0..531936f 100644 --- a/tests/tazureChat.m +++ b/tests/tazureChat.m @@ -189,7 +189,7 @@ function deploymentNotFound(testCase) import matlab.unittest.fixtures.EnvironmentVariableFixture testCase.applyFixture(EnvironmentVariableFixture("AZURE_OPENAI_DEPLOYMENT","dummy")); unsetenv("AZURE_OPENAI_DEPLOYMENT"); - testCase.verifyError(@()azureChat, "deploymentMustBeSpecified"); + testCase.verifyError(@()azureChat, "llms:deploymentMustBeSpecified"); end end end From e43cb20b770ade880b1879d36a1adbcf0e9ee42e Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Thu, 27 Jun 2024 17:11:49 +0100 Subject: [PATCH 4/4] Add test for ollamaChat.generate for the case when ollamaChat is called with the system prompt defined --- tests/tollamaChat.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/tollamaChat.m b/tests/tollamaChat.m index bdbadff..6927797 100644 --- a/tests/tollamaChat.m +++ b/tests/tollamaChat.m @@ -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.