Skip to content

Commit b19fc8c

Browse files
Add function calling REST example (#443)
* Add function calling REST example * Update function calling sample to have file content in bash script * Delete tools.json * Move tools definition into the region tag. --------- Co-authored-by: Mark Daoust <[email protected]>
1 parent 695ee95 commit b19fc8c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

samples/rest/function_calling.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
set -eu
2+
3+
echo "[START function_calling]"
4+
# [START function_calling]
5+
6+
cat > tools.json << EOF
7+
{
8+
"function_declarations": [
9+
{
10+
"name": "enable_lights",
11+
"description": "Turn on the lighting system.",
12+
"parameters": { "type": "object" }
13+
},
14+
{
15+
"name": "set_light_color",
16+
"description": "Set the light color. Lights must be enabled for this to work.",
17+
"parameters": {
18+
"type": "object",
19+
"properties": {
20+
"rgb_hex": {
21+
"type": "string",
22+
"description": "The light color as a 6-digit hex string, e.g. ff0000 for red."
23+
}
24+
},
25+
"required": [
26+
"rgb_hex"
27+
]
28+
}
29+
},
30+
{
31+
"name": "stop_lights",
32+
"description": "Turn off the lighting system.",
33+
"parameters": { "type": "object" }
34+
}
35+
]
36+
}
37+
EOF
38+
39+
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
40+
-H 'Content-Type: application/json' \
41+
-d @<(echo '
42+
{
43+
"system_instruction": {
44+
"parts": {
45+
"text": "You are a helpful lighting system bot. You can turn lights on and off, and you can set the color. Do not perform any other tasks."
46+
}
47+
},
48+
"tools": ['$(source "$tools")'],
49+
50+
"tool_config": {
51+
"function_calling_config": {"mode": "none"}
52+
},
53+
54+
"contents": {
55+
"role": "user",
56+
"parts": {
57+
"text": "What can you do?"
58+
}
59+
}
60+
}
61+
') 2>/dev/null |sed -n '/"content"/,/"finishReason"/p'
62+
# [END function_calling]

0 commit comments

Comments
 (0)