16
16
*/
17
17
18
18
/* tslint:disable */
19
- import { GoogleAuth } from 'google-auth-library' ;
19
+ import { GoogleAuth , GoogleAuthOptions } from 'google-auth-library' ;
20
20
21
21
import {
22
22
processCountTokenResponse ,
@@ -64,7 +64,8 @@ export class VertexAI {
64
64
this . preview = new VertexAI_Preview (
65
65
init . project ,
66
66
init . location ,
67
- init . apiEndpoint
67
+ init . apiEndpoint ,
68
+ init . googleAuthOptions
68
69
) ;
69
70
}
70
71
}
@@ -73,26 +74,48 @@ export class VertexAI {
73
74
* VertexAI class internal implementation for authentication.
74
75
*/
75
76
export class VertexAI_Preview {
76
- protected googleAuth : GoogleAuth = new GoogleAuth ( {
77
- scopes : 'https://www.googleapis.com/auth/cloud-platform' ,
78
- } ) ;
77
+ protected googleAuth : GoogleAuth ;
79
78
80
79
/**
81
80
* @constructor
82
81
* @param {string } - project The Google Cloud project to use for the request
83
82
* @param {string } - location The Google Cloud project location to use for the request
84
- * @param {string } - apiEndpoint The base Vertex AI endpoint to use for the request. If
83
+ * @param {string } - [ apiEndpoint] The base Vertex AI endpoint to use for the request. If
85
84
* not provided, the default regionalized endpoint
86
85
* (i.e. us-central1-aiplatform.googleapis.com) will be used.
86
+ * @param {GoogleAuthOptions } - [googleAuthOptions] The Authentication options provided by google-auth-library.
87
+ * Complete list of authentication options is documented in the GoogleAuthOptions interface:
88
+ * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts
87
89
*/
88
90
constructor (
89
91
readonly project : string ,
90
92
readonly location : string ,
91
- readonly apiEndpoint ?: string
93
+ readonly apiEndpoint ?: string ,
94
+ readonly googleAuthOptions ?: GoogleAuthOptions
92
95
) {
96
+ let opts : GoogleAuthOptions ;
97
+ if ( ! googleAuthOptions ) {
98
+ opts = {
99
+ scopes : 'https://www.googleapis.com/auth/cloud-platform' ,
100
+ } ;
101
+ } else {
102
+ if (
103
+ googleAuthOptions . projectId &&
104
+ googleAuthOptions . projectId !== project
105
+ ) {
106
+ throw new Error (
107
+ `inconsistent project ID values. argument project got value ${ project } but googleAuthOptions.projectId got value ${ googleAuthOptions . projectId } `
108
+ ) ;
109
+ }
110
+ opts = googleAuthOptions ;
111
+ if ( ! opts . scopes ) {
112
+ opts . scopes = 'https://www.googleapis.com/auth/cloud-platform' ;
113
+ }
114
+ }
93
115
this . project = project ;
94
116
this . location = location ;
95
117
this . apiEndpoint = apiEndpoint ;
118
+ this . googleAuth = new GoogleAuth ( opts ) ;
96
119
}
97
120
98
121
/**
0 commit comments