@@ -6,6 +6,39 @@ import {
66} from '../../lib/beta/BetaToolRunner' ;
77
88export class BetaCompletions extends APIResource {
9+ /**
10+ * Creates a tool runner that automates the back-and-forth conversation between the model and tools.
11+ *
12+ * The tool runner handles the following workflow:
13+ * 1. Sends a request to the model with some initial messages and available tools
14+ * 2. If the model calls tools, executes them automatically
15+ * 3. Sends tool results back to the model
16+ * 4. Repeats until the model provides a final response or max_iterations is reached
17+ *
18+ * @see [helpers.md](https://github.com/openai/openai-node/blob/master/helpers.md)
19+ *
20+ * @example
21+ * ```typescript
22+ * const finalMessage = await client.beta.chat.completions.toolRunner({
23+ * messages: [{ role: 'user', content: 'What's the weather in San Francisco?' }],
24+ * tools: [
25+ * betaZodFunctionTool({
26+ * name: 'get_weather',
27+ * inputSchema: z.object({
28+ * location: z.string().describe('The city and state, e.g. San Francisco, CA'),
29+ * unit: z.enum(['celsius', 'fahrenheit']).default('fahrenheit'),
30+ * }),
31+ * description: 'Get the current weather in a given location',
32+ * run: async (input) => {
33+ * return `The weather in ${input.location} is ${input.unit === 'celsius' ? '22°C' : '72°F'}`;
34+ * },
35+ * })
36+ * ],
37+ * model: 'gpt-4o'
38+ * });
39+ * console.log(finalMessage.content);
40+ * ```
41+ */
942 toolRunner (
1043 body : BetaToolRunnerParams & { stream ?: false } ,
1144 options ?: BetaToolRunnerRequestOptions ,
@@ -14,7 +47,6 @@ export class BetaCompletions extends APIResource {
1447 body : BetaToolRunnerParams & { stream : true } ,
1548 options ?: BetaToolRunnerRequestOptions ,
1649 ) : BetaToolRunner < true > ;
17- toolRunner ( body : BetaToolRunnerParams , options ?: BetaToolRunnerRequestOptions ) : BetaToolRunner < boolean > ;
1850 toolRunner ( body : BetaToolRunnerParams , options ?: BetaToolRunnerRequestOptions ) : BetaToolRunner < boolean > {
1951 return new BetaToolRunner ( this . _client , body , options ) ;
2052 }
0 commit comments