Skip to content

Commit 3ec92e7

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: remove placeholder cache attribute of access token
PiperOrigin-RevId: 593849437
1 parent 13380ee commit 3ec92e7

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/index.ts

-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export class VertexAI_Preview {
6565
protected googleAuth: GoogleAuth = new GoogleAuth({
6666
scopes: 'https://www.googleapis.com/auth/cloud-platform',
6767
});
68-
private tokenInternalPromise?: Promise<any>;
6968

7069
/**
7170
* @constructor
@@ -90,9 +89,6 @@ export class VertexAI_Preview {
9089
* @return {Promise<any>} Promise of token
9190
*/
9291
get token(): Promise<any> {
93-
if (this.tokenInternalPromise) {
94-
return this.tokenInternalPromise;
95-
}
9692
const credential_error_message = "\nUnable to authenticate your request\
9793
\nDepending on your run time environment, you can get authentication by\
9894
\n- if in local instance or cloud shell: `!gcloud auth login`\

src/index_test.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('VertexAI', () => {
159159
project: PROJECT,
160160
location: LOCATION,
161161
});
162-
vertexai.preview['tokenInternalPromise'] = Promise.resolve(TEST_TOKEN);
162+
spyOnProperty(vertexai.preview, 'token', 'get').and.resolveTo(TEST_TOKEN);
163163
model = vertexai.preview.getGenerativeModel({model: 'gemini-pro'});
164164
});
165165

@@ -247,8 +247,7 @@ describe('VertexAI', () => {
247247
location: LOCATION,
248248
apiEndpoint: TEST_ENDPOINT_BASE_PATH,
249249
});
250-
vertexaiWithBasePath.preview['tokenInternalPromise'] =
251-
Promise.resolve(TEST_TOKEN);
250+
spyOnProperty(vertexaiWithBasePath.preview, 'token', 'get').and.resolveTo(TEST_TOKEN);
252251
model = vertexaiWithBasePath.preview.getGenerativeModel({
253252
model: 'gemini-pro',
254253
});
@@ -280,8 +279,8 @@ describe('VertexAI', () => {
280279
project: PROJECT,
281280
location: LOCATION,
282281
});
283-
vertexaiWithoutBasePath.preview['tokenInternalPromise'] =
284-
Promise.resolve(TEST_TOKEN);
282+
spyOnProperty(vertexaiWithoutBasePath.preview, 'token', 'get')
283+
.and.resolveTo(TEST_TOKEN);
285284
model = vertexaiWithoutBasePath.preview.getGenerativeModel({
286285
model: 'gemini-pro',
287286
});
@@ -461,7 +460,7 @@ describe('ChatSession', () => {
461460

462461
beforeEach(() => {
463462
vertexai = new VertexAI({project: PROJECT, location: LOCATION});
464-
vertexai.preview['tokenInternalPromise'] = Promise.resolve(TEST_TOKEN);
463+
spyOnProperty(vertexai.preview, 'token', 'get').and.resolveTo(TEST_TOKEN);
465464
model = vertexai.preview.getGenerativeModel({model: 'gemini-pro'});
466465
chatSession = model.startChat({
467466
history: TEST_USER_CHAT_MESSAGE,

0 commit comments

Comments
 (0)