Skip to content

Commit 5882528

Browse files
authored
Merge pull request #46 from matlab-deep-learning/Azure_APIVersion_tests
Azure api version tests
2 parents 05c861b + fbf1372 commit 5882528

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

azureChat.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@
103103
function this = azureChat(systemPrompt, nvp)
104104
arguments
105105
systemPrompt {llms.utils.mustBeTextOrEmpty} = []
106-
nvp.Endpoint {mustBeNonzeroLengthTextScalar}
107-
nvp.Deployment {mustBeNonzeroLengthTextScalar}
106+
nvp.Endpoint (1,1) string {mustBeNonzeroLengthTextScalar}
107+
nvp.Deployment (1,1) string {mustBeNonzeroLengthTextScalar}
108108
nvp.APIKey {mustBeNonzeroLengthTextScalar}
109109
nvp.Tools (1,:) {mustBeA(nvp.Tools, "openAIFunction")} = openAIFunction.empty
110-
nvp.APIVersion (1,1) {mustBeAPIVersion} = "2024-02-01"
110+
nvp.APIVersion (1,1) string {mustBeAPIVersion} = "2024-02-01"
111111
nvp.Temperature {llms.utils.mustBeValidTemperature} = 1
112112
nvp.TopP {llms.utils.mustBeValidTopP} = 1
113113
nvp.StopSequences {llms.utils.mustBeValidStop} = {}

tests/tazureChat.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
InvalidGenerateInput = iGetInvalidGenerateInput;
99
InvalidValuesSetters = iGetInvalidValuesSetters;
1010
StringInputs = struct('string',{"hi"},'char',{'hi'},'cellstr',{{'hi'}});
11+
APIVersions = iGetAPIVersions();
1112
end
1213

1314
methods(Test)
@@ -150,6 +151,19 @@ function keyNotFound(testCase)
150151
unsetenv("AZURE_OPENAI_API_KEY");
151152
testCase.verifyError(@()azureChat, "llms:keyMustBeSpecified");
152153
end
154+
155+
function canUseAPIVersions(testCase, APIVersions)
156+
% Test that we can use different APIVersion value to call
157+
% azureChat.generate
158+
159+
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.");
160+
chat = azureChat("APIVersion", APIVersions);
161+
162+
response = testCase.verifyWarningFree(@() generate(chat,"How similar is the DNA of a cat and a tiger?"));
163+
testCase.verifyClass(response,'string');
164+
testCase.verifyGreaterThan(strlength(response),0);
165+
166+
end
153167
end
154168
end
155169

@@ -446,3 +460,7 @@ function keyNotFound(testCase)
446460
"Input",{{ validMessages "ToolChoice" ["validfunction", "validfunction"] }},...
447461
"Error","MATLAB:validators:mustBeTextScalar"));
448462
end
463+
464+
function apiVersions = iGetAPIVersions()
465+
apiVersions = cellstr(llms.azure.apiVersions);
466+
end

0 commit comments

Comments
 (0)