Skip to content

Commit b0ad463

Browse files
committed
Resolve merge conflict
2 parents 2ef309d + d741c6a commit b0ad463

File tree

4 files changed

+21
-36
lines changed

4 files changed

+21
-36
lines changed

+llms/+internal/callOpenAIChatAPI.m

+4-9
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,16 @@
119119

120120
parameters.stream = ~isempty(nvp.StreamFun);
121121

122-
if ~isempty(functions) && ~strcmp(nvp.ModelName,'gpt-4-vision-preview')
122+
if ~isempty(functions)
123123
parameters.tools = functions;
124124
end
125125

126-
if ~isempty(nvp.ToolChoice) && ~strcmp(nvp.ModelName,'gpt-4-vision-preview')
126+
if ~isempty(nvp.ToolChoice)
127127
parameters.tool_choice = nvp.ToolChoice;
128128
end
129129

130-
if ismember(nvp.ModelName,["gpt-3.5-turbo-1106","gpt-4-1106-preview"])
131-
if strcmp(nvp.ResponseFormat,"json")
132-
parameters.response_format = struct('type','json_object');
133-
end
130+
if strcmp(nvp.ResponseFormat,"json")
131+
parameters.response_format = struct('type','json_object');
134132
end
135133

136134
if ~isempty(nvp.Seed)
@@ -142,9 +140,6 @@
142140
dict = mapNVPToParameters;
143141

144142
nvpOptions = keys(dict);
145-
if strcmp(nvp.ModelName,'gpt-4-vision-preview')
146-
nvpOptions(ismember(nvpOptions,"StopSequences")) = [];
147-
end
148143

149144
for opt = nvpOptions.'
150145
if isfield(nvp, opt)

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ This repository contains example code to demonstrate how to connect MATLAB to th
55
The functionality shown here serves as an interface to the ChatGPT and DALL·E APIs. To start using the OpenAI APIs, you first need to obtain OpenAI API keys. You are responsible for any fees OpenAI may charge for the use of their APIs. You should be familiar with the limitations and risks associated with using this technology, and you agree that you shall be solely responsible for full compliance with any terms that may apply to your use of the OpenAI APIs.
66

77
Some of the current LLMs supported are:
8-
- gpt-3.5-turbo, gpt-3.5-turbo-1106
9-
- gpt-4, gpt-4-1106-preview
10-
- gpt-4-vision-preview (a.k.a. GPT-4 Turbo with Vision)
8+
- gpt-3.5-turbo, gpt-3.5-turbo-1106, gpt-3.5-turbo-0125
9+
- gpt-4-turbo, gpt-4-turbo-2024-04-09 (capable of Vision)
10+
- gpt-4, gpt-4-0613
1111
- dall-e-2, dall-e-3
12-
12+
1313
For details on the specification of each model, check the official [OpenAI documentation](https://platform.openai.com/docs/models).
1414

1515
## Requirements
@@ -289,11 +289,11 @@ You can extract the arguments and write the data to a table, for example.
289289
290290
You can use gpt-4-vision-preview to experiment with image understanding.
291291
```matlab
292-
chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-vision-preview");
292+
chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-turbo",StopSequences="stop");
293293
image_path = "peppers.png";
294294
messages = openAIMessages;
295295
messages = addUserMessageWithImages(messages,"What is in the image?",image_path);
296-
[txt,response] = generate(chat,messages);
296+
[txt,response] = generate(chat,messages,MaxNumTokens=4096);
297297
% Should output the description of the image
298298
```
299299
-11 Bytes
Binary file not shown.

openAIChat.m

+11-21
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,17 @@
114114
arguments
115115
systemPrompt {llms.utils.mustBeTextOrEmpty} = []
116116
nvp.Tools (1,:) {mustBeA(nvp.Tools, "openAIFunction")} = openAIFunction.empty
117+
<<<<<<< HEAD
117118
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["gpt-4", "gpt-4-0613", "gpt-4-32k", ...
118119
"gpt-3.5-turbo", "gpt-4-1106-preview", ...
119120
"gpt-3.5-turbo-1106", "gpt-4-vision-preview", ...
120121
"gpt-4-turbo-preview"])} = "gpt-3.5-turbo"
122+
=======
123+
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["gpt-4-turbo", ...
124+
"gpt-4-turbo-2024-04-09","gpt-4","gpt-4-0613", ...
125+
"gpt-3.5-turbo","gpt-3.5-turbo-0125", ...
126+
"gpt-3.5-turbo-1106"])} = "gpt-3.5-turbo"
127+
>>>>>>> dev-update-040924models
121128
nvp.Temperature {mustBeValidTemperature} = 1
122129
nvp.TopProbabilityMass {mustBeValidTopP} = 1
123130
nvp.StopSequences {mustBeValidStop} = {}
@@ -131,10 +138,6 @@
131138

132139
if isfield(nvp,"StreamFun")
133140
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
138141
else
139142
this.StreamFun = [];
140143
end
@@ -146,10 +149,6 @@
146149
else
147150
this.Tools = nvp.Tools;
148151
[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
153152
end
154153

155154
if ~isempty(systemPrompt)
@@ -163,20 +162,15 @@
163162
this.Temperature = nvp.Temperature;
164163
this.TopProbabilityMass = nvp.TopProbabilityMass;
165164
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-
171165

172166
% ResponseFormat is only supported in the latest models only
173167
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
168+
if ismember(this.ModelName,["gpt-4","gpt-4-0613"])
178169
error("llms:invalidOptionAndValueForModel", ...
179170
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionAndValueForModel", "ResponseFormat", "json", this.ModelName));
171+
else
172+
warning("llms:warningJsonInstruction", ...
173+
llms.utils.errorMessageCatalog.getMessage("llms:warningJsonInstruction"))
180174
end
181175

182176
end
@@ -222,10 +216,6 @@
222216
end
223217

224218
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
229219

230220
if isstring(messages) && isscalar(messages)
231221
messagesStruct = {struct("role", "user", "content", messages)};

0 commit comments

Comments
 (0)