-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <markdaoust@google.com>
- Loading branch information
1 parent
695ee95
commit b19fc8c
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
set -eu | ||
|
||
echo "[START function_calling]" | ||
# [START function_calling] | ||
|
||
cat > tools.json << EOF | ||
{ | ||
"function_declarations": [ | ||
{ | ||
"name": "enable_lights", | ||
"description": "Turn on the lighting system.", | ||
"parameters": { "type": "object" } | ||
}, | ||
{ | ||
"name": "set_light_color", | ||
"description": "Set the light color. Lights must be enabled for this to work.", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"rgb_hex": { | ||
"type": "string", | ||
"description": "The light color as a 6-digit hex string, e.g. ff0000 for red." | ||
} | ||
}, | ||
"required": [ | ||
"rgb_hex" | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "stop_lights", | ||
"description": "Turn off the lighting system.", | ||
"parameters": { "type": "object" } | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \ | ||
-H 'Content-Type: application/json' \ | ||
-d @<(echo ' | ||
{ | ||
"system_instruction": { | ||
"parts": { | ||
"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." | ||
} | ||
}, | ||
"tools": ['$(source "$tools")'], | ||
"tool_config": { | ||
"function_calling_config": {"mode": "none"} | ||
}, | ||
"contents": { | ||
"role": "user", | ||
"parts": { | ||
"text": "What can you do?" | ||
} | ||
} | ||
} | ||
') 2>/dev/null |sed -n '/"content"/,/"finishReason"/p' | ||
# [END function_calling] |