Skip to content

Commit ae1299f

Browse files
committed
docs: add streaming example to README
1 parent 516ed54 commit ae1299f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ https://github.com/user-attachments/assets/7bc99d61-5c49-4c65-9cf2-36c1c9415559
3535

3636
- **Streaming supported**: Enables real-time streaming of AI responses for low latency applications, with immediate validation of partial outputs. Learn more about [streaming capabilities](https://docs.workflowai.com/python-sdk/agent#streaming).
3737

38+
```python
39+
class ProductInput(BaseModel):
40+
description: str = Field()
41+
42+
class Category(str, enum.Enum):
43+
ELECTRONICS = "Electronics"
44+
CLOTHING = "Clothing"
45+
HOME_GOODS = "Home Goods"
46+
BEAUTY = "Beauty"
47+
SPORTS = "Sports"
48+
49+
class ProductAnalysisOutput(BaseModel):
50+
tags: list[str] = Field(default_factory=list)
51+
summary: str = Field()
52+
category: Category = Field()
53+
54+
@workflowai.agent(id="product-tagger", model=Model.DEEPSEEK_V3_LATEST)
55+
async def product_analyzer(input: ProductInput) -> ProductAnalysisOutput:
56+
"""
57+
Analyze a product description.
58+
"""
59+
60+
async for chunk in product_analyzer.stream(ProductInput(description="....")):
61+
# chunk is a partial ProductAnalysisOutput object. Fields are progressively
62+
# filled, but the object structure respects the type hint even when incomplete.
63+
print(chunk.output)
64+
```
65+
3866
https://github.com/user-attachments/assets/bcb52412-4dcb-45f8-b812-4275824ed543
3967

4068
- **Provider fallback**: Automatically switches to alternative AI providers when the primary provider fails, ensuring high availability and reliability for your AI applications. This feature allows you to define fallback strategies that maintain service continuity even during provider outages or rate limiting.

0 commit comments

Comments
 (0)