Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function calling REST example #443

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions samples/rest/function_calling.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cat > tools.json << EOF
MarkDaoust marked this conversation as resolved.
Show resolved Hide resolved
{
"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

set -eu

echo "[START function_calling]"
# [START function_calling]
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]
30 changes: 30 additions & 0 deletions tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"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" }
}
]
}
Loading