Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
toshiakit committed Apr 14, 2024
2 parents 2ef309d + d741c6a commit b0ad463
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
13 changes: 4 additions & 9 deletions +llms/+internal/callOpenAIChatAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,16 @@

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

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

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

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

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

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

for opt = nvpOptions.'
if isfield(nvp, opt)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ This repository contains example code to demonstrate how to connect MATLAB to th
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.

Some of the current LLMs supported are:
- gpt-3.5-turbo, gpt-3.5-turbo-1106
- gpt-4, gpt-4-1106-preview
- gpt-4-vision-preview (a.k.a. GPT-4 Turbo with Vision)
- gpt-3.5-turbo, gpt-3.5-turbo-1106, gpt-3.5-turbo-0125
- gpt-4-turbo, gpt-4-turbo-2024-04-09 (capable of Vision)
- gpt-4, gpt-4-0613
- dall-e-2, dall-e-3

For details on the specification of each model, check the official [OpenAI documentation](https://platform.openai.com/docs/models).

## Requirements
Expand Down Expand Up @@ -289,11 +289,11 @@ You can extract the arguments and write the data to a table, for example.
You can use gpt-4-vision-preview to experiment with image understanding.
```matlab
chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-vision-preview");
chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-turbo",StopSequences="stop");
image_path = "peppers.png";
messages = openAIMessages;
messages = addUserMessageWithImages(messages,"What is in the image?",image_path);
[txt,response] = generate(chat,messages);
[txt,response] = generate(chat,messages,MaxNumTokens=4096);
% Should output the description of the image
```
Expand Down
Binary file modified examples/ExampleParallelFunctionCalls.mlx
Binary file not shown.
32 changes: 11 additions & 21 deletions openAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,17 @@
arguments
systemPrompt {llms.utils.mustBeTextOrEmpty} = []
nvp.Tools (1,:) {mustBeA(nvp.Tools, "openAIFunction")} = openAIFunction.empty
<<<<<<< HEAD
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["gpt-4", "gpt-4-0613", "gpt-4-32k", ...
"gpt-3.5-turbo", "gpt-4-1106-preview", ...
"gpt-3.5-turbo-1106", "gpt-4-vision-preview", ...
"gpt-4-turbo-preview"])} = "gpt-3.5-turbo"
=======
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["gpt-4-turbo", ...
"gpt-4-turbo-2024-04-09","gpt-4","gpt-4-0613", ...
"gpt-3.5-turbo","gpt-3.5-turbo-0125", ...
"gpt-3.5-turbo-1106"])} = "gpt-3.5-turbo"
>>>>>>> dev-update-040924models
nvp.Temperature {mustBeValidTemperature} = 1
nvp.TopProbabilityMass {mustBeValidTopP} = 1
nvp.StopSequences {mustBeValidStop} = {}
Expand All @@ -131,10 +138,6 @@

if isfield(nvp,"StreamFun")
this.StreamFun = nvp.StreamFun;
if strcmp(nvp.ModelName,'gpt-4-vision-preview')
error("llms:invalidOptionForModel", ...
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "StreamFun", nvp.ModelName));
end
else
this.StreamFun = [];
end
Expand All @@ -146,10 +149,6 @@
else
this.Tools = nvp.Tools;
[this.FunctionsStruct, this.FunctionNames] = functionAsStruct(nvp.Tools);
if strcmp(nvp.ModelName,'gpt-4-vision-preview')
error("llms:invalidOptionForModel", ...
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "Tools", nvp.ModelName));
end
end

if ~isempty(systemPrompt)
Expand All @@ -163,20 +162,15 @@
this.Temperature = nvp.Temperature;
this.TopProbabilityMass = nvp.TopProbabilityMass;
this.StopSequences = nvp.StopSequences;
if ~isempty(nvp.StopSequences) && strcmp(nvp.ModelName,'gpt-4-vision-preview')
error("llms:invalidOptionForModel", ...
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "StopSequences", nvp.ModelName));
end


% ResponseFormat is only supported in the latest models only
if (nvp.ResponseFormat == "json")
if ismember(this.ModelName,["gpt-3.5-turbo-1106","gpt-4-1106-preview"])
warning("llms:warningJsonInstruction", ...
llms.utils.errorMessageCatalog.getMessage("llms:warningJsonInstruction"))
else
if ismember(this.ModelName,["gpt-4","gpt-4-0613"])
error("llms:invalidOptionAndValueForModel", ...
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionAndValueForModel", "ResponseFormat", "json", this.ModelName));
else
warning("llms:warningJsonInstruction", ...
llms.utils.errorMessageCatalog.getMessage("llms:warningJsonInstruction"))
end

end
Expand Down Expand Up @@ -222,10 +216,6 @@
end

toolChoice = convertToolChoice(this, nvp.ToolChoice);
if ~isempty(nvp.ToolChoice) && strcmp(this.ModelName,'gpt-4-vision-preview')
error("llms:invalidOptionForModel", ...
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionForModel", "ToolChoice", this.ModelName));
end

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

0 comments on commit b0ad463

Please sign in to comment.