Skip to content

Commit ae2dd76

Browse files
committed
docs: replace runFunctions with runTools in readme (#570)
1 parent f82691a commit ae2dd76

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ If you need to cancel a stream, you can `break` from a `for await` loop or call
143143

144144
### Automated function calls
145145

146-
We provide `openai.beta.chat.completions.runFunctions({…})` and `openai.beta.chat.completions.runTools({…})`
147-
convenience helpers for using function calls with the `/chat/completions` endpoint
146+
We provide the `openai.beta.chat.completions.runTools({…})`
147+
convenience helper for using function tool calls with the `/chat/completions` endpoint
148148
which automatically call the JavaScript functions you provide
149149
and sends their results back to the `/chat/completions` endpoint,
150-
looping as long as the model requests function calls.
150+
looping as long as the model requests tool calls.
151151

152152
If you pass a `parse` function, it will automatically parse the `arguments` for you
153153
and returns any parsing errors to the model to attempt auto-recovery.
154154
Otherwise, the args will be passed to the function you provide as a string.
155155

156-
If you pass `function_call: {name: …}` or `tool_choice: {function: {name: …}}` instead of `auto`,
156+
If you pass `tool_choice: {function: {name: …}}` instead of `auto`,
157157
it returns immediately after calling that function (and only loops to auto-recover parsing errors).
158158

159159
```ts
@@ -163,21 +163,27 @@ const client = new OpenAI();
163163

164164
async function main() {
165165
const runner = client.beta.chat.completions
166-
.runFunctions({
166+
.runTools({
167167
model: 'gpt-3.5-turbo',
168168
messages: [{ role: 'user', content: 'How is the weather this week?' }],
169-
functions: [
169+
tools: [
170170
{
171-
function: getCurrentLocation,
172-
parameters: { type: 'object', properties: {} },
171+
type: 'function',
172+
function: {
173+
function: getCurrentLocation,
174+
parameters: { type: 'object', properties: {} },
175+
},
173176
},
174177
{
175-
function: getWeather,
176-
parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
177-
parameters: {
178-
type: 'object',
179-
properties: {
180-
location: { type: 'string' },
178+
type: 'function',
179+
function: {
180+
function: getWeather,
181+
parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
182+
parameters: {
183+
type: 'object',
184+
properties: {
185+
location: { type: 'string' },
186+
},
181187
},
182188
},
183189
},
@@ -203,17 +209,19 @@ async function getWeather(args: { location: string }) {
203209
main();
204210

205211
// {role: "user", content: "How's the weather this week?"}
206-
// {role: "assistant", function_call: "getCurrentLocation", arguments: "{}"}
207-
// {role: "function", name: "getCurrentLocation", content: "Boston"}
208-
// {role: "assistant", function_call: "getWeather", arguments: '{"location": "Boston"}'}
209-
// {role: "function", name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}'}
212+
// {role: "assistant", tool_calls: [{type: "function", function: {name: "getCurrentLocation", arguments: "{}"}, id: "123"}
213+
// {role: "tool", name: "getCurrentLocation", content: "Boston", tool_call_id: "123"}
214+
// {role: "assistant", tool_calls: [{type: "function", function: {name: "getWeather", arguments: '{"location": "Boston"}'}, id: "1234"}]}
215+
// {role: "tool", name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}', tool_call_id: "1234"}
210216
// {role: "assistant", content: "It's looking cold and rainy - you might want to wear a jacket!"}
211217
//
212218
// Final content: "It's looking cold and rainy - you might want to wear a jacket!"
213219
```
214220

215221
Like with `.stream()`, we provide a variety of [helpers and events](helpers.md#events).
216222

223+
Note that `runFunctions` was previously available as well, but has been deprecated in favor of `runTools`.
224+
217225
Read more about various examples such as with integrating with [zod](helpers.md#integrate-with-zod),
218226
[next.js](helpers.md#integrate-wtih-next-js), and [proxying a stream to the browser](helpers.md#proxy-streaming-to-a-browser).
219227

0 commit comments

Comments
 (0)