Skip to content

Commit

Permalink
Update list of supported models on OpenAI
Browse files Browse the repository at this point in the history
Add o1, remove the deprecated 3.5-0613 models.
Change examples from outdated 3.5-turbo models to newer ones (picked at random).

`topenAIChat/canUseModel` needed a change because the o1 models error with `MaxNumTokens=1`, as they need a few tokens to get the multiple stages started.
  • Loading branch information
ccreutzi committed Jan 30, 2025
1 parent 11a54ea commit 098c830
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
15 changes: 9 additions & 6 deletions +llms/+openai/models.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
function models = models
%MODELS - supported OpenAI models

% Copyright 2024 The MathWorks, Inc.
% Copyright 2024-2025 The MathWorks, Inc.
models = [...
"gpt-4o","gpt-4o-2024-05-13",...
"gpt-4o","gpt-4o-2024-05-13","gpt-4o-2024-08-06","gpt-4o-2024-11-20",...
"chatgpt-4o-latest",...
"gpt-4o-mini","gpt-4o-mini-2024-07-18",...
"gpt-4-turbo","gpt-4-turbo-2024-04-09",...
"gpt-4","gpt-4-0613", ...
"gpt-4-turbo","gpt-4-turbo-2024-04-09","gpt-4-turbo-preview",...
"gpt-4","gpt-4-0125-preview","gpt-4-0613","gpt-4-1106-preview",...
"gpt-3.5-turbo","gpt-3.5-turbo-0125", ...
"gpt-3.5-turbo-1106",...
"o1-preview",...
"o1-mini",...
"gpt-3.5-turbo-16k",...
"o1-preview","o1-preview-2024-09-12",...
"o1-mini","o1-mini-2024-09-12",...
"o1","o1-2024-12-17",...
];
end
2 changes: 1 addition & 1 deletion +llms/+openai/validateResponseFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function validateResponseFormat(format,model,messages)
end

