Merge branch 'main' into slim-playwright

This commit is contained in:
Paul Gauthier 2024-07-14 18:29:39 +01:00
commit a3a4113331
27 changed files with 470 additions and 310 deletions

View file

@ -91,7 +91,7 @@ class YamlHelpFormatter(argparse.HelpFormatter):
def _format_text(self, text):
return """
##########################################################
# Sample .aider.conf.yaml
# Sample .aider.conf.yml
# This file lists *all* the valid configuration entries.
# Place in your home dir, or at the root of your git repo.
##########################################################

View file

@ -7,7 +7,7 @@ from pathlib import Path
import git
from aider import models, prompts, voice
from aider.help import Help, PipInstallHF
from aider.help import Help, install_help_extra
from aider.llm import litellm
from aider.scrape import Scraper
from aider.utils import is_image_file
@ -662,19 +662,12 @@ class Commands:
from aider.coders import Coder
if not self.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"):
try:
self.help = Help(pip_install=True)
except PipInstallHF:
pass
res = install_help_extra(self.io)
if not res:
self.io.tool_error("Unable to initialize interactive help.")
return
if not self.help:
self.io.tool_error("Unable to initialize interactive help.")
return
self.help = Help()
coder = Coder.create(
main_model=self.coder.main_model,

View file

@ -13,6 +13,21 @@ from aider.help_pats import exclude_website_pats
warnings.simplefilter("ignore", category=FutureWarning)
def install_help_extra(io):
pip_install_cmd = [
"aider-chat[hf-embed]",
"--extra-index-url",
"https://download.pytorch.org/whl/cpu",
]
res = utils.check_pip_install_extra(
io,
"llama_index.embeddings.huggingface",
"To use interactive /help you need to install HuggingFace embeddings",
pip_install_cmd,
)
return res
def get_package_files():
for path in importlib_resources.files("aider.website").iterdir():
if path.is_file():
@ -87,35 +102,10 @@ def get_index():
return index
class PipInstallHF(Exception):
pass
pip_install_cmd = [
"aider-chat[hf-embed]",
"--extra-index-url",
"https://download.pytorch.org/whl/cpu",
]
pip_install_error = """
To use interactive /help you need to install HuggingFace embeddings:
{cmd}
""" # noqa: E231
class Help:
def __init__(self, pip_install=False):
cmd = utils.get_pip_install(pip_install_cmd)
if pip_install:
utils.run_install(cmd)
try:
from llama_index.core import Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
except ImportError:
raise PipInstallHF(pip_install_error.format(cmd=' '.join(cmd)))
def __init__(self):
from llama_index.core import Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
os.environ["TOKENIZERS_PARALLELISM"] = "true"
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")

View file

@ -148,6 +148,15 @@ def scrub_sensitive_info(args, text):
return text
def check_streamlit_install(io):
return utils.check_pip_install_extra(
io,
"streamlit",
"You need to install the aider browser feature",
["aider-chat[browser]"],
)
def launch_gui(args):
from streamlit.web import cli
@ -318,10 +327,6 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
litellm.client_session = httpx.Client(verify=False)
if args.gui and not return_coder:
launch_gui(argv)
return
if args.dark_mode:
args.user_input_color = "#32FF32"
args.tool_error_color = "#FF3333"
@ -355,6 +360,12 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
editingmode=editing_mode,
)
if args.gui and not return_coder:
if not check_streamlit_install(io):
return
launch_gui(argv)
return
for fname in loaded_dotenvs:
io.tool_output(f"Loaded {fname}")

View file

@ -58,6 +58,7 @@ ANTHROPIC_MODELS = [ln.strip() for ln in ANTHROPIC_MODELS.splitlines() if ln.str
@dataclass
class ModelSettings:
# Model class needs to have each of these as well
name: str
edit_format: str
weak_model_name: Optional[str] = None
@ -360,6 +361,7 @@ class Model:
lazy = False
reminder_as_sys_msg = False
examples_as_sys_msg = False
can_prefill = False
max_chat_history_tokens = 1024
weak_model = None
@ -652,11 +654,7 @@ def sanity_check_model(io, model):
if possible_matches:
io.tool_output("Did you mean one of these?")
for match in possible_matches:
fq, m = match
if fq == m:
io.tool_output(f"- {m}")
else:
io.tool_output(f"- {m} ({fq})")
io.tool_output(f"- {model}")
if show:
io.tool_output(f"For more info, see: {urls.model_warnings}\n")
@ -665,7 +663,7 @@ def sanity_check_model(io, model):
def fuzzy_match_models(name):
name = name.lower()
chat_models = []
chat_models = set()
for model, attrs in litellm.model_cost.items():
model = model.lower()
if attrs.get("mode") != "chat":
@ -677,8 +675,10 @@ def fuzzy_match_models(name):
else:
fq_model = provider + model
chat_models.append((fq_model, model))
chat_models.add(fq_model)
chat_models.add(model)
chat_models = sorted(chat_models)
# exactly matching model
# matching_models = [
# (fq,m) for fq,m in chat_models
@ -688,19 +688,14 @@ def fuzzy_match_models(name):
# return matching_models
# Check for model names containing the name
matching_models = [(fq, m) for fq, m in chat_models if name in fq]
matching_models = [m for m in chat_models if name in m]
if matching_models:
return matching_models
# Check for slight misspellings
models = [m for fq, m in chat_models]
models = list(chat_models)
matching_models = difflib.get_close_matches(name, models, n=3, cutoff=0.8)
if matching_models:
return list(zip(matching_models, matching_models))
fq_models = [fq for fq, m in chat_models]
matching_models = difflib.get_close_matches(name, fq_models, n=3, cutoff=0.8)
return list(zip(matching_models, matching_models))
return sorted(matching_models)
def print_matching_models(io, search):
@ -708,8 +703,7 @@ def print_matching_models(io, search):
if matches:
io.tool_output(f'Models which match "{search}":')
for model in matches:
fq, m = model
io.tool_output(f"- {fq}")
io.tool_output(f"- {model}")
else:
io.tool_output(f'No models match "{search}".')

View file

@ -1,11 +1,13 @@
import unittest
from aider.help import Help
from aider.help import Help, install_help_extra
from aider.io import InputOutput
class TestHelp(unittest.TestCase):
def setUp(self):
Help(pip_install=True)
io = InputOutput(yes=True)
install_help_extra(io)
def test_init(self):
help_inst = Help()

View file

@ -1,8 +1,8 @@
import itertools
import os
import subprocess
import sys
import tempfile
import itertools
from pathlib import Path
import git
@ -182,7 +182,6 @@ def split_chat_history_markdown(text, include_tool=False):
def get_pip_install(args):
cmd = [
sys.executable,
"-m",
@ -192,14 +191,22 @@ def get_pip_install(args):
cmd += args
return cmd
def run_install(cmd):
print()
print("Installing: ", ' '.join(cmd))
print("Installing: ", " ".join(cmd))
try:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True)
output = []
spinner = itertools.cycle(['', '', '', '', '', '', '', '', '', ''])
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
universal_newlines=True,
)
spinner = itertools.cycle(["", "", "", "", "", "", "", "", "", ""])
for line in process.stdout:
output.append(line)
@ -208,14 +215,45 @@ def run_install(cmd):
return_code = process.wait()
if return_code == 0:
print("\rInstallation completed successfully.")
print("\rInstallation complete.")
print()
return True
return True, output
except subprocess.CalledProcessError as e:
print(f"\nError running pip install: {e}")
print("\nInstallation failed.\n")
return False, output
def check_pip_install_extra(io, module, prompt, pip_install_cmd):
try:
__import__(module)
return True
except (ImportError, ModuleNotFoundError):
pass
cmd = get_pip_install(pip_install_cmd)
text = f"{prompt}:\n\n{' '.join(cmd)}\n"
io.tool_error(text)
if not io.confirm_ask("Run pip install?", default="y"):
return
success, output = run_install(cmd)
if not success:
return
try:
__import__(module)
return True
except (ImportError, ModuleNotFoundError):
pass
for line in output:
print(line)
print()
print(f"Failed to install {pip_install_cmd[0]}")

View file

@ -29,9 +29,9 @@ def check_version(io, just_check=False):
except Exception as err:
io.tool_error(f"Error checking pypi for new version: {err}")
return False
fname.parent.mkdir(parents=True, exist_ok=True)
fname.touch()
finally:
fname.parent.mkdir(parents=True, exist_ok=True)
fname.touch()
if just_check:
return is_update_available
@ -49,7 +49,8 @@ Newer aider version v{latest_version} is available. To upgrade, run:
io.tool_error(text)
if io.confirm_ask("Run pip install?"):
if utils.run_install(cmd):
success, _output = utils.run_install(cmd)
if success:
io.tool_output("Re-run aider to use new version.")
sys.exit()

View file

@ -85,8 +85,12 @@ class Voice:
self.start_time = time.time()
with self.sd.InputStream(samplerate=sample_rate, channels=1, callback=self.callback):
prompt(self.get_prompt, refresh_interval=0.1)
try:
with self.sd.InputStream(samplerate=sample_rate, channels=1, callback=self.callback):
prompt(self.get_prompt, refresh_interval=0.1)
except self.sd.PortAudioError as err:
print(err)
return
with sf.SoundFile(filename, mode="x", samplerate=sample_rate, channels=1) as file:
while not self.q.empty():

View file

@ -681,4 +681,26 @@
versions: 0.41.1-dev
seconds_per_case: 7.1
total_cost: 0.1946
- dirname: 2024-07-09-10-12-27--gemma2:27b-instruct-q8_0
test_cases: 133
model: gemma2:27b-instruct-q8_0
edit_format: whole
commit_hash: f9d96ac-dirty
pass_rate_1: 31.6
pass_rate_2: 36.1
percent_cases_well_formed: 100.0
error_outputs: 35
num_malformed_responses: 0
num_with_malformed_responses: 0
user_asks: 35
lazy_comments: 2
syntax_errors: 0
indentation_errors: 0
exhausted_context_windows: 0
test_timeouts: 3
command: aider --model ollama/gemma2:27b-instruct-q8_0
date: 2024-07-09
versions: 0.43.0
seconds_per_case: 101.3
total_cost: 0.0000

View file

@ -1,5 +1,5 @@
##########################################################
# Sample .aider.conf.yaml
# Sample .aider.conf.yml
# This file lists *all* the valid configuration entries.
# Place in your home dir, or at the root of your git repo.
##########################################################
@ -207,10 +207,10 @@
#version:
## Check for updates and return status in the exit code
#check-update: false
#just-check-update: false
## Skips checking for the update when the program runs
#skip-check-update: false
## Check for new aider versions on launch
#check-update: true
## Apply the changes from the given file instead of running the chat (debug)
#apply:

View file

@ -208,10 +208,10 @@
#AIDER_VOICE_LANGUAGE=en
## Check for updates and return status in the exit code
#AIDER_CHECK_UPDATE=false
#AIDER_JUST_CHECK_UPDATE=false
## Skips checking for the update when the program runs
#AIDER_SKIP_CHECK_UPDATE=false
## Check for new aider versions on launch
#AIDER_CHECK_UPDATE=true
## Apply the changes from the given file instead of running the chat (debug)
#AIDER_APPLY=

View file

@ -38,7 +38,7 @@ cog.outl("```")
]]]-->
```
##########################################################
# Sample .aider.conf.yaml
# Sample .aider.conf.yml
# This file lists *all* the valid configuration entries.
# Place in your home dir, or at the root of your git repo.
##########################################################
@ -246,10 +246,10 @@ cog.outl("```")
#version:
## Check for updates and return status in the exit code
#check-update: false
#just-check-update: false
## Skips checking for the update when the program runs
#skip-check-update: false
## Check for new aider versions on launch
#check-update: true
## Apply the changes from the given file instead of running the chat (debug)
#apply:

View file

@ -250,10 +250,10 @@ cog.outl("```")
#AIDER_VOICE_LANGUAGE=en
## Check for updates and return status in the exit code
#AIDER_CHECK_UPDATE=false
#AIDER_JUST_CHECK_UPDATE=false
## Skips checking for the update when the program runs
#AIDER_SKIP_CHECK_UPDATE=false
## Check for new aider versions on launch
#AIDER_CHECK_UPDATE=true
## Apply the changes from the given file instead of running the chat (debug)
#AIDER_APPLY=

View file

@ -51,10 +51,11 @@ usage: aider [-h] [--openai-api-key] [--anthropic-api-key] [--model]
[--dry-run | --no-dry-run] [--commit] [--lint]
[--lint-cmd] [--auto-lint | --no-auto-lint]
[--test-cmd] [--auto-test | --no-auto-test] [--test]
[--vim] [--voice-language] [--version] [--check-update]
[--skip-check-update] [--apply] [--yes] [-v]
[--show-repo-map] [--show-prompts] [--exit] [--message]
[--message-file] [--encoding] [-c] [--gui]
[--vim] [--voice-language] [--version]
[--just-check-update]
[--check-update | --no-check-update] [--apply] [--yes]
[-v] [--show-repo-map] [--show-prompts] [--exit]
[--message] [--message-file] [--encoding] [-c] [--gui]
```
@ -396,15 +397,18 @@ Environment variable: `AIDER_VOICE_LANGUAGE`
### `--version`
Show the version number and exit
### `--check-update`
### `--just-check-update`
Check for updates and return status in the exit code
Default: False
Environment variable: `AIDER_CHECK_UPDATE`
Environment variable: `AIDER_JUST_CHECK_UPDATE`
### `--skip-check-update`
Skips checking for the update when the program runs
Default: False
Environment variable: `AIDER_SKIP_CHECK_UPDATE`
### `--check-update`
Check for new aider versions on launch
Default: True
Environment variable: `AIDER_CHECK_UPDATE`
Aliases:
- `--check-update`
- `--no-check-update`
### `--apply FILE`
Apply the changes from the given file instead of running the chat (debug)

View file

@ -71,6 +71,7 @@ cog.out(''.join(lines))
- DATABRICKS_API_KEY
- DEEPINFRA_API_KEY
- DEEPSEEK_API_KEY
- EMPOWER_API_KEY
- FIREWORKSAI_API_KEY
- FIREWORKS_AI_API_KEY
- FIREWORKS_API_KEY