Skip to content

Commit d406ac9

Browse files
authored
Merge pull request #96 from WorkflowAI/README-changes
docs: add streaming example to README
2 parents ac2a5ec + ed2535e commit d406ac9

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
@@ -36,6 +36,34 @@ https://github.com/user-attachments/assets/7bc99d61-5c49-4c65-9cf2-36c1c9415559
3636

3737
- **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).
3838

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

4169
- **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)