if isequal(format, "json")
if ismember(model,["gpt-4","gpt-4-0613","o1-preview","o1-mini"])
if ismember(model,["gpt-4","gpt-4-0613","o1-preview","o1-mini","o1"])
error("llms:invalidOptionAndValueForModel", ...
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionAndValueForModel", "ResponseFormat", "json", model));
elseif nargin > 2
Expand Down
2 changes: 1 addition & 1 deletion doc/OpenAI.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To start using the OpenAI APIs, you first need to obtain OpenAI API keys. You ar

Some of the current LLMs supported on OpenAI are:
- gpt-4o-mini, gpt-4o-mini-2024-07-18
- o1-preview, o1-mini
- o1, o1-mini
- gpt-3.5-turbo, gpt-3.5-turbo-1106, gpt-3.5-turbo-0125
- gpt-4o, gpt-4o-2024-05-13 (GPT-4 Omni)
- gpt-4-turbo, gpt-4-turbo-2024-04-09 (GPT-4 Turbo with Vision)
Expand Down
33 changes: 19 additions & 14 deletions examples/AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ This example contains four steps:

To run this example, you need a valid API key from a paid OpenAI™ API account.

```matlab
loadenv(".env")
addpath('../..')
```
# Extracting data from text

The customer record contains fictional information.
Expand Down Expand Up @@ -54,10 +50,10 @@ messages = messageHistory;
messages = addUserMessage(messages,"Extract data from the record: " + record);
```

Create a chat object. Specify the model to be `"gpt-3.5-turbo"`, which supports parallel function calls.
Create a chat object. Specify the model to be `"gpt-4o-mini"`, which supports parallel function calls.

```matlab
model = "gpt-3.5-turbo";
model = "gpt-4o-mini";
chat = openAIChat("You are an AI assistant designed to extract customer data.","ModelName",model,Tools=f);
```

Expand Down Expand Up @@ -105,10 +101,10 @@ f = addParameter(f,"minAge",type="integer",description="The minimum customer age
f = addParameter(f,"maxAge",type="integer",description="The maximum customer age",RequiredParameter=true);
```

Create a chat object with a latest model.
Create a chat object.

```matlab
model = "gpt-3.5-turbo";
model = "gpt-4o-mini";
chat = openAIChat("You are an AI assistant designed to search customer data.",ModelName=model,Tools=f);
```

Expand All @@ -130,7 +126,7 @@ end

```matlabTextOutput
tcalls = struct with fields:
id: 'call_JKENvUzMbNclCTI8GTBmY7YT'
id: 'call_t4ECuPMLP5mCuRCDG8ZnyjDY'
type: 'function'
function: [1x1 struct]
Expand Down Expand Up @@ -161,10 +157,19 @@ end

```matlabTextOutput
txt =
"The customers who are under 30 and older than 27 are:
1. Jane Smith (age 28)
2. Alex Lee (age 29)
3. Liam Tanaka (age 28)"
"Here are the customers who are under 30 and older than 27:
1. **Jane Smith**
- Age: 28
- Email: [email protected]
2. **Alex Lee**
- Age: 29
- Email: [email protected]
3. **Liam Tanaka**
- Age: 28
- Email: [email protected]"
```
# Helper functions
Expand Down Expand Up @@ -214,5 +219,5 @@ function msg = processToolCalls(data, msg, toolCalls)
end
```

*Copyright 2024 The MathWorks, Inc.*
*Copyright 2024\-2025 The MathWorks, Inc.*

20 changes: 8 additions & 12 deletions examples/CreateSimpleChatBot.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ When you run this example, an interactive AI chat starts in the MATLAB® Command

To run this example, you need a valid API key from a paid OpenAI™ API account.

```matlab
loadenv(".env")
addpath('../..')
```
# Setup Model

Set the maximum allowable number of words per chat session and define the keyword that, when entered by the user, ends the chat session. This example uses the model `gpt-3.5-turbo`.
Set the maximum allowable number of words per chat session and define the keyword that, when entered by the user, ends the chat session. This example uses the model o1.

```matlab
wordLimit = 2000;
stopWord = "end";
modelName = "gpt-3.5-turbo";
modelName = "o1";
```

Create an instance of `openAIChat` to perform the chat and `messageHistory` to store the conversation history`.`
Expand Down Expand Up @@ -115,15 +111,15 @@ end

```matlabTextOutput
User: Hello, how much do you know about physics?
AI: I am knowledgeable about various topics in physics. How can I assist you today?
AI: I have broad knowledge spanning classical, relativistic, and quantum physics.
User: What is torque?
AI: Torque is a measure of the rotational force applied to an object.
AI: Torque is a measure of how a force causes rotational motion around an axis.
User: What is force?
AI: Force is a push or pull that causes an object to accelerate or change its motion.
AI: Force is an interaction that changes an object's state of motion.
User: What is motion?
AI: Motion is the change in position of an object over time in relation to a reference point.
AI: Motion is the change in an object's position over time.
User: What is time?
AI: Time is a measurable period during which an action, process, or condition exists or continues.
AI: Time is the dimension in which events occur sequentially from past to future.
User: end
AI: Closing the chat. Have a great day!
```
Expand All @@ -137,5 +133,5 @@ function numWords = countNumWords(text)
end
```

*Copyright 2023\-2024 The MathWorks, Inc.*
*Copyright 2023\-2025 The MathWorks, Inc.*

Binary file not shown.
Binary file modified examples/mlx-scripts/CreateSimpleChatBot.mlx
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function constructChatWithAllNVP(testCase)
function canUseModel(testCase,ModelName)
testCase.verifyClass(generate(...
openAIChat(ModelName=ModelName), ...
"hi",MaxNumTokens=1), ...
"hi",MaxNumTokens=42), ...
"string");
end

Expand Down

0 comments on commit 098c830

Please sign in to comment.