sample_extractor_SummaryExtractor.py error
Opened this issue · 0 comments
Hi ,
Great book !
Unfortunatelly when following chapter 4 sample_extractor_SummaryExtractor.py :
from llama_index.core import SimpleDirectoryReader
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core.extractors import SummaryExtractor
reader = SimpleDirectoryReader('files')
documents = reader.load_data()
parser = SentenceSplitter(include_prev_next_rel=True)
nodes = parser.get_nodes_from_documents(documents)
summary_extractor = SummaryExtractor(
summaries=["prev", "self", "next"]
)
metadata_list = summary_extractor.extract(nodes)
The following error occurs ::
RuntimeError Traceback (most recent call last)
File ~/Building-Data-Driven-Applications-with-LlamaIndex/llama-index-book-andrei-env-python3-11/lib/python3.11/site-packages/llama_index/core/async_utils.py:33, in asyncio_run(coro)
32 # If we're here, there's an existing loop but it's not running
---> 33 return loop.run_until_complete(coro)
35 except RuntimeError as e:
36 # If we can't get the event loop, we're likely in a different thread, or its already running
File /usr/lib/python3.11/asyncio/base_events.py:626, in BaseEventLoop.run_until_complete(self, future)
625 self._check_closed()
--> 626 self._check_running()
628 new_task = not futures.isfuture(future)
File /usr/lib/python3.11/asyncio/base_events.py:586, in BaseEventLoop._check_running(self)
585 if self.is_running():
--> 586 raise RuntimeError('This event loop is already running')
587 if events._get_running_loop() is not None:
RuntimeError: This event loop is already running
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
File ~/Building-Data-Driven-Applications-with-LlamaIndex/llama-index-book-andrei-env-python3-11/lib/python3.11/site-packages/llama_index/core/async_utils.py:38, in asyncio_run(coro)
37 try:
---> 38 return asyncio.run(coro)
39 except RuntimeError as e:
File /usr/lib/python3.11/asyncio/runners.py:184, in run(main, debug)
182 if events._get_running_loop() is not None:
183 # fail fast with short traceback
--> 184 raise RuntimeError(
185 "asyncio.run() cannot be called from a running event loop")
187 with Runner(debug=debug) as runner:
RuntimeError: asyncio.run() cannot be called from a running event loop
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 metadata_list = summary_extractor.extract(nodes)
File ~/Building-Data-Driven-Applications-with-LlamaIndex/llama-index-book-andrei-env-python3-11/lib/python3.11/site-packages/llama_index/core/extractors/interface.py:95, in BaseExtractor.extract(self, nodes)
87 def extract(self, nodes: Sequence[BaseNode]) -> List[Dict]:
88 """Extracts metadata for a sequence of nodes, returning a list of
89 metadata dictionaries corresponding to each node.
90
(...)
93
94 """
---> 95 return asyncio_run(self.aextract(nodes))
File ~/Building-Data-Driven-Applications-with-LlamaIndex/llama-index-book-andrei-env-python3-11/lib/python3.11/site-packages/llama_index/core/async_utils.py:40, in asyncio_run(coro)
38 return asyncio.run(coro)
39 except RuntimeError as e:
---> 40 raise RuntimeError(
41 "Detected nested async. Please use nest_asyncio.apply() to allow nested event loops."
42 "Or, use async entry methods like aquery()
, aretriever
, achat
, etc."
43 )
45 except Exception as e:
46 # Catch any other exceptions and re-raise with more context
47 raise type(e)(f"Error running coroutine: {e!s}") from e
RuntimeError: Detected nested async. Please use nest_asyncio.apply() to allow nested event loops.Or, use async entry methods like aquery()
, aretriever
, achat
, etc.
I am using ::
Python 3.11.0rc1
and ::
aiohttp==3.9.5
aiosignal==1.3.1
altair==5.3.0
annotated-types==0.7.0
anyio==4.4.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==2.4.1
async-lru==2.0.4
attrs==23.2.0
Babel==2.15.0
beautifulsoup4==4.12.3
bleach==6.1.0
blinker==1.8.2
cachetools==5.4.0
certifi==2024.7.4
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
comm==0.2.2
dataclasses-json==0.6.7
debugpy==1.8.2
decorator==5.1.1
defusedxml==0.7.1
Deprecated==1.2.14
dirtyjson==1.0.8
distro==1.9.0
executing==2.0.1
fastjsonschema==2.20.0
fqdn==1.5.1
frozenlist==1.4.1
fsspec==2024.6.1
gitdb==4.0.11
GitPython==3.1.43
greenlet==3.0.3
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
idna==3.7
ipykernel==6.29.5
ipython==8.26.0
isoduration==20.11.0
jedi==0.19.1
Jinja2==3.1.4
joblib==1.4.2
json5==0.9.25
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.2
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_terminals==0.5.3
jupyterlab==4.2.4
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
llama-index==0.10.15
llama-index-agent-openai==0.1.7
llama-index-cli==0.1.12
llama-index-core==0.10.56
llama-index-embeddings-openai==0.1.11
llama-index-indices-managed-llama-cloud==0.1.6
llama-index-legacy==0.9.48
llama-index-llms-openai==0.1.26
llama-index-multi-modal-llms-openai==0.1.8
llama-index-program-openai==0.1.6
llama-index-question-gen-openai==0.1.3
llama-index-readers-file==0.1.30
llama-index-readers-llama-parse==0.1.6
llama-parse==0.4.9
llamaindex-py-client==0.1.19
markdown-it-py==3.0.0
MarkupSafe==2.1.5
marshmallow==3.21.3
matplotlib-inline==0.1.7
mdurl==0.1.2
mistune==3.0.2
multidict==6.0.5
mypy-extensions==1.0.0
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
networkx==3.3
nltk==3.8.1
notebook==7.2.1
notebook_shim==0.2.4
numpy==1.26.4
openai==1.36.1
overrides==7.7.0
packaging==24.1
pandas==2.2.2
pandocfilters==1.5.1
parso==0.8.4
pexpect==4.9.0
pillow==10.4.0
platformdirs==4.2.2
prometheus_client==0.20.0
prompt_toolkit==3.0.47
protobuf==5.27.2
psutil==6.0.0
ptyprocess==0.7.0
pure_eval==0.2.3
pyarrow==17.0.0
pycparser==2.22
pydantic==2.8.2
pydantic_core==2.20.1
pydeck==0.9.1
Pygments==2.18.0
pypdf==4.3.1
python-dateutil==2.9.0.post0
python-json-logger==2.0.7
pytz==2024.1
PyYAML==6.0.1
pyzmq==26.0.3
referencing==0.35.1
regex==2024.5.15
requests==2.32.3
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.7.1
rpds-py==0.19.0
Send2Trash==1.8.3
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
soupsieve==2.5
SQLAlchemy==2.0.31
stack-data==0.6.3
streamlit==1.36.0
striprtf==0.0.26
tenacity==8.5.0
terminado==0.18.1
tiktoken==0.7.0
tinycss2==1.3.0
toml==0.10.2
toolz==0.12.1
tornado==6.4.1
tqdm==4.66.4
traitlets==5.14.3
types-python-dateutil==2.9.0.20240316
typing-inspect==0.9.0
typing_extensions==4.12.2
tzdata==2024.1
uri-template==1.3.0
urllib3==2.2.2
watchdog==4.0.1
wcwidth==0.2.13
webcolors==24.6.0
webencodings==0.5.1
websocket-client==1.8.0
wrapt==1.16.0
yarl==1.9.4