SPB Git

Repository Public

tool_search.ts 2.9 KB 57 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : API Atlas8 * File             : examples/openai/tools/tool-search/tool_search.ts9 * 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 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Hosted tool search with a deferred function in a namespace. STATUS: LIVE_VERIFIED 2026-09-18 (gpt-5.4-mini; nano lacks tool_search).43// Run: node --env-file=.env --experimental-strip-types examples/openai/tools/tool-search/tool_search.ts44import OpenAI from "openai";45import { logRequest } from "../../../shared/tool-loop/log.ts";46const client = new OpenAI();47const deferred = { type: "function", name: "get_weather", description: "Current weather for a city.", defer_loading: true, strict: true,48  parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"], additionalProperties: false } };49const r: any = await client.responses.create({ model: "gpt-5.4-mini", input: "Weather in Paris? Find and use a tool.", max_output_tokens: 96, reasoning: { effort: "low" },50  tools: [{ type: "tool_search" } as any, { type: "namespace", name: "weather", description: "Weather lookup tools", tools: [deferred] } as any] });51logRequest("openai", "POST", "/v1/responses", 200, 0.0007, "tool_search.ts");52for (const i of r.output) {53  if (i.type === "tool_search_call") console.log("tool_search_call:", i.execution, JSON.stringify(i.arguments));54  if (i.type === "tool_search_output") console.log("tool_search_output:", i.tools.map((t: any) => t.name ?? t.type));55  if (i.type === "function_call") console.log("function_call:", i.namespace, i.name, i.arguments);56}57
Files main
Menu

Theme