Skip to content

Commit c1dd29b

Browse files
committed
more readme work
1 parent 3f96a58 commit c1dd29b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ await client.files.create({
126126

127127
## Streaming Helpers
128128

129+
The SDK makes it easy to stream responses, by providing an emitter helper via `.stream()`:
130+
129131
```ts
130132
import OpenAI from 'openai';
131133

@@ -154,6 +156,10 @@ async function main() {
154156
main();
155157
```
156158

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+
157163
## Tool Helpers
158164

159165
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.

helpers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ See an example of streaming helpers in action in [`examples/stream.ts`](examples
304304
305305
### Automated function calls via Beta Tool Runner
306306
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.
308308
309309
#### Usage
310310
@@ -376,6 +376,8 @@ for await (const event of toolRunner) {
376376
}
377377
```
378378

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+
379381
When you just "await" the `toolRunner`, it simply automatically iterates until the end of the async generator.
380382

381383
#### Streaming
@@ -424,9 +426,9 @@ const weatherTool = betaZodFunctionTool({
424426

425427
The AI's generated inputs will be directly validated and fed into your function automatically.
426428

427-
### Automated function calls
429+
### Legacy Automated function calls
428430

429-
We provide the `openai.chat.completions.runTools({…})`
431+
We also provide the `openai.chat.completions.runTools({…})`
430432
convenience helper for using function tool calls with the `/chat/completions` endpoint
431433
which automatically call the JavaScript functions you provide
432434
and sends their results back to the `/chat/completions` endpoint,
@@ -439,8 +441,6 @@ Otherwise, the args will be passed to the function you provide as a string.
439441
If you pass `tool_choice: {function: {name: …}}` instead of `auto`,
440442
it returns immediately after calling that function (and only loops to auto-recover parsing errors).
441443

442-
#### Beta Tool
443-
444444
```ts
445445
import OpenAI from 'openai';
446446

0 commit comments

Comments
 (0)