Skip to content

Commit a8a20e1

Browse files
committed
removed double await, fix linter
1 parent 73ef4c8 commit a8a20e1

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed

generative-ai/snippets/functionCallingStreamChat.js

+60-57
Original file line numberDiff line numberDiff line change
@@ -13,84 +13,87 @@
1313
// limitations under the License.
1414

1515
// [START aiplatform_gemini_function_calling_chat]
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:
48+
{ name: 'get_current_weather', content: { weather: 'super nice' } },
4749
},
48-
];
50+
},
51+
];
4952

5053
/**
5154
* TODO(developer): Update these variables before running the sample.
5255
*/
5356
async function functionCallingStreamChat(
54-
projectId = 'PROJECT_ID',
55-
location = 'us-central1',
56-
model = 'gemini-pro'
57+
projectId = 'PROJECT_ID',
58+
location = 'us-central1',
59+
model = 'gemini-pro'
5760
) {
58-
// Initialize Vertex with your Cloud project and location
59-
const vertexAI = new VertexAI({ project: projectId, location: location });
61+
// Initialize Vertex with your Cloud project and location
62+
const vertexAI = new VertexAI({ project: projectId, location: location });
6063

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

66-
// Create a chat session and pass your function declarations
67-
const chat = generativeModel.startChat({
68-
tools: functionDeclarations,
69-
});
69+
// Create a chat session and pass your function declarations
70+
const chat = generativeModel.startChat({
71+
tools: functionDeclarations,
72+
});
7073

71-
const chatInput1 = 'What is the weather in Boston?';
74+
const chatInput1 = 'What is the weather in Boston?';
7275

73-
// This should include a functionCall response from the model
74-
const result1 = await chat.sendMessageStream(chatInput1);
75-
for await (const item of result1.stream) {
76-
console.log(item.candidates[0]);
77-
}
78-
const response1 = await result1.response;
76+
// This should include a functionCall response from the model
77+
const result1 = await chat.sendMessageStream(chatInput1);
78+
for await (const item of result1.stream) {
79+
console.log(item.candidates[0]);
80+
}
81+
const response1 = await result1.response;
7982

80-
// Send a follow up message with a FunctionResponse
81-
const result2 = await chat.sendMessageStream(functionResponseParts);
82-
for await (const item of result2.stream) {
83-
console.log(item.candidates[0]);
84-
}
83+
// Send a follow up message with a FunctionResponse
84+
const result2 = await chat.sendMessageStream(functionResponseParts);
85+
for await (const item of result2.stream) {
86+
console.log(item.candidates[0]);
87+
}
8588

86-
// This should include a text response from the model using the response content
87-
// provided above
88-
const response2 = await result2.response;
89-
console.log(response2.candidates[0].content.parts[0].text);
89+
// This should include a text response from the model using the response content
90+
// provided above
91+
const response2 = await result2.response;
92+
console.log(response2.candidates[0].content.parts[0].text);
9093
}
9194
// [END aiplatform_gemini_function_calling_chat]
9295

9396
functionCallingStreamChat(...process.argv.slice(2)).catch(err => {
94-
console.error(err.message);
95-
process.exitCode = 1;
97+
console.error(err.message);
98+
process.exitCode = 1;
9699
});

generative-ai/snippets/functionCallingStreamContent.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const functionDeclarations = [
1919
{
2020
function_declarations: [
2121
{
22-
name: "get_current_weather",
22+
name: 'get_current_weather',
2323
description: 'get weather in a given location',
2424
parameters: {
2525
type: FunctionDeclarationSchemaType.OBJECT,
@@ -40,9 +40,9 @@ const functionDeclarations = [
4040
const functionResponseParts = [
4141
{
4242
functionResponse: {
43-
name: "get_current_weather",
43+
name: 'get_current_weather',
4444
response:
45-
{name: "get_current_weather", content: {weather: "super nice"}},
45+
{name: 'get_current_weather', content: {weather: 'super nice'}},
4646
},
4747
},
4848
];

generative-ai/snippets/nonStreamingChat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function createNonStreamingChat(
3737
console.log(`User: ${chatInput1}`);
3838

3939
const result1 = await chat.sendMessage(chatInput1);
40-
const response1 = await result1.response;
40+
const response1 = result1.response;
4141
const text1 = response1.candidates[0].content.parts[0].text;
4242
console.log('Chat bot: ', text1);
4343

0 commit comments

Comments
 (0)