diff --git a/+llms/+internal/textGenerator.m b/+llms/+internal/textGenerator.m index f6cb167..204e516 100644 --- a/+llms/+internal/textGenerator.m +++ b/+llms/+internal/textGenerator.m @@ -28,4 +28,10 @@ properties (Access=protected) StreamFun end + + methods + function hObj = set.StopSequences(hObj,value) + hObj.StopSequences = string(value); + end + end end diff --git a/+llms/+utils/mustBeValidStop.m b/+llms/+utils/mustBeValidStop.m index f3862c7..7301a2c 100644 --- a/+llms/+utils/mustBeValidStop.m +++ b/+llms/+utils/mustBeValidStop.m @@ -5,6 +5,7 @@ function mustBeValidStop(value) if ~isempty(value) mustBeVector(value); mustBeNonzeroLengthText(value); + value = string(value); % This restriction is set by the OpenAI API if numel(value)>4 error("llms:stopSequencesMustHaveMax4Elements", llms.utils.errorMessageCatalog.getMessage("llms:stopSequencesMustHaveMax4Elements")); diff --git a/tests/topenAIChat.m b/tests/topenAIChat.m index e06db55..b156b18 100644 --- a/tests/topenAIChat.m +++ b/tests/topenAIChat.m @@ -388,7 +388,6 @@ function keyNotFound(testCase) function validConstructorInput = iGetValidConstructorInput() % while it is valid to provide the key via an environment variable, % this test set does not use that, for easier setup -validFunction = openAIFunction("funName"); validConstructorInput = struct( ... "JustKey", struct( ... "Input",{{"APIKey","this-is-not-a-real-key"}}, ... @@ -396,7 +395,7 @@ function keyNotFound(testCase) "VerifyProperties", struct( ... "Temperature", {1}, ... "TopP", {1}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0}, ... "FrequencyPenalty", {0}, ... "TimeOut", {10}, ... @@ -412,7 +411,7 @@ function keyNotFound(testCase) "VerifyProperties", struct( ... "Temperature", {1}, ... "TopP", {1}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0}, ... "FrequencyPenalty", {0}, ... "TimeOut", {10}, ... @@ -428,7 +427,7 @@ function keyNotFound(testCase) "VerifyProperties", struct( ... "Temperature", {2}, ... "TopP", {1}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0}, ... "FrequencyPenalty", {0}, ... "TimeOut", {10}, ... @@ -444,7 +443,7 @@ function keyNotFound(testCase) "VerifyProperties", struct( ... "Temperature", {1}, ... "TopP", {0.2}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0}, ... "FrequencyPenalty", {0}, ... "TimeOut", {10}, ... @@ -470,13 +469,29 @@ function keyNotFound(testCase) "ResponseFormat", {"text"} ... ) ... ), ... + "StopSequencesCharVector", struct( ... + "Input",{{"APIKey","this-is-not-a-real-key","StopSequences",'supercalifragilistic'}}, ... + "ExpectedWarning", '', ... + "VerifyProperties", struct( ... + "Temperature", {1}, ... + "TopP", {1}, ... + "StopSequences", {"supercalifragilistic"}, ... + "PresencePenalty", {0}, ... + "FrequencyPenalty", {0}, ... + "TimeOut", {10}, ... + "FunctionNames", {[]}, ... + "ModelName", {"gpt-4o-mini"}, ... + "SystemPrompt", {[]}, ... + "ResponseFormat", {"text"} ... + ) ... + ), ... "PresencePenalty", struct( ... "Input",{{"APIKey","this-is-not-a-real-key","PresencePenalty",0.1}}, ... "ExpectedWarning", '', ... "VerifyProperties", struct( ... "Temperature", {1}, ... "TopP", {1}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0.1}, ... "FrequencyPenalty", {0}, ... "TimeOut", {10}, ... @@ -492,7 +507,7 @@ function keyNotFound(testCase) "VerifyProperties", struct( ... "Temperature", {1}, ... "TopP", {1}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0}, ... "FrequencyPenalty", {0.1}, ... "TimeOut", {10}, ... @@ -508,7 +523,7 @@ function keyNotFound(testCase) "VerifyProperties", struct( ... "Temperature", {1}, ... "TopP", {1}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0}, ... "FrequencyPenalty", {0}, ... "TimeOut", {0.1}, ... @@ -524,7 +539,7 @@ function keyNotFound(testCase) "VerifyProperties", struct( ... "Temperature", {1}, ... "TopP", {1}, ... - "StopSequences", {{}}, ... + "StopSequences", {string([])}, ... "PresencePenalty", {0}, ... "FrequencyPenalty", {0}, ... "TimeOut", {10}, ...