13
13
// limitations under the License.
14
14
15
15
// [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' ) ;
17
20
18
21
const functionDeclarations = [
19
22
{
@@ -24,7 +27,7 @@ const functionDeclarations = [
24
27
parameters : {
25
28
type : FunctionDeclarationSchemaType . OBJECT ,
26
29
properties : {
27
- location : { type : FunctionDeclarationSchemaType . STRING } ,
30
+ location : { type : FunctionDeclarationSchemaType . STRING } ,
28
31
unit : {
29
32
type : FunctionDeclarationSchemaType . STRING ,
30
33
enum : [ 'celsius' , 'fahrenheit' ] ,
@@ -41,8 +44,7 @@ const functionResponseParts = [
41
44
{
42
45
functionResponse : {
43
46
name : 'get_current_weather' ,
44
- response :
45
- { name : 'get_current_weather' , content : { weather : 'super nice' } } ,
47
+ response : { name : 'get_current_weather' , content : { weather : 'super nice' } } ,
46
48
} ,
47
49
} ,
48
50
] ;
@@ -56,7 +58,7 @@ async function functionCallingStreamChat(
56
58
model = 'gemini-pro'
57
59
) {
58
60
// Initialize Vertex with your Cloud project and location
59
- const vertexAI = new VertexAI ( { project : projectId , location : location } ) ;
61
+ const vertexAI = new VertexAI ( { project : projectId , location : location } ) ;
60
62
61
63
// Instantiate the model
62
64
const generativeModel = vertexAI . preview . getGenerativeModel ( {
@@ -65,9 +67,9 @@ async function functionCallingStreamChat(
65
67
66
68
const request = {
67
69
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 }
70
+ { role : 'user' , parts : [ { text : 'What is the weather in Boston?' } ] } ,
71
+ { role : 'model' , parts : [ { functionCall : { name : 'get_current_weather' , args : { 'location' : 'Boston' } } } ] } ,
72
+ { role : 'function' , parts : functionResponseParts } ,
71
73
] ,
72
74
tools : functionDeclarations ,
73
75
} ;
0 commit comments