You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,6 +124,85 @@ await client.files.create({
124
124
});
125
125
```
126
126
127
+
## Streaming Helpers
128
+
129
+
```ts
130
+
importOpenAIfrom'openai';
131
+
132
+
const client =newOpenAI();
133
+
134
+
asyncfunction main() {
135
+
const stream =client.chat.completions
136
+
.stream({
137
+
model: 'gpt-4o',
138
+
max_tokens: 1024,
139
+
messages: [
140
+
{
141
+
role: 'user',
142
+
content: 'Say hi!',
143
+
},
144
+
],
145
+
})
146
+
.on('chunk', (text) => {
147
+
console.log(text);
148
+
});
149
+
150
+
const message =awaitstream.finalMessage();
151
+
console.log(message);
152
+
}
153
+
154
+
main();
155
+
```
156
+
157
+
## Tool Helpers
158
+
159
+
The SDK makes it easy to create and run [function tools with the chats API](https://platform.openai.com/docs/guides/function-calling). You can use Zod schemas or direct JSON schemas to describe the shape of tool input, and then you can run the tools using the `client.beta.messages.toolRunner` method. This method will automatically handle passing the inputs generated by the model into your tools and providing the results back to the model.
Copy file name to clipboardExpand all lines: helpers.md
+124Lines changed: 124 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -302,6 +302,128 @@ If you need to cancel a stream, you can `break` from a `for await` loop or call
302
302
303
303
See an example of streaming helpers in action in [`examples/stream.ts`](examples/stream.ts).
304
304
305
+
### Automated function calls via Beta Tool Runner
306
+
307
+
We now offer an easier to use tool calling approach via the `openai.beta.chat.completions.toolRunner({…})` helper. The SDK provides helper functions to create runnable tools that can be automatically invoked by the .toolRunner() method. These helpers simplify tool creation with JSON Schema or Zod validation.
0 commit comments