offer to install aider[hf]

This commit is contained in:
Paul Gauthier 2024-07-10 16:20:06 +01:00
parent 4e07710d4e
commit f688c18b65
8 changed files with 60 additions and 14 deletions

View file

@ -6,7 +6,7 @@ from pathlib import Path
import importlib_resources
from aider import __version__
from aider import __version__, utils
from aider.dump import dump # noqa: F401
from aider.help_pats import exclude_website_pats
@ -87,10 +87,35 @@ def get_index():
return index
class PipInstallHF(Exception):
pass
pip_install_cmd = [
"aider[hf]",
"--extra-index-url",
"https://download.pytorch.org/whl/cpu",
]
pip_install_error = f"""
To use interactive /help you need to install HuggingFace embeddings:
pip install {' '.join(pip_install_cmd)}
"""
class Help:
def __init__(self):
def __init__(self, pip_install=False):
if pip_install:
utils.pip_install(pip_install_cmd)
from llama_index.core import Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
try:
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
except ImportError:
raise PipInstallHF(pip_install_error)
os.environ["TOKENIZERS_PARALLELISM"] = "true"
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")