Skip to content

Commit 306e5a9

Browse files
committed
fix: adding in type:module in package.docs.json (#3624)
chore: attempt to fix linting errors chore: attempt to fix linting errors chore: attempt to lint functionCallingStreamChat chore: lint functionCallingStreamContent chore: lint functionCallingStreamContent chore: lint functionCallingStreamContent chore: lint functionCallingStreamContent chore: lint functionCallingStreamContent
1 parent 5cac544 commit 306e5a9

File tree

3 files changed

+68
-56
lines changed

3 files changed

+68
-56
lines changed

generative-ai/snippets/functionCallingStreamChat.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
// [START aiplatform_gemini_function_calling_chat]
1616
const {
17-
VertexAI,
18-
FunctionDeclarationSchemaType
17+
VertexAI,
18+
FunctionDeclarationSchemaType,
1919
} = require('@google-cloud/vertexai');
2020

2121
const functionDeclarations = [
@@ -27,7 +27,7 @@ const functionDeclarations = [
2727
parameters: {
2828
type: FunctionDeclarationSchemaType.OBJECT,
2929
properties: {
30-
location: { type: FunctionDeclarationSchemaType.STRING },
30+
location: {type: FunctionDeclarationSchemaType.STRING},
3131
unit: {
3232
type: FunctionDeclarationSchemaType.STRING,
3333
enum: ['celsius', 'fahrenheit'],
@@ -44,8 +44,7 @@ const functionResponseParts = [
4444
{
4545
functionResponse: {
4646
name: 'get_current_weather',
47-
response:
48-
{ name: 'get_current_weather', content: { weather: 'super nice' } },
47+
response: {name: 'get_current_weather', content: {weather: 'super nice'}},
4948
},
5049
},
5150
];
@@ -59,7 +58,7 @@ async function functionCallingStreamChat(
5958
model = 'gemini-pro'
6059
) {
6160
// Initialize Vertex with your Cloud project and location
62-
const vertexAI = new VertexAI({ project: projectId, location: location });
61+
const vertexAI = new VertexAI({project: projectId, location: location});
6362

6463
// Instantiate the model
6564
const generativeModel = vertexAI.preview.getGenerativeModel({
@@ -78,7 +77,7 @@ async function functionCallingStreamChat(
7877
for await (const item of result1.stream) {
7978
console.log(item.candidates[0]);
8079
}
81-
const response1 = await result1.response;
80+
await result1.response;
8281

8382
// Send a follow up message with a FunctionResponse
8483
const result2 = await chat.sendMessageStream(functionResponseParts);

generative-ai/snippets/functionCallingStreamContent.js

+61-49
Original file line numberDiff line numberDiff line change
@@ -13,73 +13,85 @@
1313
// limitations under the License.
1414

1515
// [START aiplatform_gemini_function_calling_content]
16-
const { VertexAI, FunctionDeclarationSchemaType } = require('@google-cloud/vertexai');
16+
const {
17+
VertexAI,
18+
FunctionDeclarationSchemaType,
19+
} = require('@google-cloud/vertexai');
1720

1821
const functionDeclarations = [
19-
{
20-
function_declarations: [
21-
{
22-
name: 'get_current_weather',
23-
description: 'get weather in a given location',
24-
parameters: {
25-
type: FunctionDeclarationSchemaType.OBJECT,
26-
properties: {
27-
location: {type: FunctionDeclarationSchemaType.STRING},
28-
unit: {
29-
type: FunctionDeclarationSchemaType.STRING,
30-
enum: ['celsius', 'fahrenheit'],
31-
},
22+
{
23+
function_declarations: [
24+
{
25+
name: 'get_current_weather',
26+
description: 'get weather in a given location',
27+
parameters: {
28+
type: FunctionDeclarationSchemaType.OBJECT,
29+
properties: {
30+
location: {type: FunctionDeclarationSchemaType.STRING},
31+
unit: {
32+
type: FunctionDeclarationSchemaType.STRING,
33+
enum: ['celsius', 'fahrenheit'],
3234
},
33-
required: ['location'],
3435
},
36+
required: ['location'],
3537
},
36-
],
37-
},
38-
];
39-
40-
const functionResponseParts = [
41-
{
42-
functionResponse: {
43-
name: 'get_current_weather',
44-
response:
45-
{name: 'get_current_weather', content: {weather: 'super nice'}},
4638
},
39+
],
40+
},
41+
];
42+
43+
const functionResponseParts = [
44+
{
45+
functionResponse: {
46+
name: 'get_current_weather',
47+
response: {name: 'get_current_weather', content: {weather: 'super nice'}},
4748
},
48-
];
49+
},
50+
];
4951

5052
/**
5153
* TODO(developer): Update these variables before running the sample.
5254
*/
5355
async function functionCallingStreamChat(
54-
projectId = 'PROJECT_ID',
55-
location = 'us-central1',
56-
model = 'gemini-pro'
56+
projectId = 'PROJECT_ID',
57+
location = 'us-central1',
58+
model = 'gemini-pro'
5759
) {
58-
// Initialize Vertex with your Cloud project and location
59-
const vertexAI = new VertexAI({ project: projectId, location: location });
60+
// Initialize Vertex with your Cloud project and location
61+
const vertexAI = new VertexAI({project: projectId, location: location});
6062

61-
// Instantiate the model
62-
const generativeModel = vertexAI.preview.getGenerativeModel({
63-
model: model,
64-
});
63+
// Instantiate the model
64+
const generativeModel = vertexAI.preview.getGenerativeModel({
65+
model: model,
66+
});
6567

66-
const request = {
67-
contents: [
68-
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
69-
{role: 'model', parts: [{functionCall: {name: 'get_current_weather', args: {'location': 'Boston'}}}]},
70-
{role: 'function', parts: functionResponseParts}
68+
const request = {
69+
contents: [
70+
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
71+
{
72+
role: 'model',
73+
parts: [
74+
{
75+
functionCall: {
76+
name: 'get_current_weather',
77+
args: {'location': 'Boston'},
78+
},
79+
}
7180
],
72-
tools: functionDeclarations,
73-
};
74-
const streamingResp =
75-
await generativeModel.generateContentStream(request);
76-
for await (const item of streamingResp.stream) {
77-
console.log(item.candidates[0].content.parts[0].text);
78-
}
81+
},
82+
{role: 'function', parts: functionResponseParts},
83+
],
84+
tools: functionDeclarations,
85+
};
86+
const streamingResp =
87+
await generativeModel.generateContentStream(request);
88+
for await (const item of streamingResp.stream) {
89+
console.log(item.candidates[0].content.parts[0].text);
90+
}
7991
}
8092
// [END aiplatform_gemini_function_calling_content]
8193

8294
functionCallingStreamChat(...process.argv.slice(2)).catch(err => {
83-
console.error(err.message);
84-
process.exitCode = 1;
95+
console.error(err.message);
96+
process.exitCode = 1;
8597
});

run/helloworld/package.docs.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.0.0",
55
"private": true,
66
"main": "index.js",
7+
"type": "module",
78
"scripts": {
89
"start": "node index.js"
910
},

0 commit comments

Comments
 (0)