Skip to content

Commit f8ebc2c

Browse files
authored
Merge branch 'main' into bqstore-v1b1
2 parents b050cd8 + ff51616 commit f8ebc2c

7 files changed

Lines changed: 105 additions & 292 deletions

File tree

generative-ai/snippets/test/nonStreamingContent.test.js renamed to genai/tools/test/tools-func-calling-stream-content.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ const {describe, it} = require('mocha');
1919
const cp = require('child_process');
2020
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2121

22-
const projectId = process.env.CAIP_PROJECT_ID;
23-
const location = process.env.LOCATION;
24-
const model = 'gemini-2.0-flash-001';
22+
const projectId = process.env.GOOGLE_CLOUD_PROJECT;
23+
const location = process.env.GOOGLE_CLOUD_LOCATION || 'global';
24+
const model = 'gemini-2.5-flash';
2525

26-
describe.skip('Generative AI NonStreaming Content', () => {
26+
describe('tools-func-calling-stream-content', () => {
2727
/**
2828
* TODO(developer): Uncomment these variables before running the sample.\
2929
* (Not necessary if passing values as arguments)
3030
*/
3131
// const projectId = 'YOUR_PROJECT_ID';
3232
// const location = 'YOUR_LOCATION';
33-
// const model = 'gemini-2.0-flash-001';
33+
// const model = 'gemini-2.5-flash';
3434

35-
it('should create nonstreaming content', async () => {
35+
it('should create stream chat and begin the conversation the same in each instance', async () => {
3636
const output = execSync(
37-
`node ./nonStreamingContent.js ${projectId} ${location} ${model}`
37+
`node ./tools-func-calling-stream-content.js ${projectId} ${location} ${model}`
3838
);
3939

40-
// Assert that the correct prompt was issued
41-
assert(output.match(/Write a story about a magic backpack/));
40+
// Assert that the response is what we expect
41+
assert(output.match(/super nice/), output);
4242
});
4343
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START aiplatform_genai_function_calling_stream_content]
16+
const {GoogleGenAI} = require('@google/genai');
17+
18+
const tools = [
19+
{
20+
functionDeclarations: [
21+
{
22+
name: 'get_current_weather',
23+
description: 'get weather in a given location',
24+
parameters: {
25+
type: 'OBJECT',
26+
properties: {
27+
location: {type: 'STRING'},
28+
unit: {type: 'STRING', enum: ['celsius', 'fahrenheit']},
29+
},
30+
required: ['location'],
31+
},
32+
},
33+
],
34+
},
35+
];
36+
37+
const functionResponseParts = [
38+
{
39+
functionResponse: {
40+
name: 'get_current_weather',
41+
response: {weather: 'super nice'},
42+
},
43+
},
44+
];
45+
46+
/**
47+
* TODO(developer): Update these variables before running the sample.
48+
*/
49+
async function functionCallingStreamContent(
50+
projectId = 'PROJECT_ID',
51+
location = 'us-central1',
52+
model = 'gemini-2.5-flash'
53+
) {
54+
// Initialize client with your Cloud project and location
55+
const client = new GoogleGenAI({
56+
vertexai: true,
57+
project: projectId,
58+
location: location,
59+
});
60+
61+
const request = [
62+
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
63+
{
64+
role: 'model',
65+
parts: [
66+
{
67+
functionCall: {
68+
name: 'get_current_weather',
69+
args: {location: 'Boston'},
70+
},
71+
},
72+
],
73+
},
74+
{role: 'user', parts: functionResponseParts},
75+
];
76+
77+
const streamingResp = await client.models.generateContentStream({
78+
model: model,
79+
contents: request,
80+
config: {tools: tools},
81+
});
82+
83+
let completeResponseText = '';
84+
for await (const chunk of streamingResp) {
85+
if (chunk.text) {
86+
completeResponseText += chunk.text;
87+
}
88+
}
89+
console.log(completeResponseText);
90+
}
91+
// [END aiplatform_genai_function_calling_stream_content]
92+
93+
functionCallingStreamContent(...process.argv.slice(2)).catch(err => {
94+
console.error(err.message);
95+
process.exitCode = 1;
96+
});

generative-ai/snippets/gemini-translate.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

generative-ai/snippets/nonStreamingContent.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

generative-ai/snippets/streamContent.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

generative-ai/snippets/test/gemini-translate.test.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)