Skip to content

Commit

Permalink
spiffy
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Nov 13, 2024
1 parent 329cf8e commit 26717b4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/read_hn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import httpx
from prefect.artifacts import create_markdown_artifact
from prefect.blocks.system import Secret
from prefect.docker import DockerImage
from prefect.runner.storage import GitCredentials, GitRepository
from pydantic import AnyHttpUrl, Field
from pydantic import AnyHttpUrl, Field, TypeAdapter

import controlflow as cf

Expand Down Expand Up @@ -41,15 +40,17 @@ def summarize_article_briefs(


@cf.flow(retries=2)
def analyze_hn_articles(n: int = 5):
def analyze_hn_articles(n: int = 5) -> list[HNArticleSummary]:
top_article_ids = httpx.get(
"https://hacker-news.firebaseio.com/v0/topstories.json"
).json()[:n]
briefs = analyze_article.map(top_article_ids).result()
create_markdown_artifact(
key="hn-article-exec-summary",
markdown=summarize_article_briefs(briefs),
description="executive summary of all extracted article briefs",
)
return briefs


if __name__ == "__main__":
Expand Down Expand Up @@ -96,4 +97,5 @@ def analyze_hn_articles(n: int = 5):
)
else:
print(f"just running the code\n\n\n\n\n\n")
analyze_hn_articles(5)
briefs = analyze_hn_articles(5) # type: ignore
TypeAdapter(list[HNArticleSummary]).validate_python(briefs)

0 comments on commit 26717b4

Please sign in to comment.