|
8 | 8 | StructuredArticle, |
9 | 9 | SummarizeWebContentState, |
10 | 10 | ) |
11 | | -from template_langgraph.agents.news_summarizer_agent.scrapers import ( |
12 | | - BaseScraper, |
13 | | - HttpxScraper, |
14 | | - MockScraper, |
15 | | -) |
16 | | -from template_langgraph.agents.news_summarizer_agent.summarizers import ( |
17 | | - BaseSummarizer, |
18 | | - LlmSummarizer, |
19 | | - MockSummarizer, |
20 | | -) |
| 11 | +from template_langgraph.internals.notifiers import get_notifier |
| 12 | +from template_langgraph.internals.scrapers import get_scraper |
| 13 | +from template_langgraph.internals.summarizers import get_summarizer |
21 | 14 | from template_langgraph.llms.azure_openais import AzureOpenAiWrapper |
22 | 15 | from template_langgraph.loggers import get_logger |
23 | 16 |
|
24 | 17 | logger = get_logger(__name__) |
25 | 18 |
|
26 | 19 |
|
27 | | -class MockNotifier: |
28 | | - def notify(self, id: str, body: dict) -> None: |
29 | | - """Simulate sending a notification to the user.""" |
30 | | - logger.info(f"Notification sent for request {id}: {body}") |
31 | | - |
32 | | - |
33 | 20 | class NewsSummarizerAgent: |
34 | 21 | def __init__( |
35 | 22 | self, |
36 | 23 | llm=AzureOpenAiWrapper().chat_model, |
37 | | - notifier=MockNotifier(), |
38 | | - scraper: BaseScraper = MockScraper(), |
39 | | - summarizer: BaseSummarizer = MockSummarizer(), |
| 24 | + notifier=get_notifier(), |
| 25 | + scraper=get_scraper(), |
| 26 | + summarizer=get_summarizer(), |
40 | 27 | ): |
41 | 28 | self.llm = llm |
42 | 29 | self.notifier = notifier |
43 | | - self.scraper: BaseScraper = scraper |
44 | | - self.summarizer: BaseSummarizer = summarizer |
| 30 | + self.scraper = scraper |
| 31 | + self.summarizer = summarizer |
45 | 32 |
|
46 | 33 | def create_graph(self): |
47 | 34 | """Create the main graph for the agent.""" |
@@ -127,23 +114,20 @@ def summarize_web_content(self, state: SummarizeWebContentState): |
127 | 114 | def notify(self, state: AgentState) -> AgentState: |
128 | 115 | """Send notifications to the user.""" |
129 | 116 | logger.info(f"Sending notifications with state: {state}") |
130 | | - # Simulate sending notifications |
131 | | - # convert list of articles to a dictionary for notification |
132 | 117 | summary = {} |
133 | 118 | for i, article in enumerate(state.articles): |
134 | | - summary[i] = article.model_dump() |
| 119 | + summary[i] = { |
| 120 | + "url": article.url, |
| 121 | + "structured_article": article.structured_article.model_dump(), |
| 122 | + } |
135 | 123 | self.notifier.notify( |
136 | | - id=state.input.id, |
137 | | - body=summary, |
| 124 | + text=summary.__str__(), |
138 | 125 | ) |
139 | 126 | return state |
140 | 127 |
|
141 | 128 |
|
142 | | -# For testing |
143 | | -# graph = NewsSummarizerAgent().create_graph() |
144 | | - |
145 | 129 | graph = NewsSummarizerAgent( |
146 | | - notifier=MockNotifier(), |
147 | | - scraper=HttpxScraper(), |
148 | | - summarizer=LlmSummarizer(), |
| 130 | + notifier=get_notifier(), |
| 131 | + scraper=get_scraper(), |
| 132 | + summarizer=get_summarizer(), |
149 | 133 | ).create_graph() |
0 commit comments