mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
fix: handle exceptions during index loading and recreate cache if necessary in aider/help.py
This commit is contained in:
parent
a230fa10b3
commit
cb1f6f2e3a
1 changed files with 33 additions and 19 deletions
|
@ -58,6 +58,9 @@ def fname_to_url(filepath):
|
|||
return docid
|
||||
|
||||
|
||||
import json
|
||||
import shutil
|
||||
|
||||
def get_index():
|
||||
from llama_index.core import (
|
||||
Document,
|
||||
|
@ -69,35 +72,46 @@ def get_index():
|
|||
|
||||
dname = Path.home() / ".aider" / "caches" / ("help." + __version__)
|
||||
|
||||
index = None
|
||||
|
||||
if dname.exists():
|
||||
try:
|
||||
storage_context = StorageContext.from_defaults(
|
||||
persist_dir=dname,
|
||||
)
|
||||
index = load_index_from_storage(storage_context)
|
||||
except (OSError, json.JSONDecodeError):
|
||||
shutil.rmtree(dname)
|
||||
pass
|
||||
storage_context = StorageContext.from_defaults(
|
||||
persist_dir=dname,
|
||||
)
|
||||
index = load_index_from_storage(storage_context)
|
||||
else:
|
||||
if index is None:
|
||||
parser = MarkdownNodeParser()
|
||||
|
||||
nodes = []
|
||||
for fname in get_package_files():
|
||||
fname = Path(fname)
|
||||
if any(fname.match(pat) for pat in exclude_website_pats):
|
||||
continue
|
||||
nodes = []
|
||||
for fname in get_package_files():
|
||||
fname = Path(fname)
|
||||
if any(fname.match(pat) for pat in exclude_website_pats):
|
||||
continue
|
||||
|
||||
doc = Document(
|
||||
text=importlib_resources.files("aider.website")
|
||||
.joinpath(fname)
|
||||
.read_text(encoding="utf-8"),
|
||||
metadata=dict(
|
||||
filename=fname.name,
|
||||
extension=fname.suffix,
|
||||
url=fname_to_url(str(fname)),
|
||||
),
|
||||
)
|
||||
nodes += parser.get_nodes_from_documents([doc])
|
||||
doc = Document(
|
||||
text=importlib_resources.files("aider.website")
|
||||
.joinpath(fname)
|
||||
.read_text(encoding="utf-8"),
|
||||
metadata=dict(
|
||||
filename=fname.name,
|
||||
extension=fname.suffix,
|
||||
url=fname_to_url(str(fname)),
|
||||
),
|
||||
)
|
||||
nodes += parser.get_nodes_from_documents([doc])
|
||||
|
||||
index = VectorStoreIndex(nodes, show_progress=True)
|
||||
dname.parent.mkdir(parents=True, exist_ok=True)
|
||||
index.storage_context.persist(dname)
|
||||
index = VectorStoreIndex(nodes, show_progress=True)
|
||||
dname.parent.mkdir(parents=True, exist_ok=True)
|
||||
index.storage_context.persist(dname)
|
||||
|
||||
return index
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue