Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('createInferenceEndpointExecutor', () => {
querystring: { timeout: '3m' },
body,
},
{ asStream: true }
{ asStream: true, requestTimeout: 180_000 }
);
});

Expand Down Expand Up @@ -118,13 +118,16 @@ describe('createInferenceEndpointExecutor', () => {
);
});

it('does not include requestTimeout when timeout is not provided', async () => {
it('uses the default requestTimeout when timeout is not provided', async () => {
const stream = new PassThrough();
mockTransportRequest.mockResolvedValue(stream);

await executor.invoke({ body: {} });

expect(mockTransportRequest).toHaveBeenCalledWith(expect.anything(), { asStream: true });
expect(mockTransportRequest).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ requestTimeout: 180_000 })
);
});

it('returns the stream from the response', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,21 @@ export const createInferenceEndpointExecutor = ({
esClient: ElasticsearchClient;
}): InferenceEndpointExecutor => {
return {
async invoke({ body, signal, timeout }): Promise<Readable> {
// timeout for the inference call performed by the endpoint
const inferenceTimeout =
typeof timeout === 'number' && Number.isFinite(timeout)
? `${Math.ceil(timeout / 60000)}m`
: '3m';

async invoke({ body, signal, timeout = 180_000 }): Promise<Readable> {
const response = await esClient.transport.request(
{
method: 'POST',
path: `/_inference/chat_completion/${encodeURIComponent(inferenceId)}/_stream`,
querystring: {
timeout: inferenceTimeout,
// timeout for the inference call performed by the endpoint
timeout: `${Math.ceil(timeout / 60000)}m`,
},
body,
},
{
asStream: true,
requestTimeout: timeout,
...(signal ? { signal } : {}),
...(typeof timeout === 'number' && Number.isFinite(timeout)
? { requestTimeout: timeout }
: {}),
}
);
return response as unknown as Readable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('InferenceConnector', () => {
{
asStream: true,
meta: true,
requestTimeout: 180_000,
headers: {
'X-Elastic-Product-Use-Case': 'security_ai_assistant',
},
Expand Down Expand Up @@ -322,6 +323,7 @@ describe('InferenceConnector', () => {
{
asStream: true,
meta: true,
requestTimeout: 180_000,
}
);
});
Expand All @@ -348,6 +350,7 @@ describe('InferenceConnector', () => {
{
asStream: true,
meta: true,
requestTimeout: 180_000,
signal,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export class InferenceConnector extends SubActionConnector<Config, Secrets> {
{
asStream: true,
meta: true,
requestTimeout: 180_000,
signal: params.signal,
...(params.telemetryMetadata?.pluginId
? {
Expand Down
Loading