diff --git a/examples/read_hn.py b/examples/read_hn.py index e3dff0b..7b61ff4 100644 --- a/examples/read_hn.py +++ b/examples/read_hn.py @@ -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 @@ -41,7 +40,7 @@ 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] @@ -49,7 +48,9 @@ def analyze_hn_articles(n: int = 5): 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__": @@ -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)