Skip to content

Commit 2d0ec2d

Browse files
committed
Stop warning in constructor for ResponseFormat="json"
Since we now throw an error when `ResponseFormat="json"` is used without the required `"json"` in the inputs, we can stop warning in the constructor. With the previous state, users got a warning they could not avoid, even in code doing everything correctly.
1 parent 245e4b0 commit 2d0ec2d

7 files changed

+20
-25
lines changed

+llms/+openai/validateResponseFormat.m

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ function validateResponseFormat(format,model,messages)
1818
error("llms:warningJsonInstruction", ...
1919
llms.utils.errorMessageCatalog.getMessage("llms:warningJsonInstruction"))
2020
end
21-
else
22-
warning("llms:warningJsonInstruction", ...
23-
llms.utils.errorMessageCatalog.getMessage("llms:warningJsonInstruction"))
2421
end
2522
elseif requestsStructuredOutput(format)
2623
if ~startsWith(model,"gpt-4o")

examples/AnalyzeSentimentinTextUsingChatGPTinJSONMode.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ model = "gpt-3.5-turbo";
4848
chat = openAIChat(systemPrompt, ModelName=model, ResponseFormat="json");
4949
```
5050

51-
```matlabTextOutput
52-
Warning: When using JSON mode, you must also prompt the model to produce JSON yourself via a system or user message.
53-
```
54-
5551
Concatenate the prompt and input text and generate an answer with the model.
5652

5753
```matlab
@@ -67,7 +63,7 @@ Generate a response from the message.
6763
end
6864
```
6965

70-
Extract the data from the JSON ouput.
66+
Extract the data from the JSON output.
7167

7268
```matlab
7369
T = struct2table([scores{:}]);
@@ -78,10 +74,10 @@ T = movevars(T,"text","Before","sentiment")
7874
|:--:|:--:|:--:|:--:|
7975
|1|"I can't stand homework."|'negative'|0.9500|
8076
|2|"This sucks. I'm bored."|'negative'|0.9000|
81-
|3|"I can't wait for Halloween!!!"|'positive'|0.9500|
77+
|3|"I can't wait for Halloween!!!"|'positive'|1|
8278
|4|"I am neigher for or against the idea."|'neutral'|1|
8379
|5|"My cat is adorable ❤️❤️"|'positive'|0.9500|
84-
|6|"I hate chocolate"|'negative'|0.9000|
80+
|6|"I hate chocolate"|'negative'|1|
8581

8682

8783
*Copyright 2024 The MathWorks, Inc.*
Binary file not shown.

tests/hopenAIChat.m

-8
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,6 @@ function createChatWithStreamFunc(testCase)
297297
testCase.verifyGreaterThan(numel(sf("")), 1);
298298
end
299299

300-
function warningJSONResponseFormat(testCase)
301-
chat = @() testCase.constructor("You are a useful assistant", ...
302-
APIKey="this-is-not-a-real-key", ...
303-
ResponseFormat="json");
304-
305-
testCase.verifyWarning(@()chat(), "llms:warningJsonInstruction");
306-
end
307-
308300
function errorJSONResponseFormat(testCase)
309301
testCase.verifyError( ...
310302
@() generate(testCase.structuredModel,"create some address",ResponseFormat="json"), ...

tests/tazureChat.m

+15-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ function deploymentNotFound(testCase)
171171
testCase.verifyError(@()azureChat, "llms:deploymentMustBeSpecified");
172172
end
173173

174-
% open TODOs for azureChat
175-
function warningJSONResponseFormat(testCase)
176-
testCase.assumeFail("TODO for azureChat");
177-
end
178174
end
179175
end
180176

@@ -194,6 +190,21 @@ function warningJSONResponseFormat(testCase)
194190
"SystemPrompt", {[]}, ...
195191
"ResponseFormat", {"text"} ...
196192
) ...
193+
),...
194+
"SomeSettings", struct( ...
195+
"Input",{{"Temperature",1.23,"TopP",0.6,"TimeOut",120,"ResponseFormat","json"}}, ...
196+
"ExpectedWarning", '', ...
197+
"VerifyProperties", struct( ...
198+
"Temperature", {1.23}, ...
199+
"TopP", {0.6}, ...
200+
"StopSequences", {string([])}, ...
201+
"PresencePenalty", {0}, ...
202+
"FrequencyPenalty", {0}, ...
203+
"TimeOut", {120}, ...
204+
"FunctionNames", {[]}, ...
205+
"SystemPrompt", {[]}, ...
206+
"ResponseFormat", {"json"} ...
207+
) ...
197208
));
198209
end
199210

tests/texampleTests.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ function testAnalyzeScientificPapersUsingFunctionCalls(testCase)
6767

6868
function testAnalyzeSentimentinTextUsingChatGPTinJSONMode(testCase)
6969
testCase.startCapture("AnalyzeSentimentinTextUsingChatGPTinJSONMode");
70-
testCase.verifyWarning(@AnalyzeSentimentinTextUsingChatGPTinJSONMode,...
71-
"llms:warningJsonInstruction");
70+
AnalyzeSentimentinTextUsingChatGPTinJSONMode;
7271
end
7372

7473
function testAnalyzeTextDataUsingParallelFunctionCallwithChatGPT(testCase)

tests/topenAIChat.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ function specialErrorForUnsupportedResponseFormat(testCase)
340340
), ...
341341
"ResponseFormat", struct( ...
342342
"Input",{{"APIKey","this-is-not-a-real-key","ResponseFormat","json"}}, ...
343-
"ExpectedWarning", "llms:warningJsonInstruction", ...
343+
"ExpectedWarning", '', ...
344344
"VerifyProperties", struct( ...
345345
"Temperature", {1}, ...
346346
"TopP", {1}, ...

0 commit comments

Comments
 (0)