From d99cc21af299afde10de734d8e10a37785f371a3 Mon Sep 17 00:00:00 2001 From: Christopher Creutzig <89011131+ccreutzi@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:20:55 +0100 Subject: [PATCH] test the chatbot example, with a fake input function --- tests/texampleTests.m | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/texampleTests.m b/tests/texampleTests.m index 90b05e7..79b0420 100644 --- a/tests/texampleTests.m +++ b/tests/texampleTests.m @@ -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 + + % to avoid errors about a static workspace, let MATLAB know we + % want these variables to exist + wordLimit = []; %#ok + stopWord = []; %#ok + modelName = []; %#ok + chat = []; %#ok + messages = []; + totalWords = []; %#ok + messagesSizes = []; %#ok + query = []; %#ok + numWordsQuery = []; %#ok + text = []; %#ok + response = []; %#ok + numWordsResponse = []; %#ok + + % Run the example + CreateSimpleChatBot; + + testCase.verifyEqual(count,find(prompts=="end",1)); + testCase.verifySize(messages.Messages,[1 2*(count-1)]); + end end end