Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 3a5b81d

Browse files
committed
spiffy
doesnt need to be a cf flow
1 parent 329cf8e commit 3a5b81d

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

examples/read_hn.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from typing import Annotated, TypedDict
99

1010
import httpx
11+
from prefect import flow
1112
from prefect.artifacts import create_markdown_artifact
12-
from prefect.blocks.system import Secret
1313
from prefect.docker import DockerImage
1414
from prefect.runner.storage import GitCredentials, GitRepository
15-
from pydantic import AnyHttpUrl, Field
15+
from pydantic import AnyHttpUrl, Field, TypeAdapter
1616

1717
import controlflow as cf
1818

@@ -32,24 +32,22 @@ def analyze_article(id: str) -> HNArticleSummary:
3232
return f"here is the article content: {content}" # type: ignore
3333

3434

35-
@cf.task()
36-
def summarize_article_briefs(
37-
briefs: list[HNArticleSummary],
38-
) -> Annotated[str, Field(description="markdown summary")]:
39-
"""Summarize a list of article briefs"""
40-
return f"here are the article briefs: {briefs}" # type: ignore
41-
42-
43-
@cf.flow(retries=2)
44-
def analyze_hn_articles(n: int = 5):
35+
@flow(retries=2)
36+
def analyze_hn_articles(n: int = 5) -> list[HNArticleSummary]:
4537
top_article_ids = httpx.get(
4638
"https://hacker-news.firebaseio.com/v0/topstories.json"
4739
).json()[:n]
4840
briefs = analyze_article.map(top_article_ids).result()
4941
create_markdown_artifact(
5042
key="hn-article-exec-summary",
51-
markdown=summarize_article_briefs(briefs),
43+
markdown=cf.run(
44+
objective="markdown summary of all extracted article briefs",
45+
result_type=Annotated[str, Field(description="markdown summary")],
46+
context=dict(briefs=briefs),
47+
),
48+
description="executive summary of all extracted article briefs",
5249
)
50+
return briefs
5351

5452

5553
if __name__ == "__main__":
@@ -96,4 +94,5 @@ def analyze_hn_articles(n: int = 5):
9694
)
9795
else:
9896
print(f"just running the code\n\n\n\n\n\n")
99-
analyze_hn_articles(5)
97+
briefs = analyze_hn_articles(5) # type: ignore
98+
TypeAdapter(list[HNArticleSummary]).validate_python(briefs)

0 commit comments

Comments
 (0)