-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test doubles to record & replay server interactions in example tests
- Loading branch information
Showing
26 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function [response, streamedText] = sendRequestWrapper(varargin) | ||
% This function is undocumented and will change in a future release | ||
|
||
% A wrapper around sendRequest to have a test seam | ||
[response, streamedText] = llms.internal.sendRequest(varargin{:}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.env | ||
*.asv | ||
*.mat | ||
!tests/recordings/*.mat | ||
startup.m | ||
papers_to_read.csv | ||
data/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/recording-doubles/+llms/+internal/sendRequestWrapper.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function [response, streamedText] = sendRequestWrapper(parameters, token, varargin) | ||
% This function is undocumented and will change in a future release | ||
|
||
% A wrapper around sendRequest to have a test seam | ||
persistent seenCalls | ||
if isempty(seenCalls) | ||
seenCalls = cell(0,2); | ||
end | ||
|
||
persistent filename | ||
|
||
if nargin == 1 && isequal(parameters,"close") | ||
save(filename+".mat","seenCalls"); | ||
seenCalls = cell(0,2); | ||
return | ||
end | ||
|
||
if nargin==2 && isequal(parameters,"open") | ||
filename = token; | ||
return | ||
end | ||
|
||
streamFunCalls = {}; | ||
hasCallback = nargin >= 5 && isa(varargin{3},'function_handle'); | ||
if hasCallback | ||
streamFun = varargin{3}; | ||
end | ||
function wrappedStreamFun(varargin) | ||
streamFunCalls(end+1) = varargin; | ||
streamFun(varargin{:}); | ||
end | ||
if hasCallback | ||
varargin{3} = @wrappedStreamFun; | ||
end | ||
|
||
|
||
[response, streamedText] = llms.internal.sendRequest(parameters, token, varargin{:}); | ||
|
||
seenCalls(end+1,:) = {{parameters},{response,streamFunCalls,streamedText}}; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
function addpath(~) | ||
% ignore addpath calls in examples |
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+13.1 KB
tests/recordings/AnalyzeTextDataUsingParallelFunctionCallwithChatGPT.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+87.1 KB
tests/recordings/InformationRetrievalUsingOpenAIDocumentEmbedding.mat
Binary file not shown.
Binary file added
BIN
+17.4 KB
tests/recordings/ProcessGeneratedTextInRealTimeByUsingOllamaInStreamingMode.mat
Binary file not shown.
Binary file added
BIN
+17.1 KB
tests/recordings/ProcessGeneratedTextinRealTimebyUsingChatGPTinStreamingMode.mat
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Test Double Recordings | ||
|
||
Testing the examples typically takes a long time and tends to have false negatives relatively often, mostly due to timeout errors. | ||
|
||
The point of testing the examples is not to test that we can connect to the servers. We have other test points for that. Hence, we insert a “test double” while testing the examples that keeps recordings of previous interactions with the servers and just replays the responses. | ||
|
||
This directory contains those recordings. | ||
|
||
## Generating Recordings | ||
|
||
To generate or re-generate recordings (e.g., after changing an example, or making relevant software changes), open [`texampleTests.m`](../texampleTests.m) and in `setUpAndTearDowns`, change `capture = false;` to `capture = true;`. Then, run the test points relevant to the example(s) in question, and change `capture` back to `false`. | ||
|
Binary file added
BIN
+8.74 KB
tests/recordings/RetrievalAugmentedGenerationUsingChatGPTandMATLAB.mat
Binary file not shown.
Binary file added
BIN
+5.81 KB
tests/recordings/RetrievalAugmentedGenerationUsingOllamaAndMATLAB.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions
30
tests/replaying-doubles/+llms/+internal/sendRequestWrapper.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function [response, streamedText] = sendRequestWrapper(parameters, token, varargin) | ||
% This function is undocumented and will change in a future release | ||
|
||
% A wrapper around sendRequest to have a test seam | ||
persistent seenCalls | ||
if isempty(seenCalls) | ||
seenCalls = cell(0,2); | ||
end | ||
|
||
if nargin == 1 && isequal(parameters,"close") | ||
seenCalls = cell(0,2); | ||
return | ||
end | ||
|
||
if nargin==2 && isequal(parameters,"open") | ||
load(token+".mat","seenCalls"); | ||
return | ||
end | ||
|
||
result = seenCalls{1,2}; | ||
response = result{1}; | ||
streamFunCalls = result{2}; | ||
streamedText = result{3}; | ||
|
||
if nargin >= 5 && isa(varargin{3},'function_handle') | ||
streamFun = varargin{3}; | ||
cellfun(streamFun, streamFunCalls); | ||
end | ||
|
||
seenCalls(1,:) = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
function addpath(~) | ||
% ignore addpath calls in examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters