Skip to content

Commit 8de8d44

Browse files
DARREN OBERSTDARREN OBERST
authored andcommitted
shifting several web-related dependencies to optional
1 parent e949ce1 commit 8de8d44

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

‎examples/Parsing/parse_web_sources_in_memory.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
When parsing websites, please follow best practices, ethical guidelines and common sense - as a good example,
55
see https://monashdatafluency.github.io/python-web-scraping/section-5-legal-and-ethical-considerations/
66
7+
To use the WebSite Parser requires several additional python libraries to be installed:
8+
9+
pip3 install beautifulsoup4
10+
pip3 install lxml
11+
pip3 install requests
12+
pip3 install urllib3
13+
714
"""
815

916
from llmware.parsers import Parser, WebSiteParser

‎examples/Use_Cases/web_services_slim_fx.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
The example shows how to extract keys from one source that can then be used as a lookup in a web service to
1515
supplement the original source materials, and provide a secondary source, which can then also be prompted and
1616
used to extract, analyze and summarize key information.
17+
18+
NOTE: to run this example, please install yfinance library, e.g., 'pip3 install yfinance'
19+
1720
"""
1821

1922

2023
from llmware.web_services import YFinance
2124
from llmware.models import ModelCatalog
2225
from llmware.parsers import WikiParser
2326

27+
from importlib import util
28+
if not util.find_spec("yfinance"):
29+
print("\nto run this example, you need to install yfinance first, e.g., pip3 install yfinance")
30+
2431
# our input - financial news article
2532

2633
text=("BEAVERTON, Ore.--(BUSINESS WIRE)--NIKE, Inc. (NYSE:NKE) today reported fiscal 2024 financial results for its "

‎llmware/requirements.txt‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
beautifulsoup4==4.11.1
21
boto3==1.24.53
32
datasets==2.15.0
43
huggingface-hub==0.19.4
5-
lxml==4.9.3
64
numpy>=1.23.2
75
openai>=1.0
86
pdf2image==1.16.0
@@ -16,7 +14,6 @@ torch>=1.13.1
1614
transformers>=4.36.0
1715
word2number==1.1
1816
Wikipedia-API==0.6.0
19-
yfinance>=0.2.28
2017
psycopg-binary==3.1.17
2118
psycopg==3.1.17
2219
pgvector==0.2.4

‎llmware/web_services.py‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ def __init__(self, ticker=None):
164164

165165
try:
166166
import yfinance
167-
except ImportError:
168-
raise LLMWareException(message="Exception: need to `pip install yfinance` library.")
167+
except ImportError or ModuleNotFoundError:
168+
raise LLMWareException(message="Exception: YFinance library not installed - "
169+
"fix with `pip3 install yfinance`")
169170

170171
if ticker:
171172
self.company_info = yfinance.Ticker(ticker)
@@ -255,10 +256,15 @@ def __init__(self, url_or_fp, link="/", save_images=True, reset_img_folder=False
255256
from bs4 import BeautifulSoup
256257
import requests
257258
from urllib.request import urlopen, Request
258-
except ImportError:
259-
raise LLMWareException(message="Exception: to use WebSiteParser requires three additional Python "
260-
"dependencies via pip install: bs4 (BeautifulSoup), requests, and "
261-
"urllib.request")
259+
import lxml
260+
261+
except ModuleNotFoundError or ImportError:
262+
raise LLMWareException(message="Exception: to use WebSiteParser requires additional Python "
263+
"dependencies via pip install: "
264+
"\n -- pip3 install beautifulsoup4 (or bs4)"
265+
"\n -- pip3 install lxml"
266+
"\n -- pip3 install requests"
267+
"\n -- pip3 install urllib3")
262268

263269
# note: for webscraping, unverified ssl are a common error
264270
# to debug, if the risk environment is relatively low, set `unverified_context` = True, although
@@ -341,7 +347,7 @@ def __init__(self, url_or_fp, link="/", save_images=True, reset_img_folder=False
341347
except Exception as e:
342348
success_code = -1
343349
raise LLMWareException(message=f"Exception: website_parser could not connect to website - "
344-
f"caught error - {e}. Two suggested fixes: \n"
350+
f"caught error - {e}. Common issues: \n"
345351
f"1. Update your certificates in the Python path, e.g., "
346352
f"'Install Certificates.command'\n"
347353
f"2. Set unverified_context=True in the constructor for "

‎setup.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ def glob_fix(package_name, glob):
5353
python_requires=">=3.9",
5454
zip_safe=True,
5555
install_requires=[
56-
'beautifulsoup4==4.11.1',
5756
'boto3==1.24.53',
5857
'datasets==2.15.0',
5958
'huggingface-hub==0.19.4',
60-
'lxml==4.9.3',
6159
'numpy>=1.23.2',
6260
'openai>=1.0.0',
6361
'pdf2image==1.16.0',
@@ -71,7 +69,6 @@ def glob_fix(package_name, glob):
7169
'transformers>=4.36.0',
7270
'word2number==1.1',
7371
'Wikipedia-API==0.6.0',
74-
'yfinance>=0.2.28',
7572
'psycopg-binary==3.1.17',
7673
'psycopg==3.1.17',
7774
'pgvector==0.2.4',

0 commit comments

Comments
 (0)