Skip to content

Commit 8fb1843

Browse files
committed
Remove model name validation
Replace mustBeModel (mustBeMember against hardcoded list) with mustBeTextScalar so unknown model names are accepted while non-text inputs like numerics are still rejected. Note that we still keep the model list for tab completion and still validate we can actively use all the models in the list on OpenAI. But this change allows the use of other model names, whether new ones at OpenAI or on other servers, in conjunction with BaseURL.
1 parent e512d87 commit 8fb1843

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

‎openAIChat.m‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@
9393

9494
properties
9595
%ModelName Model name.
96-
ModelName (1,1) string {mustBeModel} = "gpt-4o-mini"
96+
ModelName = "gpt-4o-mini"
9797

9898
%Verbosity Verbosity level for the model output.
9999
Verbosity (1,1) string {mustBeVerbosity} = "auto"
100100

101101
%ReasoningEffort Reasoning effort level for reasoning models.
102102
ReasoningEffort (1,1) string {mustBeReasoningEffort} = "auto"
103103

104-
%BaseURL Service baser URL.
104+
%BaseURL Service base URL.
105105
BaseURL (1,1) string = "https://api.openai.com/v1"
106106
end
107107

@@ -115,7 +115,7 @@
115115
arguments
116116
systemPrompt {llms.utils.mustBeTextOrEmpty} = []
117117
nvp.Tools (1,:) {mustBeA(nvp.Tools, "openAIFunction")} = openAIFunction.empty
118-
nvp.ModelName (1,1) string {mustBeModel} = "gpt-4o-mini"
118+
nvp.ModelName {mustBeTextScalar} = "gpt-4o-mini"
119119
nvp.Temperature {llms.utils.mustBeValidTemperature} = 1
120120
nvp.TopP {llms.utils.mustBeValidProbability} = 1
121121
nvp.StopSequences {llms.utils.mustBeValidStop} = {}
@@ -239,7 +239,7 @@
239239
arguments
240240
this (1,1) openAIChat
241241
messages {mustBeValidMsgs}
242-
nvp.ModelName (1,1) string {mustBeModel} = this.ModelName
242+
nvp.ModelName {mustBeTextScalar} = this.ModelName
243243
nvp.Temperature {llms.utils.mustBeValidTemperature} = this.Temperature
244244
nvp.TopP {llms.utils.mustBeValidProbability} = this.TopP
245245
nvp.StopSequences {llms.utils.mustBeValidStop} = this.StopSequences
@@ -309,6 +309,11 @@
309309
text = llms.internal.reformatOutput(text,nvp.ResponseFormat);
310310
end
311311
end
312+
313+
function this = set.ModelName(this, model)
314+
mustBeTextScalar(model);
315+
this.ModelName = string(model);
316+
end
312317
end
313318

314319
methods(Access=protected)
@@ -404,10 +409,6 @@ function mustBeIntegerOrEmpty(value)
404409
end
405410
end
406411

407-
function mustBeModel(model)
408-
mustBeMember(model,llms.openai.models);
409-
end
410-
411412
function mustBeVerbosity(value)
412413
mustBeMember(value,llms.openai.verbosityValues);
413414
end

‎tests/topenAIChat.m‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ function jsonFormatWithSystemPrompt(testCase)
134134
"InvalidModelNameType", struct( ...
135135
"Property", "ModelName", ...
136136
"Value", table(1), ...
137-
"Error", "MATLAB:validation:UnableToConvert"), ...
137+
"Error", "MATLAB:validators:mustBeTextScalar"), ...
138138
...
139-
"InvalidModelNameSize", struct( ...
139+
"InvalidModelNameNumeric", struct( ...
140140
"Property", "ModelName", ...
141-
"Value", ["gpt-5-mini","gpt-5"], ...
142-
"Error", "MATLAB:validation:IncompatibleSize"), ...
141+
"Value", 0, ...
142+
"Error", "MATLAB:validators:mustBeTextScalar"), ...
143143
...
144-
"InvalidModelNameValue", struct( ...
144+
"InvalidModelNameSize", struct( ...
145145
"Property", "ModelName", ...
146-
"Value", "llama-3.2", ...
147-
"Error", "MATLAB:validators:mustBeMember"), ...
146+
"Value", ["gpt-5-mini","gpt-5"], ...
147+
"Error", "MATLAB:validators:mustBeTextScalar"), ...
148148
...
149149
"InvalidTemperatureType", struct( ...
150150
"Property", "Temperature", ...
@@ -297,6 +297,22 @@ function jsonFormatWithSystemPrompt(testCase)
297297
"ResponseFormat", {"text"} ...
298298
) ...
299299
), ...
300+
"ModelNameAsCharVector", struct( ...
301+
"Input",{{"APIKey","this-is-not-a-real-key","ModelName",'gpt-4o'}}, ...
302+
"ExpectedWarning", '', ...
303+
"VerifyProperties", struct( ...
304+
"Temperature", {1}, ...
305+
"TopP", {1}, ...
306+
"StopSequences", {string([])}, ...
307+
"PresencePenalty", {0}, ...
308+
"FrequencyPenalty", {0}, ...
309+
"TimeOut", {10}, ...
310+
"FunctionNames", {[]}, ...
311+
"ModelName", {"gpt-4o"}, ...
312+
"SystemPrompt", {[]}, ...
313+
"ResponseFormat", {"text"} ...
314+
) ...
315+
), ...
300316
"SystemPrompt", struct( ...
301317
"Input",{{"system prompt","APIKey","this-is-not-a-real-key"}}, ...
302318
"ExpectedWarning", '', ...
@@ -544,15 +560,11 @@ function jsonFormatWithSystemPrompt(testCase)
544560
...
545561
"InvalidModelNameType",struct( ...
546562
"Input",{{ "ModelName", 0 }},...
547-
"Error","MATLAB:validators:mustBeMember"),...
563+
"Error","MATLAB:validators:mustBeTextScalar"),...
548564
...
549565
"InvalidModelNameSize",struct( ...
550566
"Input",{{ "ModelName", ["gpt-4o-mini", "gpt-4o-mini"] }},...
551-
"Error","MATLAB:validation:IncompatibleSize"),...
552-
...
553-
"InvalidModelNameOption",struct( ...
554-
"Input",{{ "ModelName", "gpt" }},...
555-
"Error","MATLAB:validators:mustBeMember"),...
567+
"Error","MATLAB:validators:mustBeTextScalar"),...
556568
...
557569
"InvalidTemperatureType",struct( ...
558570
"Input",{{ "Temperature" "2" }},...

0 commit comments

Comments
 (0)