SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.6 KB · 14 lines shellscript
Raw Blame History
1#!/usr/bin/env bash2# Function calling via curl: forced strict function -> function_call -> function_call_output round trip.3# STATUS: LIVE_VERIFIED 2026-09-18 (gpt-5.4-nano). Run: bash examples/openai/tools/function-calling/function_calling.sh4set -eo pipefail  # no -u: oai() runs in $(...) subshells, so OAI_STATUS may be unset in the parent5source "$(dirname "$0")/../../../../scripts/lib.sh"6TOOL='{"type":"function","name":"get_weather","description":"Current weather for a city.","strict":true,"parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"],"additionalProperties":false}}'7R1=$(oai POST /v1/responses -d "{\"model\":\"gpt-5.4-nano\",\"input\":\"Weather in Paris?\",\"tools\":[$TOOL],\"tool_choice\":{\"type\":\"function\",\"name\":\"get_weather\"},\"max_output_tokens\":64,\"reasoning\":{\"effort\":\"low\"}}")8log_request openai POST /v1/responses "${OAI_STATUS:-200}" 0.0001 "function_calling.sh forced"9RID=$(echo "$R1" | jq -r .id); CALL_ID=$(echo "$R1" | jq -r '.output[] | select(.type=="function_call") | .call_id')10echo "$R1" | jq -c '.output[] | select(.type=="function_call") | {name, arguments, call_id, status}'11R2=$(oai POST /v1/responses -d "{\"model\":\"gpt-5.4-nano\",\"previous_response_id\":\"$RID\",\"tools\":[$TOOL],\"max_output_tokens\":32,\"reasoning\":{\"effort\":\"low\"},\"input\":[{\"type\":\"function_call_output\",\"call_id\":\"$CALL_ID\",\"output\":\"{\\\"temp_c\\\":18,\\\"sky\\\":\\\"clear\\\"}\"}]}")12log_request openai POST /v1/responses "${OAI_STATUS:-200}" 0.0001 "function_calling.sh round trip"13echo "$R2" | jq -r '.output[] | select(.type=="message") | .content[0].text'14