@@ -47,11 +47,30 @@ function doGenerate(testCase,StringInputs)
47
47
testCase .verifyGreaterThan(strlength(response ),0 );
48
48
end
49
49
50
- function doGenerateUsingSystemPrompt(testCase )
51
- chat = ollamaChat(testCase .defaultModelName ," You are a helpful assistant" );
50
+ function sendsSystemPrompt(testCase )
51
+ import matlab .unittest .constraints .HasField
52
+ [sendRequestMock ,sendRequestBehaviour ] = ...
53
+ createMock(testCase , AddedMethods= " sendRequest" );
54
+ testCase .assignOutputsWhen( ...
55
+ withAnyInputs(sendRequestBehaviour .sendRequest ),...
56
+ iResponseMessage(" Hello" )," This output is unused with Stream=false" );
57
+
58
+ chat = testCase .constructor(" You are a helpful assistant" );
59
+ chat.sendRequestFcn = @(varargin ) sendRequestMock .sendRequest(varargin{: });
60
+
52
61
response = testCase .verifyWarningFree(@() generate(chat ," Hi" ));
53
- testCase .verifyClass(response ,' string' );
54
- testCase .verifyGreaterThan(strlength(response ),0 );
62
+
63
+ calls = testCase .getMockHistory(sendRequestMock );
64
+
65
+ testCase .verifySize(calls ,[1 ,1 ]);
66
+ sentHistory = calls.Inputs{2 };
67
+ testCase .verifyThat(sentHistory ,HasField(" messages" ));
68
+ testCase .verifyEqual(sentHistory .messages , ...
69
+ { ...
70
+ struct(role = " system" ,content= " You are a helpful assistant" ),...
71
+ struct(role = " user" ,content= " Hi" ) ...
72
+ });
73
+ testCase .verifyEqual(response ," Hello" );
55
74
end
56
75
57
76
function generateOverridesProperties(testCase )
@@ -513,3 +532,13 @@ function queryModels(testCase)
513
532
" Input" ,{{ validMessages " MaxNumTokens" 0 }},...
514
533
" Error" ," MATLAB:validators:mustBePositive" ));
515
534
end
535
+
536
+ function msg = iResponseMessage(txt )
537
+ % minimal structure replacing the real matlab.net.http.ResponseMessage() in our mocks
538
+ msg = struct(...
539
+ StatusCode= " OK" ,...
540
+ Body= struct(...
541
+ Data= struct(...
542
+ message= struct(...
543
+ content= txt ))));
544
+ end
0 commit comments