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
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,6 +126,8 @@ await client.files.create({
126
126
127
127
## Streaming Helpers
128
128
129
+
The SDK makes it easy to stream responses, by providing an emitter helper via `.stream()`:
130
+
129
131
```ts
130
132
importOpenAIfrom'openai';
131
133
@@ -154,6 +156,10 @@ async function main() {
154
156
main();
155
157
```
156
158
159
+
With `.stream()` you get event handlers, accumulation, and an async iterable.
160
+
161
+
Alternatively, you can use `client.chat.completions({ ..., stream: true })` which only returns an async iterable of the events in the stream and thus uses less memory (it does not build up a final message object for you).
162
+
157
163
## Tool Helpers
158
164
159
165
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
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -304,7 +304,7 @@ See an example of streaming helpers in action in [`examples/stream.ts`](examples
304
304
305
305
### Automated function calls via Beta Tool Runner
306
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.
307
+
The SDK provides a convenient tool runner helper at `openai.beta.chat.completions.toolRunner({…})`that simplifies [function tool calling](https://platform.openai.com/docs/guides/function-calling). This helper allows you to define functions with their associated schemas, and the SDK will automatically invoke them as the AI requests and validate the parameters for you.
308
308
309
309
#### Usage
310
310
@@ -376,6 +376,8 @@ for await (const event of toolRunner) {
376
376
}
377
377
```
378
378
379
+
The tool runner will invoke the AI with your tool offering and initial message history, and then the AI may respond by invoking your tools. Eventually the AI will respond without a tool call message, which is the "final" message in the chain. As the AI repeatedly invokes tools, you can view the responses via the async iterator.
380
+
379
381
When you just "await" the `toolRunner`, it simply automatically iterates until the end of the async generator.
0 commit comments