Skip to content

Commit d99cc21

Browse files
committed
test the chatbot example, with a fake input function
1 parent 91b1c06 commit d99cc21

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/texampleTests.m

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,47 @@ function testAnalyzeSentimentinTextUsingChatGPTinJSONMode(testCase)
6565
testCase.verifyWarning(@AnalyzeSentimentinTextUsingChatGPTinJSONMode,...
6666
"llms:warningJsonInstruction");
6767
end
68+
69+
function testCreateSimpleChatBot(testCase)
70+
% set up a fake input command, returning canned user prompts
71+
count = 0;
72+
prompts = [
73+
"Hello, how much do you know about physics?"
74+
"What is torque?"
75+
"What is force?"
76+
"What is motion?"
77+
"What is time?"
78+
"end"
79+
"end"
80+
"end"
81+
];
82+
function res = input_(varargin)
83+
count = count + 1;
84+
res = prompts(count);
85+
end
86+
input = @input_; %#ok<NASGU>
87+
88+
% to avoid errors about a static workspace, let MATLAB know we
89+
% want these variables to exist
90+
wordLimit = []; %#ok<NASGU>
91+
stopWord = []; %#ok<NASGU>
92+
modelName = []; %#ok<NASGU>
93+
chat = []; %#ok<NASGU>
94+
messages = [];
95+
totalWords = []; %#ok<NASGU>
96+
messagesSizes = []; %#ok<NASGU>
97+
query = []; %#ok<NASGU>
98+
numWordsQuery = []; %#ok<NASGU>
99+
text = []; %#ok<NASGU>
100+
response = []; %#ok<NASGU>
101+
numWordsResponse = []; %#ok<NASGU>
102+
103+
% Run the example
104+
CreateSimpleChatBot;
105+
106+
testCase.verifyEqual(count,find(prompts=="end",1));
107+
testCase.verifySize(messages.Messages,[1 2*(count-1)]);
108+
end
68109
end
69110

70111
end

0 commit comments

Comments
 (0)