From f12e7c8d0415bb69b29d74beda66ab82986e0e6b Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 3 Dec 2024 15:28:12 -0500 Subject: [PATCH] Add timeout constant and bring back minimum timeout value --- packages/vertexai/src/constants.ts | 2 ++ packages/vertexai/src/requests/request.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/vertexai/src/constants.ts b/packages/vertexai/src/constants.ts index 3ff894f354b..357e6c4e77c 100644 --- a/packages/vertexai/src/constants.ts +++ b/packages/vertexai/src/constants.ts @@ -28,3 +28,5 @@ export const DEFAULT_API_VERSION = 'v1beta'; export const PACKAGE_VERSION = version; export const LANGUAGE_TAG = 'gl-js'; + +export const DEFAULT_FETCH_TIMEOUT_MS = 180 * 1000; diff --git a/packages/vertexai/src/requests/request.ts b/packages/vertexai/src/requests/request.ts index 98c3d7273dd..28b7a2d64b4 100644 --- a/packages/vertexai/src/requests/request.ts +++ b/packages/vertexai/src/requests/request.ts @@ -21,6 +21,7 @@ import { ApiSettings } from '../types/internal'; import { DEFAULT_API_VERSION, DEFAULT_BASE_URL, + DEFAULT_FETCH_TIMEOUT_MS, LANGUAGE_TAG, PACKAGE_VERSION } from '../constants'; @@ -145,9 +146,9 @@ export async function makeRequest( ); // Timeout is 180s by default const timeoutMillis = - requestOptions?.timeout !== undefined + requestOptions?.timeout !== undefined && requestOptions.timeout >= 0 ? requestOptions.timeout - : 180 * 1000; + : DEFAULT_FETCH_TIMEOUT_MS; const abortController = new AbortController(); fetchTimeoutId = setTimeout(() => abortController.abort(), timeoutMillis); request.fetchOptions.signal = abortController.signal;