Skip to content

Commit f9124a1

Browse files
committed
fixed StopSequences error with GPT-4 Vision
1 parent a6ba4e4 commit f9124a1

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

+llms/+internal/callOpenAIChatAPI.m

+9
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@
146146
parameters.(dict(opt)) = nvp.(opt);
147147
end
148148
end
149+
150+
if isempty(nvp.StopSequences)
151+
parameters = rmfield(parameters,"stop");
152+
end
153+
154+
if nvp.MaxNumTokens == Inf
155+
parameters = rmfield(parameters,"max_tokens");
156+
end
157+
149158
end
150159

151160
function dict = mapNVPToParameters()

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Set up your OpenAI API key. Create a `.env` file in the project root directory w
5656
OPENAI_API_KEY=<your key>
5757
```
5858

59-
Then load your `.env` file as follows:
59+
Then load your `.env` file as follows:
6060

6161
```matlab
6262
loadenv(".env")
@@ -287,9 +287,9 @@ You can extract the arguments and write the data to a table, for example.
287287
288288
### Understand the content of an image
289289
290-
You can use gpt-4-vision-preview to experiment with image understanding.
290+
You can use gpt-4-turbo to experiment with image understanding.
291291
```matlab
292-
chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-turbo",StopSequences="stop");
292+
chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-turbo");
293293
image_path = "peppers.png";
294294
messages = openAIMessages;
295295
messages = addUserMessageWithImages(messages,"What is in the image?",image_path);

tests/topenAIChat.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function generateAcceptsMessagesAsInput(testCase)
3838
end
3939

4040
function constructMdlWithInvalidParameters(testCase)
41-
testCase.verifyError(@()openAIChat(ApiKey="this-is-not-a-real-key", ResponseFormat="json"), "llms:invalidOptionAndValueForModel");
41+
testCase.verifyError(@()openAIChat(ApiKey="this-is-not-a-real-key", ModelName="gpt-4", ResponseFormat="json"), "llms:invalidOptionAndValueForModel");
4242
end
4343

4444
function keyNotFound(testCase)

0 commit comments

Comments
 (0)