The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
Substack loader improvements (#952)
Sidharth Mohantyd62a23edf6ab
diff --git a/docs/data-sources/overview.mdx b/docs/data-sources/overview.mdxindex 8bff8bced..8488ce400 100644--- a/docs/data-sources/overview.mdx+++ b/docs/data-sources/overview.mdx@@ -27,6 +27,7 @@ Embedchain comes with built-in support for various data sources. We handle the c<Card title="π¬ Discord" href="/data-sources/discord"></Card><Card title="π Github" href="/data-sources/github"></Card><Card title="βοΈ Custom" href="/data-sources/custom"></Card>+ <Card title="π Substack" href="/data-sources/substack"></Card><Card title="π Beehiiv" href="/data-sources/beehiiv"></Card></CardGroup>diff --git a/docs/data-sources/substack.mdx b/docs/data-sources/substack.mdxindex 2a5f9d8a9..41aba375f 100644--- a/docs/data-sources/substack.mdx+++ b/docs/data-sources/substack.mdx@@ -2,15 +2,15 @@title: "π Substack"----To add any Substack data sources to your app, just add the sitemap.xml of that url as the source and set the data_type to `substack`.+To add any Substack data sources to your app, just add the main base url as the source and set the data_type to `substack`.```pythonfrom embedchain import Pipeline as Appapp = App()-# source: for any substack just add the sitemap.xml url-app.add('https://www.lennysnewsletter.com/sitemap.xml', data_type='substack')+# source: for any substack just add the root URL+app.add('https://www.lennysnewsletter.com', data_type='substack')app.query("Who is Brian Chesky?")# Answer: Brian Chesky is the co-founder and CEO of Airbnb.```diff --git a/embedchain/loaders/substack.py b/embedchain/loaders/substack.pyindex 350ab3c22..a5fd0b6f6 100644--- a/embedchain/loaders/substack.py+++ b/embedchain/loaders/substack.py@@ -3,7 +3,7 @@ import loggingimport timeimport requests-+from xml.etree import ElementTreefrom embedchain.helpers.json_serializable import register_deserializablefrom embedchain.loaders.base_loader import BaseLoaderfrom embedchain.utils import is_readable@@ -24,9 +24,29 @@ class SubstackLoader(BaseLoader):'Substack requires extra dependencies. Install with `pip install --upgrade "embedchain[dataloaders]"`') from None+ if not url.endswith("sitemap.xml"):+ url = url + "/sitemap.xml"+output = []response = requests.get(url)- response.raise_for_status()++ try:+ response.raise_for_status()+ except requests.exceptions.HTTPError as e:+ raise ValueError(+ f"""+ Failed to load {url}: {e}. Please use the root substack URL. For example, https://example.substack.com+ """+ )++ try:+ ElementTree.fromstring(response.content)+ except ElementTree.ParseError:+ raise ValueError(+ f"""+ Failed to parse {url}. Please use the root substack URL. For example, https://example.substack.com+ """+ )soup = BeautifulSoup(response.text, "xml")links = [link.text for link in soup.find_all("loc") if link.parent.name == "url" and "/p/" in link.text]