Skip to content

Commit ea8874b

Browse files
authored
Merge pull request #67 from matlab-deep-learning/allow-char-StopSequences
Allow (long) char vectors for StopSequences
2 parents ae07cd9 + 57b22e1 commit ea8874b

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

+llms/+internal/textGenerator.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@
2828
properties (Access=protected)
2929
StreamFun
3030
end
31+
32+
methods
33+
function hObj = set.StopSequences(hObj,value)
34+
hObj.StopSequences = string(value);
35+
end
36+
end
3137
end

+llms/+utils/mustBeValidStop.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function mustBeValidStop(value)
55
if ~isempty(value)
66
mustBeVector(value);
77
mustBeNonzeroLengthText(value);
8+
value = string(value);
89
% This restriction is set by the OpenAI API
910
if numel(value)>4
1011
error("llms:stopSequencesMustHaveMax4Elements", llms.utils.errorMessageCatalog.getMessage("llms:stopSequencesMustHaveMax4Elements"));

tests/topenAIChat.m

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,14 @@ function keyNotFound(testCase)
388388
function validConstructorInput = iGetValidConstructorInput()
389389
% while it is valid to provide the key via an environment variable,
390390
% this test set does not use that, for easier setup
391-
validFunction = openAIFunction("funName");
392391
validConstructorInput = struct( ...
393392
"JustKey", struct( ...
394393
"Input",{{"APIKey","this-is-not-a-real-key"}}, ...
395394
"ExpectedWarning", '', ...
396395
"VerifyProperties", struct( ...
397396
"Temperature", {1}, ...
398397
"TopP", {1}, ...
399-
"StopSequences", {{}}, ...
398+
"StopSequences", {string([])}, ...
400399
"PresencePenalty", {0}, ...
401400
"FrequencyPenalty", {0}, ...
402401
"TimeOut", {10}, ...
@@ -412,7 +411,7 @@ function keyNotFound(testCase)
412411
"VerifyProperties", struct( ...
413412
"Temperature", {1}, ...
414413
"TopP", {1}, ...
415-
"StopSequences", {{}}, ...
414+
"StopSequences", {string([])}, ...
416415
"PresencePenalty", {0}, ...
417416
"FrequencyPenalty", {0}, ...
418417
"TimeOut", {10}, ...
@@ -428,7 +427,7 @@ function keyNotFound(testCase)
428427
"VerifyProperties", struct( ...
429428
"Temperature", {2}, ...
430429
"TopP", {1}, ...
431-
"StopSequences", {{}}, ...
430+
"StopSequences", {string([])}, ...
432431
"PresencePenalty", {0}, ...
433432
"FrequencyPenalty", {0}, ...
434433
"TimeOut", {10}, ...
@@ -444,7 +443,7 @@ function keyNotFound(testCase)
444443
"VerifyProperties", struct( ...
445444
"Temperature", {1}, ...
446445
"TopP", {0.2}, ...
447-
"StopSequences", {{}}, ...
446+
"StopSequences", {string([])}, ...
448447
"PresencePenalty", {0}, ...
449448
"FrequencyPenalty", {0}, ...
450449
"TimeOut", {10}, ...
@@ -470,13 +469,29 @@ function keyNotFound(testCase)
470469
"ResponseFormat", {"text"} ...
471470
) ...
472471
), ...
472+
"StopSequencesCharVector", struct( ...
473+
"Input",{{"APIKey","this-is-not-a-real-key","StopSequences",'supercalifragilistic'}}, ...
474+
"ExpectedWarning", '', ...
475+
"VerifyProperties", struct( ...
476+
"Temperature", {1}, ...
477+
"TopP", {1}, ...
478+
"StopSequences", {"supercalifragilistic"}, ...
479+
"PresencePenalty", {0}, ...
480+
"FrequencyPenalty", {0}, ...
481+
"TimeOut", {10}, ...
482+
"FunctionNames", {[]}, ...
483+
"ModelName", {"gpt-4o-mini"}, ...
484+
"SystemPrompt", {[]}, ...
485+
"ResponseFormat", {"text"} ...
486+
) ...
487+
), ...
473488
"PresencePenalty", struct( ...
474489
"Input",{{"APIKey","this-is-not-a-real-key","PresencePenalty",0.1}}, ...
475490
"ExpectedWarning", '', ...
476491
"VerifyProperties", struct( ...
477492
"Temperature", {1}, ...
478493
"TopP", {1}, ...
479-
"StopSequences", {{}}, ...
494+
"StopSequences", {string([])}, ...
480495
"PresencePenalty", {0.1}, ...
481496
"FrequencyPenalty", {0}, ...
482497
"TimeOut", {10}, ...
@@ -492,7 +507,7 @@ function keyNotFound(testCase)
492507
"VerifyProperties", struct( ...
493508
"Temperature", {1}, ...
494509
"TopP", {1}, ...
495-
"StopSequences", {{}}, ...
510+
"StopSequences", {string([])}, ...
496511
"PresencePenalty", {0}, ...
497512
"FrequencyPenalty", {0.1}, ...
498513
"TimeOut", {10}, ...
@@ -508,7 +523,7 @@ function keyNotFound(testCase)
508523
"VerifyProperties", struct( ...
509524
"Temperature", {1}, ...
510525
"TopP", {1}, ...
511-
"StopSequences", {{}}, ...
526+
"StopSequences", {string([])}, ...
512527
"PresencePenalty", {0}, ...
513528
"FrequencyPenalty", {0}, ...
514529
"TimeOut", {0.1}, ...
@@ -524,7 +539,7 @@ function keyNotFound(testCase)
524539
"VerifyProperties", struct( ...
525540
"Temperature", {1}, ...
526541
"TopP", {1}, ...
527-
"StopSequences", {{}}, ...
542+
"StopSequences", {string([])}, ...
528543
"PresencePenalty", {0}, ...
529544
"FrequencyPenalty", {0}, ...
530545
"TimeOut", {10}, ...

0 commit comments

Comments
 (0)