1- function response = sendRequest(parameters , token , endpoint , timeout )
2- % This function is undocumented and will change in a future release
3-
1+ function [response , streamedText ] = sendRequest(parameters , token , endpoint , timeout , streamFun )
42% sendRequest Sends a request to an ENDPOINT using PARAMETERS and
53% api key TOKEN. TIMEOUT is the nubmer of seconds to wait for initial
6- % server connection.
4+ % server connection. STREAMFUN is an optional callback function.
75
86% Copyright 2023 The MathWorks, Inc.
97
1210 token
1311 endpoint
1412 timeout
13+ streamFun
1514end
1615
1716% Define the headers for the API request
2423
2524% Create a HTTPOptions object;
2625httpOpts = matlab .net .http .HTTPOptions ;
27- % Set the ConnectTimeout option
2826
27+ % Set the ConnectTimeout option
2928httpOpts.ConnectTimeout = timeout ;
29+
3030% Send the request and store the response
31- response = send(request , matlab .net .URI(endpoint ),httpOpts );
31+ if isempty(streamFun )
32+ response = send(request , matlab .net .URI(endpoint ),httpOpts );
33+ streamedText = " " ;
34+ else
35+ % User defined a stream callback function
36+ consumer = llms .stream .responseStreamer(streamFun );
37+ response = send(request , matlab .net .URI(endpoint ),httpOpts ,consumer );
38+ streamedText = consumer .ResponseText ;
39+ end
3240end
0 commit comments