Skip to content

Commit a0b8dc5

Browse files
committed
fix : adding writer support article, fixed the announcement article and deleted failing multitask.py task
1 parent 9f1ab9f commit a0b8dc5

File tree

6 files changed

+198
-89
lines changed

6 files changed

+198
-89
lines changed

docs/blog/.authors.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ authors:
2727
name: Thierry Jean
2828
description: Contributor
2929
avatar: https://avatars.githubusercontent.com/u/68975210?v=4
30-
url: https://www.linkedin.com/in/thierry-jean/
30+
url: https://www.linkedin.com/in/thierry-jean/
31+
yanomaly:
32+
name: Yan
33+
description: Contributor
34+
avatar: https://avatars.githubusercontent.com/u/87994542?v=4

docs/blog/posts/writer-support.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ We're excited to announce that `instructor` now supports [Writer](https://writer
2121

2222
## Getting Started
2323

24-
First, install `instructor` with Writer support by running `pip install instructor[writer]` in your terminal. Then, head over to [Writer](https://writer.com) to sign up for Writer access and get an API key. You can paste API key as environment variable _WRITER_API_KEY_, or set attribute for Writer constructor.
24+
First, make sure that you've signed up for an account on [Writer](https://writer.com) and obtained an API key. Once you've done so, install `instructor` with Writer support by running `pip install instructor[writer]` in your terminal.
25+
26+
Make sure to set the `WRITER_API_KEY` environment variable with your Writer API key or pass it as an argument to the `Writer` constructor.
2527

2628
<!-- more -->
2729

@@ -118,7 +120,7 @@ for obj in extraction_stream:
118120
#> date='March 15th, 2024' location='Grand Tech Arena, 4521 Innovation Drive' budget=50000 eadline='February 20th'
119121
```
120122

121-
As well, if you don't sure that your request will be successfully performed from the first attempt, don't excite we also support retries mechanism! It's quite easy in use:
123+
As with all our integrations, `instructor` ships with the ability to automatically retry requests that happen due to schema validation without you having to do anything.
122124

123125
```python
124126
import instructor
@@ -142,7 +144,7 @@ class User(BaseModel):
142144
..., description="The name of the user"
143145
)
144146
age: int
145-
147+
146148

