Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 58 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ client = Writer(
)

chat_completion = client.chat.chat(
messages=[{"role": "user"}],
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
)
print(chat_completion.id)
Expand All @@ -59,7 +64,12 @@ client = AsyncWriter(

async def main() -> None:
chat_completion = await client.chat.chat(
messages=[{"role": "user"}],
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
)
print(chat_completion.id)
Expand All @@ -79,13 +89,18 @@ from writerai import Writer

client = Writer()

stream = client.completions.create(
model="palmyra-x-003-instruct",
prompt="Hi, my name is",
stream = client.chat.chat(
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
stream=True,
)
for completion in stream:
print(completion.choices)
for chat_completion in stream:
print(chat_completion.id)
```

The async client uses the exact same interface.
Expand All @@ -95,13 +110,18 @@ from writerai import AsyncWriter

client = AsyncWriter()

stream = await client.completions.create(
model="palmyra-x-003-instruct",
prompt="Hi, my name is",
stream = await client.chat.chat(
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
stream=True,
)
async for completion in stream:
print(completion.choices)
async for chat_completion in stream:
print(chat_completion.id)
```

## Using types
Expand Down Expand Up @@ -211,7 +231,12 @@ client = Writer()

try:
client.chat.chat(
messages=[{"role": "user"}],
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
)
except writerai.APIConnectionError as e:
Expand Down Expand Up @@ -257,7 +282,12 @@ client = Writer(

# Or, configure per-request:
client.with_options(max_retries=5).chat.chat(
messages=[{"role": "user"}],
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
)
```
Expand All @@ -283,7 +313,12 @@ client = Writer(

# Override per-request:
client.with_options(timeout=5.0).chat.chat(
messages=[{"role": "user"}],
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
)
```
Expand Down Expand Up @@ -328,7 +363,8 @@ from writerai import Writer
client = Writer()
response = client.chat.with_raw_response.chat(
messages=[{
"role": "user"
"content": "Write a poem about Python",
"role": "user",
}],
model="palmyra-x-004",
)
Expand All @@ -350,7 +386,12 @@ To stream the response body, use `.with_streaming_response` instead, which requi

```python
with client.chat.with_streaming_response.chat(
messages=[{"role": "user"}],
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
) as response:
print(response.headers.get("X-My-Header"))
Expand Down
44 changes: 40 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,16 @@ def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> No
body=cast(
object,
maybe_transform(
dict(messages=[{"role": "user"}], model="palmyra-x-004"), ChatChatParamsNonStreaming
dict(
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
),
ChatChatParamsNonStreaming,
),
),
cast_to=httpx.Response,
Expand All @@ -752,7 +761,16 @@ def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> Non
body=cast(
object,
maybe_transform(
dict(messages=[{"role": "user"}], model="palmyra-x-004"), ChatChatParamsNonStreaming
dict(
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
),
ChatChatParamsNonStreaming,
),
),
cast_to=httpx.Response,
Expand Down Expand Up @@ -1534,7 +1552,16 @@ async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter)
body=cast(
object,
maybe_transform(
dict(messages=[{"role": "user"}], model="palmyra-x-004"), ChatChatParamsNonStreaming
dict(
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
),
ChatChatParamsNonStreaming,
),
),
cast_to=httpx.Response,
Expand All @@ -1554,7 +1581,16 @@ async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter)
body=cast(
object,
maybe_transform(
dict(messages=[{"role": "user"}], model="palmyra-x-004"), ChatChatParamsNonStreaming
dict(
messages=[
{
"content": "Write a poem about Python",
"role": "user",
}
],
model="palmyra-x-004",
),
ChatChatParamsNonStreaming,
),
),
cast_to=httpx.Response,
Expand Down