Skip to content

Commit

Permalink
Add timeout constant and bring back minimum timeout value
Browse files Browse the repository at this point in the history
  • Loading branch information
dlarocque committed Dec 3, 2024
1 parent e9ae353 commit f12e7c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/vertexai/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 3 additions & 2 deletions packages/vertexai/src/requests/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f12e7c8

Please sign in to comment.