Skip to content

Commit

Permalink
feat: [Many APIs] update Nodejs generator to send API versions in hea…
Browse files Browse the repository at this point in the history
…ders for GAPICs (#5350)

* feat: update Nodejs generator to send API versions in headers for GAPICs

PiperOrigin-RevId: 634109303

Source-Link: googleapis/googleapis@998ade8

Source-Link: googleapis/googleapis-gen@000ca6f
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiMDAwY2E2ZjAwODAxZjY1Yjg0N2U2MDI5Y2IwNTExMTQwNGRmMjFlYyJ9
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFuYWx5dGljcy1hZG1pbi8uT3dsQm90LnlhbWwiLCJoIjoiMDAwY2E2ZjAwODAxZjY1Yjg0N2U2MDI5Y2IwNTExMTQwNGRmMjFlYyJ9
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFuYWx5dGljcy1kYXRhLy5Pd2xCb3QueWFtbCIsImgiOiIwMDBjYTZmMDA4MDFmNjViODQ3ZTYwMjljYjA1MTExNDA0ZGYyMWVjIn0=
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFwaS1hcGlrZXlzLy5Pd2xCb3QueWFtbCIsImgiOiIwMDBjYTZmMDA4MDFmNjViODQ3ZTYwMjljYjA1MTExNDA0ZGYyMWVjIn0=
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFwaS1jbG91ZHF1b3Rhcy8uT3dsQm90LnlhbWwiLCJoIjoiMDAwY2E2ZjAwODAxZjY1Yjg0N2U2MDI5Y2IwNTExMTQwNGRmMjFlYyJ9
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFwaS1zZXJ2aWNlY29udHJvbC8uT3dsQm90LnlhbWwiLCJoIjoiMDAwY2E2ZjAwODAxZjY1Yjg0N2U2MDI5Y2IwNTExMTQwNGRmMjFlYyJ9
Copy-Tag: eyJwI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kLWFsbG95ZGIvLk93bEJvdC55YW1sIiwiaCI6IjAwMGNhNmYwMDgwMWY2NWI4NDdlNjAyOWNiMDUxMTE0MDRkZjIxZWMifQ==
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWFwaWdhdGV3YXkvLk93bEJvdC55YW1sIiwiaCI6IjAwMGNhNmYwMDgwMWY2NWI4NDdlNjAyOWNiMDUxMTE0MDRkZjIxZWMifQ==
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWFwaWdlZWNvbm5lY3QvLk93bEJvdC55YW1sIiwiaCI6IjAwMGNhNmYwMDgwMWY2NWI4NDdlNjAyOWNiMDUxMTE0MDRkZjIxZWMifQ==
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWFwaWdlZXJlZ2lzdHJ5Ly5Pd2xCb3QueWFtbCIsImgiOiIwMDBjYTZmMDA4MDFmNjViODQ3ZTYwMjljYjA1MTExNDA0ZGYyMWVjIn0=
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWFwcGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDAwY2E2ZjAwODAxZjY1Yjg0N2U2MDI5Y2IwNTExMTQwNGRmMjFlYyJ9
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWFzc2V0Ly5Pd2xCb3QueWFtbCIsImgiOiIwMDBjYTZmMDA4MDFmNjViODQ3ZTYwMjljYjA1MTExNDA0ZGYyMWVjIn0=
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWFzc3VyZWR3b3JrbG9hZHMvLk93bEJvdC55YW1sIiwiaCI6IjAwMGNhNmYwMDgwMWY2NWI4NDdlNjAyOWNiMDUxMTE0MDRkZjIxZWMifQ==

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored May 20, 2024
1 parent 181871c commit 6c03873
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class GenerativeServiceClient {
streamGenerateContent: new this._gaxModule.StreamDescriptor(
this._gaxModule.StreamType.SERVER_STREAMING,
!!opts.fallback,
/* gaxStreamingRetries: */ false
!!opts.gaxServerStreamingRetries
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class GenerativeServiceClient {
streamGenerateContent: new this._gaxModule.StreamDescriptor(
this._gaxModule.StreamType.SERVER_STREAMING,
!!opts.fallback,
/* gaxStreamingRetries: */ false
!!opts.gaxServerStreamingRetries
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,51 @@ describe('v1.GenerativeServiceClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamGenerateContent without error and gaxServerStreamingRetries enabled', async () => {
const client = new generativeserviceModule.v1.GenerativeServiceClient({
gaxServerStreamingRetries: true,
});
client.initialize();
const request = generateSampleMessage(
new protos.google.ai.generativelanguage.v1.GenerateContentRequest()
);
const defaultValue1 = getTypeDefaultValue(
'.google.ai.generativelanguage.v1.GenerateContentRequest',
['model']
);
request.model = defaultValue1;
const expectedHeaderRequestParams = `model=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.ai.generativelanguage.v1.GenerateContentResponse()
);
client.innerApiCalls.streamGenerateContent =
stubServerStreamingCall(expectedResponse);
const stream = client.streamGenerateContent(request);
const promise = new Promise((resolve, reject) => {
stream.on(
'data',
(
response: protos.google.ai.generativelanguage.v1.GenerateContentResponse
) => {
resolve(response);
}
);
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (
client.innerApiCalls.streamGenerateContent as SinonStub
).getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (
client.innerApiCalls.streamGenerateContent as SinonStub
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamGenerateContent with error', async () => {
const client = new generativeserviceModule.v1.GenerativeServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -916,6 +961,12 @@ describe('v1.GenerativeServiceClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new generativeserviceModule.v1.GenerativeServiceClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('Path templates', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,51 @@ describe('v1beta.GenerativeServiceClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamGenerateContent without error and gaxServerStreamingRetries enabled', async () => {
const client = new generativeserviceModule.v1beta.GenerativeServiceClient(
{gaxServerStreamingRetries: true}
);
client.initialize();
const request = generateSampleMessage(
new protos.google.ai.generativelanguage.v1beta.GenerateContentRequest()
);
const defaultValue1 = getTypeDefaultValue(
'.google.ai.generativelanguage.v1beta.GenerateContentRequest',
['model']
);
request.model = defaultValue1;
const expectedHeaderRequestParams = `model=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.ai.generativelanguage.v1beta.GenerateContentResponse()
);
client.innerApiCalls.streamGenerateContent =
stubServerStreamingCall(expectedResponse);
const stream = client.streamGenerateContent(request);
const promise = new Promise((resolve, reject) => {
stream.on(
'data',
(
response: protos.google.ai.generativelanguage.v1beta.GenerateContentResponse
) => {
resolve(response);
}
);
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (
client.innerApiCalls.streamGenerateContent as SinonStub
).getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (
client.innerApiCalls.streamGenerateContent as SinonStub
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamGenerateContent with error', async () => {
const client = new generativeserviceModule.v1beta.GenerativeServiceClient(
{
Expand Down Expand Up @@ -1108,6 +1153,14 @@ describe('v1beta.GenerativeServiceClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new generativeserviceModule.v1beta.GenerativeServiceClient(
{
gaxServerStreamingRetries: true,
}
);
assert(client);
});
});

describe('Path templates', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class TetherClient {
egress: new this._gaxModule.StreamDescriptor(
this._gaxModule.StreamType.BIDI_STREAMING,
!!opts.fallback,
/* gaxStreamingRetries: */ false
!!opts.gaxServerStreamingRetries
),
};

Expand Down

0 comments on commit 6c03873

Please sign in to comment.