Skip to content

Commit

Permalink
Add function calling REST example (#443)
Browse files Browse the repository at this point in the history
* 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
shilpakancharla and MarkDaoust committed Jul 23, 2024
1 parent 695ee95 commit b19fc8c
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions samples/rest/function_calling.sh
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]

0 comments on commit b19fc8c

Please sign in to comment.