|
from langgraph.graph import StateGraph, START, END |
|
from state import NewsState, ArticleScraperState, BlogState |
|
from nodes import ( |
|
search_ai_news, |
|
parse_news_items, |
|
scrape_article_content, |
|
orchestrator, |
|
llm_call, |
|
synthesizer, |
|
assign_workers |
|
) |
|
|
|
def create_news_search_workflow(): |
|
"""Create a workflow for searching and parsing AI news""" |
|
workflow = StateGraph(NewsState) |
|
|
|
|
|
workflow.add_node("search_ai_news", search_ai_news) |
|
workflow.add_node("parse_news_items", parse_news_items) |
|
|
|
|
|
workflow.add_edge(START, "search_ai_news") |
|
workflow.add_edge("search_ai_news", "parse_news_items") |
|
workflow.add_edge("parse_news_items", END) |
|
|
|
return workflow.compile() |
|
|
|
def create_article_scraper_workflow(): |
|
"""Create a workflow for scraping article content""" |
|
workflow = StateGraph(ArticleScraperState) |
|
|
|
|
|
workflow.add_node("scrape_article", scrape_article_content) |
|
|
|
|
|
workflow.add_edge(START, "scrape_article") |
|
workflow.add_edge("scrape_article", END) |
|
|
|
return workflow.compile() |
|
|
|
def create_blog_generator_workflow(): |
|
"""Create a workflow for generating the blog""" |
|
workflow = StateGraph(BlogState) |
|
|
|
|
|
workflow.add_node("orchestrator", orchestrator) |
|
workflow.add_node("llm_call", llm_call) |
|
workflow.add_node("synthesizer", synthesizer) |
|
|
|
|
|
workflow.add_edge(START, "orchestrator") |
|
workflow.add_conditional_edges("orchestrator", assign_workers, ["llm_call"]) |
|
workflow.add_edge("llm_call", "synthesizer") |
|
workflow.add_edge("synthesizer", END) |
|
|
|
return workflow.compile() |