mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
Merge branch 'main' into chat-history
This commit is contained in:
commit
16dea76691
5 changed files with 55 additions and 12 deletions
|
@ -13,7 +13,7 @@ It also has features that [help GPT-4 understand and modify larger codebases](ht
|
|||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://discord.gg/SqzfE6bw">
|
||||
<a href="https://discord.gg/Tv2uQnR88V">
|
||||
<img src="https://img.shields.io/badge/Join-Discord-blue.svg"/>
|
||||
</a>
|
||||
</p>
|
||||
|
|
|
@ -746,11 +746,11 @@ class Coder:
|
|||
|
||||
# Check if the file is already in the repo
|
||||
if self.repo:
|
||||
tracked_files = set(self.get_tracked_files())
|
||||
tracked_files = set(self.repo.get_tracked_files())
|
||||
relative_fname = self.get_rel_fname(full_path)
|
||||
if relative_fname not in tracked_files and self.io.confirm_ask(f"Add {path} to git?"):
|
||||
if not self.dry_run:
|
||||
self.repo.git.add(full_path)
|
||||
self.repo.repo.git.add(full_path)
|
||||
|
||||
if write_content:
|
||||
self.io.write_text(full_path, write_content)
|
||||
|
|
|
@ -135,33 +135,38 @@ class Commands:
|
|||
self.io.tool_output()
|
||||
|
||||
width = 8
|
||||
cost_width = 7
|
||||
|
||||
def fmt(v):
|
||||
return format(int(v), ",").rjust(width)
|
||||
|
||||
col_width = max(len(row[1]) for row in res)
|
||||
|
||||
cost_pad = " " * cost_width
|
||||
total = 0
|
||||
total_cost = 0.0
|
||||
for tk, msg, tip in res:
|
||||
total += tk
|
||||
cost = tk * (self.coder.main_model.prompt_price / 1000)
|
||||
total_cost += cost
|
||||
msg = msg.ljust(col_width)
|
||||
self.io.tool_output(f"{fmt(tk)} {msg} {tip}")
|
||||
self.io.tool_output(f"${cost:5.2f} {fmt(tk)} {msg} {tip}")
|
||||
|
||||
self.io.tool_output("=" * width)
|
||||
self.io.tool_output(f"{fmt(total)} tokens total")
|
||||
self.io.tool_output("=" * (width + cost_width + 1))
|
||||
self.io.tool_output(f"${total_cost:5.2f} {fmt(total)} tokens total")
|
||||
|
||||
limit = self.coder.main_model.max_context_tokens
|
||||
remaining = limit - total
|
||||
if remaining > 1024:
|
||||
self.io.tool_output(f"{fmt(remaining)} tokens remaining in context window")
|
||||
self.io.tool_output(f"{cost_pad}{fmt(remaining)} tokens remaining in context window")
|
||||
elif remaining > 0:
|
||||
self.io.tool_error(
|
||||
f"{fmt(remaining)} tokens remaining in context window (use /drop or /clear to make"
|
||||
" space)"
|
||||
f"{cost_pad}{fmt(remaining)} tokens remaining in context window (use /drop or"
|
||||
" /clear to make space)"
|
||||
)
|
||||
else:
|
||||
self.io.tool_error(f"{fmt(remaining)} tokens remaining, window exhausted!")
|
||||
self.io.tool_output(f"{fmt(limit)} tokens max context window size")
|
||||
self.io.tool_error(f"{cost_pad}{fmt(remaining)} tokens remaining, window exhausted!")
|
||||
self.io.tool_output(f"{cost_pad}{fmt(limit)} tokens max context window size")
|
||||
|
||||
def cmd_undo(self, args):
|
||||
"Undo the last git commit if it was done by aider"
|
||||
|
|
|
@ -4,7 +4,13 @@ import json
|
|||
import backoff
|
||||
import openai
|
||||
import requests
|
||||
from openai.error import APIError, RateLimitError, ServiceUnavailableError, Timeout
|
||||
from openai.error import (
|
||||
APIConnectionError,
|
||||
APIError,
|
||||
RateLimitError,
|
||||
ServiceUnavailableError,
|
||||
Timeout,
|
||||
)
|
||||
|
||||
|
||||
@backoff.on_exception(
|
||||
|
@ -14,6 +20,7 @@ from openai.error import APIError, RateLimitError, ServiceUnavailableError, Time
|
|||
APIError,
|
||||
ServiceUnavailableError,
|
||||
RateLimitError,
|
||||
APIConnectionError,
|
||||
requests.exceptions.ConnectionError,
|
||||
),
|
||||
max_tries=10,
|
||||
|
|
|
@ -22,6 +22,37 @@ class TestCoder(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
self.patcher.stop()
|
||||
|
||||
def test_allowed_to_edit(self):
|
||||
with GitTemporaryDirectory():
|
||||
repo = git.Repo(Path.cwd())
|
||||
fname = Path("foo.txt")
|
||||
fname.touch()
|
||||
repo.git.add(str(fname))
|
||||
repo.git.commit("-m", "init")
|
||||
|
||||
io = InputOutput(yes=True)
|
||||
# Initialize the Coder object with the mocked IO and mocked repo
|
||||
coder = Coder.create(models.GPT4, None, io, fnames=["foo.txt"])
|
||||
|
||||
self.assertTrue(coder.allowed_to_edit("foo.txt"))
|
||||
self.assertTrue(coder.allowed_to_edit("new.txt"))
|
||||
|
||||
def test_allowed_to_edit_no(self):
|
||||
with GitTemporaryDirectory():
|
||||
repo = git.Repo(Path.cwd())
|
||||
fname = Path("foo.txt")
|
||||
fname.touch()
|
||||
repo.git.add(str(fname))
|
||||
repo.git.commit("-m", "init")
|
||||
|
||||
# say NO
|
||||
io = InputOutput(yes=False)
|
||||
|
||||
coder = Coder.create(models.GPT4, None, io, fnames=["foo.txt"])
|
||||
|
||||
self.assertTrue(coder.allowed_to_edit("foo.txt"))
|
||||
self.assertFalse(coder.allowed_to_edit("new.txt"))
|
||||
|
||||
def test_get_last_modified(self):
|
||||
# Mock the IO object
|
||||
mock_io = MagicMock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue