Skip to content

Commit

Permalink
Allow (long) char vectors for StopSequences
Browse files Browse the repository at this point in the history
  • Loading branch information
ccreutzi committed Aug 1, 2024
1 parent ae07cd9 commit 57b22e1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
6 changes: 6 additions & 0 deletions +llms/+internal/textGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@
properties (Access=protected)
StreamFun
end

methods
function hObj = set.StopSequences(hObj,value)
hObj.StopSequences = string(value);
end
end
end
1 change: 1 addition & 0 deletions +llms/+utils/mustBeValidStop.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
33 changes: 24 additions & 9 deletions tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,14 @@ 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"}}, ...
"ExpectedWarning", '', ...
"VerifyProperties", struct( ...
"Temperature", {1}, ...
"TopP", {1}, ...
"StopSequences", {{}}, ...
"StopSequences", {string([])}, ...
"PresencePenalty", {0}, ...
"FrequencyPenalty", {0}, ...
"TimeOut", {10}, ...
Expand All @@ -412,7 +411,7 @@ function keyNotFound(testCase)
"VerifyProperties", struct( ...
"Temperature", {1}, ...
"TopP", {1}, ...
"StopSequences", {{}}, ...
"StopSequences", {string([])}, ...
"PresencePenalty", {0}, ...
"FrequencyPenalty", {0}, ...
"TimeOut", {10}, ...
Expand All @@ -428,7 +427,7 @@ function keyNotFound(testCase)
"VerifyProperties", struct( ...
"Temperature", {2}, ...
"TopP", {1}, ...
"StopSequences", {{}}, ...
"StopSequences", {string([])}, ...
"PresencePenalty", {0}, ...
"FrequencyPenalty", {0}, ...
"TimeOut", {10}, ...
Expand All @@ -444,7 +443,7 @@ function keyNotFound(testCase)
"VerifyProperties", struct( ...
"Temperature", {1}, ...
"TopP", {0.2}, ...
"StopSequences", {{}}, ...
"StopSequences", {string([])}, ...
"PresencePenalty", {0}, ...
"FrequencyPenalty", {0}, ...
"TimeOut", {10}, ...
Expand All @@ -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}, ...
Expand All @@ -492,7 +507,7 @@ function keyNotFound(testCase)
"VerifyProperties", struct( ...
"Temperature", {1}, ...
"TopP", {1}, ...
"StopSequences", {{}}, ...
"StopSequences", {string([])}, ...
"PresencePenalty", {0}, ...
"FrequencyPenalty", {0.1}, ...
"TimeOut", {10}, ...
Expand All @@ -508,7 +523,7 @@ function keyNotFound(testCase)
"VerifyProperties", struct( ...
"Temperature", {1}, ...
"TopP", {1}, ...
"StopSequences", {{}}, ...
"StopSequences", {string([])}, ...
"PresencePenalty", {0}, ...
"FrequencyPenalty", {0}, ...
"TimeOut", {0.1}, ...
Expand All @@ -524,7 +539,7 @@ function keyNotFound(testCase)
"VerifyProperties", struct( ...
"Temperature", {1}, ...
"TopP", {1}, ...
"StopSequences", {{}}, ...
"StopSequences", {string([])}, ...
"PresencePenalty", {0}, ...
"FrequencyPenalty", {0}, ...
"TimeOut", {10}, ...
Expand Down

0 comments on commit 57b22e1

Please sign in to comment.