File tree 3 files changed +31
-1
lines changed
3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 49
49
catalog(" llms:mustBeMessagesOrTxt" ) = " Messages must be text with one or more characters or an openAIMessages objects." ;
50
50
catalog(" llms:invalidOptionAndValueForModel" ) = " '{1}' with value '{2}' is not supported for ModelName '{3}'" ;
51
51
catalog(" llms:invalidOptionForModel" ) = " {1} is not supported for ModelName '{2}'" ;
52
+ catalog(" llms:invalidContentTypeForModel" ) = " {1} is not supported for ModelName '{2}'" ;
52
53
catalog(" llms:functionNotAvailableForModel" ) = " This function is not supported for ModelName '{1}'" ;
53
54
catalog(" llms:promptLimitCharacter" ) = " Prompt must have a maximum length of {1} characters for ModelName '{2}'" ;
54
55
catalog(" llms:pngExpected" ) = " Argument must be a PNG image." ;
55
56
catalog(" 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}" ;
56
58
end
Original file line number Diff line number Diff line change 216
216
messagesStruct = messages .Messages ;
217
217
end
218
218
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
+
219
226
if ~isempty(this .SystemPrompt )
220
227
messagesStruct = horzcat(this .SystemPrompt , messagesStruct );
221
228
end
227
234
PresencePenalty= this .PresencePenalty , FrequencyPenalty= this .FrequencyPenalty , ...
228
235
ResponseFormat= this .ResponseFormat ,Seed= nvp .Seed , ...
229
236
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
+
230
244
end
231
245
232
246
function this = set .Temperature(this , temperature )
Original file line number Diff line number Diff line change @@ -100,7 +100,21 @@ function assignValueToProperty(property, value)
100
100
end
101
101
102
102
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
+
104
118
end
105
119
end
106
120
You can’t perform that action at this time.
0 commit comments