File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 4949catalog(" llms:mustBeMessagesOrTxt" ) = " Messages must be text with one or more characters or an openAIMessages objects." ;
5050catalog(" llms:invalidOptionAndValueForModel" ) = " '{1}' with value '{2}' is not supported for ModelName '{3}'" ;
5151catalog(" llms:invalidOptionForModel" ) = " {1} is not supported for ModelName '{2}'" ;
52+ catalog(" llms:invalidContentTypeForModel" ) = " {1} is not supported for ModelName '{2}'" ;
5253catalog(" llms:functionNotAvailableForModel" ) = " This function is not supported for ModelName '{1}'" ;
5354catalog(" llms:promptLimitCharacter" ) = " Prompt must have a maximum length of {1} characters for ModelName '{2}'" ;
5455catalog(" llms:pngExpected" ) = " Argument must be a PNG image." ;
5556catalog(" llms:warningJsonInstruction" ) = " When using JSON mode, you must also prompt the model to produce JSON yourself via a system or user message." ;
57+ catalog(" llms:apiReturnedError" ) = " OpenAI API Error: {1}" ;
5658end
Original file line number Diff line number Diff line change 216216 messagesStruct = messages .Messages ;
217217 end
218218
219+ if iscell(messagesStruct{end }.content) && any(cellfun(@(x ) isfield(x ," image_url" ), messagesStruct{end }.content))
220+ if ~ismember(this .ModelName ,[" gpt-4-turbo" ," gpt-4-turbo-2024-04-09" ])
221+ error(" llms:invalidContentTypeForModel" , ...
222+ llms .utils .errorMessageCatalog .getMessage(" llms:invalidContentTypeForModel" , " Image content" , this .ModelName ));
223+ end
224+ end
225+
219226 if ~isempty(this .SystemPrompt )
220227 messagesStruct = horzcat(this .SystemPrompt , messagesStruct );
221228 end
227234 PresencePenalty= this .PresencePenalty , FrequencyPenalty= this .FrequencyPenalty , ...
228235 ResponseFormat= this .ResponseFormat ,Seed= nvp .Seed , ...
229236 ApiKey= this .ApiKey ,TimeOut= this .TimeOut , StreamFun= this .StreamFun );
237+
238+ if isfield(response .Body .Data ," error" )
239+ err = response .Body .Data .error .message ;
240+ text = llms .utils .errorMessageCatalog .getMessage(" llms:apiReturnedError" ,err );
241+ message = struct(" role" ," assistant" ," content" ,text );
242+ end
243+
230244 end
231245
232246 function this = set .Temperature(this , temperature )
Original file line number Diff line number Diff line change @@ -100,7 +100,21 @@ function assignValueToProperty(property, value)
100100 end
101101
102102 testCase .verifyError(@()assignValueToProperty(InvalidValuesSetters .Property ,InvalidValuesSetters .Value ), InvalidValuesSetters .Error );
103- end
103+ end
104+
105+ function invalidGenerateInputforModel(testCase )
106+ chat = openAIChat(ApiKey = " this-is-not-a-real-key" );
107+ image_path = " peppers.png" ;
108+ emptyMessages = openAIMessages ;
109+ inValidMessages = addUserMessageWithImages(emptyMessages ," What is in the image?" ,image_path );
110+ testCase .verifyError(@()generate(chat ,inValidMessages ), " llms:invalidContentTypeForModel" )
111+ end
112+
113+ function noStopSequencesNoMaxNumTokens(testCase )
114+ chat = openAIChat(ApiKey = " this-is-not-a-real-key" );
115+ testCase .verifyWarningFree(@()generate(chat ," This is okay" ));
116+ end
117+
104118 end
105119end
106120
You can’t perform that action at this time.
0 commit comments