|
114 | 114 | arguments
|
115 | 115 | systemPrompt {llms.utils.mustBeTextOrEmpty} = []
|
116 | 116 | nvp.Tools (1,:) {mustBeA(nvp.Tools, "openAIFunction")} = openAIFunction.empty
|
117 |
| - nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["gpt-4", "gpt-4-0613", "gpt-4-32k", ... |
118 |
| - "gpt-3.5-turbo", "gpt-4-1106-preview", ... |
119 |
| - "gpt-3.5-turbo-1106", "gpt-4-vision-preview", ... |
120 |
| - "gpt-4-turbo-preview"])} = "gpt-3.5-turbo" |
| 117 | + nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["gpt-4-turbo", ... |
| 118 | + "gpt-4-turbo-2024-04-09","gpt-4","gpt-4-0613", ... |
| 119 | + "gpt-3.5-turbo","gpt-3.5-turbo-0125", ... |
| 120 | + "gpt-3.5-turbo-1106"])} = "gpt-3.5-turbo" |
121 | 121 | nvp.Temperature {mustBeValidTemperature} = 1
|
122 | 122 | nvp.TopProbabilityMass {mustBeValidTopP} = 1
|
123 | 123 | nvp.StopSequences {mustBeValidStop} = {}
|
|
131 | 131 |
|
132 | 132 | if isfield(nvp,"StreamFun")
|
133 | 133 | this.StreamFun = nvp.StreamFun;
|
134 |
| - if strcmp(nvp.ModelName,'gpt-4-vision-preview') |
135 |
| - error("llms:invalidOptionForModel", ... |
136 |
| - llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "StreamFun", nvp.ModelName)); |
137 |
| - end |
138 | 134 | else
|
139 | 135 | this.StreamFun = [];
|
140 | 136 | end
|
|
146 | 142 | else
|
147 | 143 | this.Tools = nvp.Tools;
|
148 | 144 | [this.FunctionsStruct, this.FunctionNames] = functionAsStruct(nvp.Tools);
|
149 |
| - if strcmp(nvp.ModelName,'gpt-4-vision-preview') |
150 |
| - error("llms:invalidOptionForModel", ... |
151 |
| - llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "Tools", nvp.ModelName)); |
152 |
| - end |
153 | 145 | end
|
154 | 146 |
|
155 | 147 | if ~isempty(systemPrompt)
|
|
163 | 155 | this.Temperature = nvp.Temperature;
|
164 | 156 | this.TopProbabilityMass = nvp.TopProbabilityMass;
|
165 | 157 | this.StopSequences = nvp.StopSequences;
|
166 |
| - if ~isempty(nvp.StopSequences) && strcmp(nvp.ModelName,'gpt-4-vision-preview') |
167 |
| - error("llms:invalidOptionForModel", ... |
168 |
| - llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "StopSequences", nvp.ModelName)); |
169 |
| - end |
170 |
| - |
171 | 158 |
|
172 | 159 | % ResponseFormat is only supported in the latest models only
|
173 | 160 | if (nvp.ResponseFormat == "json")
|
174 |
| - if ismember(this.ModelName,["gpt-3.5-turbo-1106","gpt-4-1106-preview"]) |
175 |
| - warning("llms:warningJsonInstruction", ... |
176 |
| - llms.utils.errorMessageCatalog.getMessage("llms:warningJsonInstruction")) |
177 |
| - else |
| 161 | + if ismember(this.ModelName,["gpt-4","gpt-4-0613"]) |
178 | 162 | error("llms:invalidOptionAndValueForModel", ...
|
179 | 163 | llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionAndValueForModel", "ResponseFormat", "json", this.ModelName));
|
| 164 | + else |
| 165 | + warning("llms:warningJsonInstruction", ... |
| 166 | + llms.utils.errorMessageCatalog.getMessage("llms:warningJsonInstruction")) |
180 | 167 | end
|
181 | 168 |
|
182 | 169 | end
|
|
222 | 209 | end
|
223 | 210 |
|
224 | 211 | toolChoice = convertToolChoice(this, nvp.ToolChoice);
|
225 |
| - if ~isempty(nvp.ToolChoice) && strcmp(this.ModelName,'gpt-4-vision-preview') |
226 |
| - error("llms:invalidOptionForModel", ... |
227 |
| - llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "ToolChoice", this.ModelName)); |
228 |
| - end |
229 | 212 |
|
230 | 213 | if isstring(messages) && isscalar(messages)
|
231 | 214 | messagesStruct = {struct("role", "user", "content", messages)};
|
232 | 215 | else
|
233 | 216 | messagesStruct = messages.Messages;
|
234 | 217 | end
|
235 | 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 | + |
236 | 226 | if ~isempty(this.SystemPrompt)
|
237 | 227 | messagesStruct = horzcat(this.SystemPrompt, messagesStruct);
|
238 | 228 | end
|
|
244 | 234 | PresencePenalty=this.PresencePenalty, FrequencyPenalty=this.FrequencyPenalty, ...
|
245 | 235 | ResponseFormat=this.ResponseFormat,Seed=nvp.Seed, ...
|
246 | 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 | + |
247 | 244 | end
|
248 | 245 |
|
249 | 246 | function this = set.Temperature(this, temperature)
|
|
0 commit comments