Skip to content

test the chatbot example, with a fake input function #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/texampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,47 @@ function testAnalyzeSentimentinTextUsingChatGPTinJSONMode(testCase)
testCase.verifyWarning(@AnalyzeSentimentinTextUsingChatGPTinJSONMode,...
"llms:warningJsonInstruction");
end

function testCreateSimpleChatBot(testCase)
% set up a fake input command, returning canned user prompts
count = 0;
prompts = [
"Hello, how much do you know about physics?"
"What is torque?"
"What is force?"
"What is motion?"
"What is time?"
"end"
"end"
"end"
];
function res = input_(varargin)
count = count + 1;
res = prompts(count);
end
input = @input_; %#ok<NASGU>

% to avoid errors about a static workspace, let MATLAB know we
% want these variables to exist
wordLimit = []; %#ok<NASGU>
stopWord = []; %#ok<NASGU>
modelName = []; %#ok<NASGU>
chat = []; %#ok<NASGU>
messages = [];
totalWords = []; %#ok<NASGU>
messagesSizes = []; %#ok<NASGU>
query = []; %#ok<NASGU>
numWordsQuery = []; %#ok<NASGU>
text = []; %#ok<NASGU>
response = []; %#ok<NASGU>
numWordsResponse = []; %#ok<NASGU>

% Run the example
CreateSimpleChatBot;

testCase.verifyEqual(count,find(prompts=="end",1));
testCase.verifySize(messages.Messages,[1 2*(count-1)]);
end
end

end
Expand Down