Commit 54f460e
fix(examples): refresh chat streaming examples (#2974)
## Summary
Several example scripts still reference `poetry` in their shebangs and
use the legacy Completions API, which is no longer documented in the
README. This PR brings them up to date:
- **Shebangs**: `demo.py`, `async_demo.py`, `streaming.py`, and
`video.py` all used `#!/usr/bin/env -S poetry run python`. The project
migrated to [Rye](https://rye.astral.sh/) and other examples (e.g.
`audio.py`, `speech_to_text.py`) already use `rye run python`. Updated
the four remaining files for consistency.
- **Deprecated API**: `async_demo.py` and `streaming.py` used the legacy
Completions endpoint (`client.completions.create` with
`gpt-3.5-turbo-instruct`). This endpoint isn't referenced in the README
and `gpt-3.5-turbo-instruct` is one of the last models supporting it.
Migrated both to the Chat Completions API
(`client.chat.completions.create`).
- **Model name**: `demo.py` referenced `gpt-4`. Updated to `gpt-4o` to
reflect current recommended usage.
## Changes
| File | Change |
|------|--------|
| `examples/demo.py` | shebang `poetry` → `rye`, model `gpt-4` →
`gpt-4o` |
| `examples/async_demo.py` | shebang `poetry` → `rye`,
`completions.create` → `chat.completions.create` |
| `examples/streaming.py` | shebang `poetry` → `rye`,
`completions.create` → `chat.completions.create` |
| `examples/video.py` | shebang `poetry` → `rye` |
## Test plan
- [x] `ruff check` passes on all modified files
- [x] `ruff format --check` passes on all modified files
- [x] Existing streaming tests (`tests/test_streaming.py`) pass
- [x] `import openai` works correctly
Co-authored-by: Marcus Wood <marcuswood@openai.com>1 parent d241ed6 commit 54f460e
2 files changed
Lines changed: 17 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
| |||
0 commit comments