SPB Git

Repository Public

custom_tools.sh 2.4 KB 48 lines shellscript

1#!/usr/bin/env bash2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : API Atlas8# File             : examples/openai/tools/custom-tools/custom_tools.sh9# Module           : examples10# Repository       : https://git.spboucher.ai/doc-api11# Created          : 2026-09-1812# Last Modified    : 2026-09-1813#14# Author           : Simon-Pierre Boucher15# Position         : Professor of Finance16# Institution      : Université du Québec en Outaouais (UQO)17# Organization     : SP Boucher18# Website          : https://spboucher.ai19# Git              : https://git.spboucher.ai20#21# Preferred Contact: contact@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin   : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# License          : None specified (no license file in this repository)32#33# Do not embed credentials, private keys, access tokens,34# certificates or confidential personal information.35#36# =============================================================================37# END OF SP BOUCHER SOURCE HEADER38# =============================================================================3940# Custom tool with a regex grammar (yes|no). STATUS: LIVE_VERIFIED 2026-09-18 (gpt-5.4-nano). Run: bash examples/openai/tools/custom-tools/custom_tools.sh41set -eo pipefail  # no -u: oai() runs in $(...) subshells, so OAI_STATUS may be unset in the parent42source "$(dirname "$0")/../../../../scripts/lib.sh"43R=$(oai POST /v1/responses -d '{"model":"gpt-5.4-nano","input":"Is 2+2 equal to 4? Use the tool.","max_output_tokens":32,"reasoning":{"effort":"low"},44 "tools":[{"type":"custom","name":"answer_yes_no","description":"Reply with exactly yes or no.","format":{"type":"grammar","syntax":"regex","definition":"^(yes|no)$"}}],45 "tool_choice":{"type":"custom","name":"answer_yes_no"}}')46log_request openai POST /v1/responses "${OAI_STATUS:-200}" 0.0001 "custom_tools.sh"47echo "$R" | jq -c '.output[] | select(.type=="custom_tool_call") | {name, input, call_id}'48
Files main
Menu

Theme