147149
user = client.chat.completions.create(
148150
model="palmyra-x-004",
@@ -155,4 +157,6 @@ print(user)
155157
#> name='JASON' age=12
156158
```
157159

158-
And that’s it! We showed only small part of things you can do featuring Writer provider: different types of classification, sentimental analysis and other cool stuff are ready to be used out of the box. We're excited to see what you build with Instructor and Writer! If you have any questions about Writer, do check out the [Writer documentation](https://dev.writer.com/home/introduction).
160+
This was a sneak peek into the things that you can do with Writer and `instructor` - from classification of text to sentimen analysis and more.
161+
162+
We're excited to see what you build with `instructor` and Writer. If you have any other questions about writer, do check out the [Writer Documentation](https://dev.writer.com/introduction) for the API sdk.

docs/integrations/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ Instructor supports a wide range of AI model providers, each with their own capa
2222
- [Anthropic](./anthropic.md) - Claude and Claude 2 models
2323
- [Google](./google.md) - PaLM and Gemini models
2424
- [Vertex AI](./vertex.md) - Google Cloud's AI platform
25-
- [Cohere](./cohere.md) - Command and other Cohere models
25+
- [Cohere](./cohere.md) - Command-R and other Cohere models
2626
- [Groq](./groq.md) - High-performance inference platform
2727
- [Mistral](./mistral.md) - Mistral's hosted models
2828
- [Fireworks](./fireworks.md) - High-performance model inference
29-
- [Cerebras](./cerebras.md) - AI accelerator platform
29+
- [Cerebras](./cerebras.md) - Llama-3-70B and other Open Source Models at blazing fast inference speeds
30+
- [Writer](./writer.md) - Palmyra-X-004 and other Writer models
3031

3132
### Model Management
3233

docs/integrations/writer.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
title: Structured Outputs with Writer
3+
description: Learn how to use Writer for structured outputs using their latest Palmyra-X-004 model for more reliable system outputs
4+
---
5+
6+
# Structured Outputs with Writer
7+
8+
This guide demonstrates how to use Writer for structured outputs using their latest Palmyra-X-004 model for more reliable system outputs.
9+
10+
You'll need to sign up for an account and get an API key. You can do that [here](https://writer.com).
11+
12+
```bash
13+
export WRITER_API_KEY=<your-api-key-here>
14+
pip install "instructor[writer]"
15+
```
16+
17+
## Palmyra-X-004
18+
19+
Writer supports structured outputs with their latest Palmyra-X-004 model that introduces tool calling functionality
20+
21+
### Sync Example
22+
23+
```python
24+
import instructor
25+
from writerai import Writer
26+
from pydantic import BaseModel
27+
28+
# Initialize Writer client
29+
client = instructor.from_writer(Writer(api_key="your API key"))
30+
31+
32+
class User(BaseModel):
33+
name: str
34+
age: int
35+
36+
37+
# Extract structured data
38+
user = client.chat.completions.create(
39+
model="palmyra-x-004",
40+
messages=[{"role": "user", "content": "Extract: John is 30 years old"}],
41+
response_model=User,
42+
)
43+
44+
print(user)
45+
#> name='John' age=30
46+
```
47+
48+
### Async Example
49+
50+
```python
51+
import instructor
52+
from writerai import AsyncWriter
53+
from pydantic import BaseModel
54+
55+
# Initialize Writer client
56+
client = instructor.from_writer(AsyncWriter())
57+
58+
59+
class User(BaseModel):
60+
name: str
61+
age: int
62+
63+
64+
async def extract_user():
65+
# Extract structured data
66+
user = await client.chat.completions.create(
67+
model="palmyra-x-004",
68+
messages=[{"role": "user", "content": "Extract: John is 30 years old"}],
69+
response_model=User,
70+
)
71+
72+
print(user)
73+
# > name='John' age=30
74+
75+
76+
if __name__ == "__main__":
77+
import asyncio
78+
79+
asyncio.run(extract_user())
80+
```
81+
82+
## Nested Objects
83+
84+
Writer also supports nested objects, which is useful for extracting data from more complex responses.
85+
86+
```python
87+
import instructor
88+
from writerai import Writer
89+
from pydantic import BaseModel
90+
91+
# Initialize Writer client
92+
client = instructor.from_writer(Writer())
93+
94+
95+
class Address(BaseModel):
96+
street: str
97+
city: str
98+
country: str
99+
100+
101+
class User(BaseModel):
102+
name: str
103+
age: int
104+
addresses: list[Address]
105+
106+
107+
# Create structured output with nested objects
108+
user = client.chat.completions.create(
109+
model="palmyra-x-004",
110+
messages=[
111+
{
112+
"role": "user",
113+
"content": """
114+
Extract: Jason is 25 years old.
115+
He lives at 123 Main St, New York, USA
116+
and has a summer house at 456 Beach Rd, Miami, USA
117+
""",
118+
},
119+
],
120+
response_model=User,
121+
)
122+
print(user)
123+
#> {
124+
#> 'name': 'Jason',
125+
#> 'age': 25,
126+
#> 'addresses': [
127+
#> {
128+
#> 'street': '123 Main St',
129+
#> 'city': 'New York',
130+
#> 'country': 'USA'
131+
#> },
132+
#> {
133+
#> 'street': '456 Beach Rd',
134+
#> 'city': 'Miami',
135+
#> 'country': 'USA'
136+
#> }
137+
#> ]
138+
#> }
139+
```
140+
141+
## Streaming Support
142+
143+
Instructor has two main ways that you can use to stream responses out
144+
145+
1. **Iterables**: These are useful when you'd like to stream a list of objects of the same type (Eg. use structured outputs to extract multiple users)
146+
2. **Partial Streaming**: This is useful when you'd like to stream a single object and you'd like to immediately start processing the response as it comes in.
147+
148+
We currently support streaming for Writer with native tool for both methods listed above.
149+
150+
### Partial Streaming
151+
152+
```python
153+
import instructor
154+
from writerai import Writer
155+
from pydantic import BaseModel
156+
157+
client = instructor.from_writer(Writer())
158+
159+
160+
class Person(BaseModel):
161+
name: str
162+
age: int
163+
164+
165+
resp = client.chat.completions.create_partial(
166+
model="palmyra-x-004",
167+
messages=[
168+
{
169+
"role": "user",
170+
"content": "Ivan is 27 and lives in Singapore",
171+
}
172+
],
173+
response_model=Person,
174+
)
175+
176+
for person in resp:
177+
print(person)
178+
# > name=None age=None
179+
# > name='Ivan' age=None
180+
# > name='Ivan' age=27
181+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ nav:
223223
- OpenAI: 'integrations/openai.md'
224224
- Together: 'integrations/together.md'
225225
- Vertex AI: 'integrations/vertex.md'
226+
- Writer: 'integrations/writer.md'
226227
- CLI Reference:
227228
- "CLI Reference": "cli/index.md"
228229
- "Finetuning GPT-3.5": "cli/finetune.md"

tests/llm/test_writer/test_multitask.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)