Skip to content

Commit ec22477

Browse files
docs: Fix README code samples. (#193)
1 parent 6fc78a9 commit ec22477

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ pip install writer-sdk
2525
Before you begin, ensure you have:
2626

2727
- Python 3.8 or higher
28-
- A [Writer API key](https://dev.writer.com/api-guides/introduction#authentication)
28+
- A [Writer API key](https://dev.writer.com/api-guides/quickstart#generate-a-new-api-key)
2929

3030
## Authentication
3131

3232
To authenticate with the Writer API, set the `WRITER_API_KEY` environment variable.
3333

34-
The `Writer` class automatically infers your API key from the `WRITER_API_KEY` environment variable.
35-
3634
```shell
3735
$ export WRITER_API_KEY="my-api-key"
3836
```
3937

38+
The `Writer` class automatically infers your API key from the `WRITER_API_KEY` environment variable.
39+
4040
```python
4141
from writerai import Writer
4242

@@ -127,12 +127,14 @@ stream = client.chat.chat(
127127
model="palmyra-x-004",
128128
stream=True,
129129
)
130+
130131
output_text = ""
131-
for chunk in chat_response:
132+
for chunk in stream:
132133
if chunk.choices[0].delta.content:
133-
output_text += chunk.choices[0].delta.content:
134+
output_text += chunk.choices[0].delta.content
134135
else:
135136
continue
137+
print(output_text)
136138
```
137139

138140
The async client uses the same interface.
@@ -153,12 +155,14 @@ stream = await client.chat.chat(
153155
model="palmyra-x-004",
154156
stream=True,
155157
)
158+
156159
output_text = ""
157160
async for chunk in stream:
158161
if chunk.choices[0].delta.content:
159162
output_text += chunk.choices[0].delta.content
160163
else:
161164
continue
165+
print(output_text)
162166
```
163167

164168
For non-streaming responses, the library returns a single response object.
@@ -307,6 +311,7 @@ By default, requests time out after three minutes. You can configure this with a
307311
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
308312

309313
```python
314+
import httpx
310315
from writerai import Writer
311316

312317
# Configure the default for all requests:

0 commit comments

Comments
 (0)