mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
offer to install aider[hf]
This commit is contained in:
parent
4e07710d4e
commit
f688c18b65
8 changed files with 60 additions and 14 deletions
|
@ -7,7 +7,7 @@ from pathlib import Path
|
||||||
import git
|
import git
|
||||||
|
|
||||||
from aider import models, prompts, voice
|
from aider import models, prompts, voice
|
||||||
from aider.help import Help
|
from aider.help import Help, PipInstallHF
|
||||||
from aider.llm import litellm
|
from aider.llm import litellm
|
||||||
from aider.scrape import Scraper
|
from aider.scrape import Scraper
|
||||||
from aider.utils import is_image_file
|
from aider.utils import is_image_file
|
||||||
|
@ -654,7 +654,14 @@ class Commands:
|
||||||
from aider.coders import Coder
|
from aider.coders import Coder
|
||||||
|
|
||||||
if not self.help:
|
if not self.help:
|
||||||
self.help = Help()
|
try:
|
||||||
|
self.help = Help()
|
||||||
|
except PipInstallHF as err:
|
||||||
|
self.io.tool_error(str(err))
|
||||||
|
if self.io.confirm_ask("Run pip install?", default="y"):
|
||||||
|
self.help = Help(pip_install=True)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
coder = Coder.create(
|
coder = Coder.create(
|
||||||
main_model=self.coder.main_model,
|
main_model=self.coder.main_model,
|
||||||
|
|
|
@ -6,7 +6,7 @@ from pathlib import Path
|
||||||
|
|
||||||
import importlib_resources
|
import importlib_resources
|
||||||
|
|
||||||
from aider import __version__
|
from aider import __version__, utils
|
||||||
from aider.dump import dump # noqa: F401
|
from aider.dump import dump # noqa: F401
|
||||||
from aider.help_pats import exclude_website_pats
|
from aider.help_pats import exclude_website_pats
|
||||||
|
|
||||||
|
@ -87,10 +87,35 @@ def get_index():
|
||||||
return 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:
|
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.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"
|
os.environ["TOKENIZERS_PARALLELISM"] = "true"
|
||||||
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -176,3 +178,18 @@ def split_chat_history_markdown(text, include_tool=False):
|
||||||
messages = [m for m in messages if m["role"] != "tool"]
|
messages = [m for m in messages if m["role"] != "tool"]
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
|
def pip_install(args):
|
||||||
|
cmd = [
|
||||||
|
sys.executable,
|
||||||
|
"-m",
|
||||||
|
"pip",
|
||||||
|
"install",
|
||||||
|
]
|
||||||
|
cmd += args
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.run(cmd)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error running pip download: {e}")
|
||||||
|
|
|
@ -7,6 +7,7 @@ RUN apt-get update && \
|
||||||
COPY . /aider
|
COPY . /aider
|
||||||
|
|
||||||
RUN pip install --no-cache-dir /aider
|
RUN pip install --no-cache-dir /aider
|
||||||
|
RUN pip install --no-cache-dir /aider[hf] --extra-index-url https://download.pytorch.org/whl/cpu
|
||||||
|
|
||||||
# Final stage
|
# Final stage
|
||||||
FROM python:3.10-slim
|
FROM python:3.10-slim
|
||||||
|
|
|
@ -4,3 +4,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
llama-index-embeddings-huggingface
|
llama-index-embeddings-huggingface
|
||||||
|
|
||||||
|
# To retain python 3.9 compatibility
|
||||||
|
scipy<1.14
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ scikit-learn==1.5.1
|
||||||
# via sentence-transformers
|
# via sentence-transformers
|
||||||
scipy==1.13.1
|
scipy==1.13.1
|
||||||
# via
|
# via
|
||||||
# -c requirements.txt
|
# -r requirements-hf.in
|
||||||
# scikit-learn
|
# scikit-learn
|
||||||
# sentence-transformers
|
# sentence-transformers
|
||||||
sentence-transformers==3.0.1
|
sentence-transformers==3.0.1
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
configargparse
|
configargparse
|
||||||
GitPython
|
GitPython
|
||||||
openai
|
|
||||||
tiktoken
|
|
||||||
jsonschema
|
jsonschema
|
||||||
rich
|
rich
|
||||||
prompt_toolkit
|
prompt_toolkit
|
||||||
|
@ -37,9 +35,6 @@ networkx<3.3
|
||||||
# v0.22.2 seems to break tree-sitter-languages?
|
# v0.22.2 seems to break tree-sitter-languages?
|
||||||
tree-sitter==0.21.3
|
tree-sitter==0.21.3
|
||||||
|
|
||||||
# To retain python 3.9 compatibility
|
|
||||||
scipy<1.14
|
|
||||||
|
|
||||||
# GitHub Release action failing on "KeyError: 'home-page'"
|
# GitHub Release action failing on "KeyError: 'home-page'"
|
||||||
# https://github.com/pypa/twine/blob/6fbf880ee60915cf1666348c4bdd78a10415f2ac/twine/__init__.py#L40
|
# https://github.com/pypa/twine/blob/6fbf880ee60915cf1666348c4bdd78a10415f2ac/twine/__init__.py#L40
|
||||||
# Uses importlib-metadata
|
# Uses importlib-metadata
|
||||||
|
|
|
@ -196,7 +196,6 @@ numpy==1.26.4
|
||||||
# pandas
|
# pandas
|
||||||
# pyarrow
|
# pyarrow
|
||||||
# pydeck
|
# pydeck
|
||||||
# scipy
|
|
||||||
# streamlit
|
# streamlit
|
||||||
openai==1.35.10
|
openai==1.35.10
|
||||||
# via
|
# via
|
||||||
|
@ -310,8 +309,6 @@ rpds-py==0.18.1
|
||||||
# referencing
|
# referencing
|
||||||
rsa==4.9
|
rsa==4.9
|
||||||
# via google-auth
|
# via google-auth
|
||||||
scipy==1.13.1
|
|
||||||
# via -r requirements.in
|
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
# via python-dateutil
|
# via python-dateutil
|
||||||
smmap==5.0.1
|
smmap==5.0.1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue