From 2666f5fd7023afa17c45e3cbd68790567e8378f4 Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Wed, 26 Jun 2024 16:18:46 +0100 Subject: [PATCH 1/4] Update tazureChat.m Add test for all different APIVersion values --- tests/tazureChat.m | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/tazureChat.m b/tests/tazureChat.m index 333b1c7..22e51ff 100644 --- a/tests/tazureChat.m +++ b/tests/tazureChat.m @@ -8,6 +8,7 @@ InvalidGenerateInput = iGetInvalidGenerateInput; InvalidValuesSetters = iGetInvalidValuesSetters; StringInputs = struct('string',{"hi"},'char',{'hi'},'cellstr',{{'hi'}}); + APIVersions = iGetAPIVersions(); end methods(Test) @@ -150,6 +151,19 @@ function keyNotFound(testCase) unsetenv("AZURE_OPENAI_API_KEY"); testCase.verifyError(@()azureChat, "llms:keyMustBeSpecified"); end + + function canUseAPIVersions(testCase, APIVersions) + % Test that we can use different APIVersion value to call + % azureChat.generate + + 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("APIVersion", 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 end end @@ -446,3 +460,11 @@ function keyNotFound(testCase) "Input",{{ validMessages "ToolChoice" ["validfunction", "validfunction"] }},... "Error","MATLAB:validators:mustBeTextScalar")); end + +function apiVersions = iGetAPIVersions() +apiVersions = struct("2024-05-01-preview", "2024-05-01-preview", ... + "2024-04-01-preview", "2024-04-01-preview", ... + "2024-03-01-preview", "2024-03-01-preview", ... + "2024-02-01", "2024-02-01", ... + "2023-05-15", "2023-05-15"); +end \ No newline at end of file From be06d88e5365395b76916ce2cb46be7ae0e78a8b Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Wed, 26 Jun 2024 16:35:03 +0100 Subject: [PATCH 2/4] Update tazureChat.m --- tests/tazureChat.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/tazureChat.m b/tests/tazureChat.m index 22e51ff..f1c6bc8 100644 --- a/tests/tazureChat.m +++ b/tests/tazureChat.m @@ -462,9 +462,9 @@ function canUseAPIVersions(testCase, APIVersions) end function apiVersions = iGetAPIVersions() -apiVersions = struct("2024-05-01-preview", "2024-05-01-preview", ... - "2024-04-01-preview", "2024-04-01-preview", ... - "2024-03-01-preview", "2024-03-01-preview", ... - "2024-02-01", "2024-02-01", ... - "2023-05-15", "2023-05-15"); +apiVersions = struct("Version_2024_05_01_preview", "2024-05-01-preview", ... + "Version_2024_04_01_preview", "2024-04-01-preview", ... + "Version_2024_03_01_preview", "2024-03-01-preview", ... + "Version_2024_02_01", "2024-02-01", ... + "Version_2023_05_15", "2023-05-15"); end \ No newline at end of file From 4cd9047bb67aeb3f52e54b47733d3cc37f45d05c Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Thu, 27 Jun 2024 11:32:01 +0100 Subject: [PATCH 3/4] Update tazureChat.m --- tests/tazureChat.m | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/tazureChat.m b/tests/tazureChat.m index f1c6bc8..e499bdd 100644 --- a/tests/tazureChat.m +++ b/tests/tazureChat.m @@ -157,7 +157,7 @@ function canUseAPIVersions(testCase, APIVersions) % azureChat.generate 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("APIVersion", APIVersions); + chat = azureChat("APIVersion", string(APIVersions)); response = testCase.verifyWarningFree(@() generate(chat,"How similar is the DNA of a cat and a tiger?")); testCase.verifyClass(response,'string'); @@ -462,9 +462,5 @@ function canUseAPIVersions(testCase, APIVersions) end function apiVersions = iGetAPIVersions() -apiVersions = struct("Version_2024_05_01_preview", "2024-05-01-preview", ... - "Version_2024_04_01_preview", "2024-04-01-preview", ... - "Version_2024_03_01_preview", "2024-03-01-preview", ... - "Version_2024_02_01", "2024-02-01", ... - "Version_2023_05_15", "2023-05-15"); +apiVersions = cellstr(llms.azure.apiVersions); end \ No newline at end of file From fbf137228e291232e0448b616ac369734ab907e3 Mon Sep 17 00:00:00 2001 From: Vassilis Papanastasiou Date: Thu, 27 Jun 2024 12:57:54 +0100 Subject: [PATCH 4/4] Fix azureChat issue with APIVersion, Endpoint and Deployment arguments APIVersion, Endpoint and Deployment arguments did not cast char arrays to strings. Fixed that so char arrays strings are accepted as inputs of these arguments. --- azureChat.m | 6 +++--- tests/tazureChat.m | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azureChat.m b/azureChat.m index fccf7da..27bdded 100644 --- a/azureChat.m +++ b/azureChat.m @@ -103,11 +103,11 @@ function this = azureChat(systemPrompt, nvp) arguments systemPrompt {llms.utils.mustBeTextOrEmpty} = [] - nvp.Endpoint {mustBeNonzeroLengthTextScalar} - nvp.Deployment {mustBeNonzeroLengthTextScalar} + nvp.Endpoint (1,1) string {mustBeNonzeroLengthTextScalar} + nvp.Deployment (1,1) string {mustBeNonzeroLengthTextScalar} nvp.APIKey {mustBeNonzeroLengthTextScalar} nvp.Tools (1,:) {mustBeA(nvp.Tools, "openAIFunction")} = openAIFunction.empty - nvp.APIVersion (1,1) {mustBeAPIVersion} = "2024-02-01" + nvp.APIVersion (1,1) string {mustBeAPIVersion} = "2024-02-01" nvp.Temperature {llms.utils.mustBeValidTemperature} = 1 nvp.TopP {llms.utils.mustBeValidTopP} = 1 nvp.StopSequences {llms.utils.mustBeValidStop} = {} diff --git a/tests/tazureChat.m b/tests/tazureChat.m index e499bdd..f56e04b 100644 --- a/tests/tazureChat.m +++ b/tests/tazureChat.m @@ -157,7 +157,7 @@ function canUseAPIVersions(testCase, APIVersions) % azureChat.generate 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("APIVersion", string(APIVersions)); + chat = azureChat("APIVersion", APIVersions); response = testCase.verifyWarningFree(@() generate(chat,"How similar is the DNA of a cat and a tiger?")); testCase.verifyClass(response,'string');