-
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.
Trace/replay
llms.internal.sendRequest
To decouple `texampleTests.m` from availability and speed of external servers, record calls to `llms.internal.sendRequest` (on dev machine) and replay (during most test runs, including CI). See tests/recording/README.md for instructions.
- Loading branch information
Showing
28 changed files
with
3,828 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
test-utils/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 |
30 changes: 30 additions & 0 deletions
30
test-utils/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 |
Oops, something went wrong.