rename simple_send_with_retries -> send_with_retries

This commit is contained in:
Paul Gauthier 2024-08-02 10:35:10 -03:00
parent b543dda664
commit d619edf6e9
5 changed files with 19 additions and 26 deletions

View file

@ -2,7 +2,7 @@ import argparse
from aider import models, prompts
from aider.dump import dump # noqa: F401
from aider.sendchat import simple_send_with_retries
from aider.sendchat import send_with_retries
class ChatSummary:
@ -108,7 +108,7 @@ class ChatSummary:
for model in self.models:
try:
summary = simple_send_with_retries(model.name, summarize_messages)
summary = send_with_retries(model.name, summarize_messages)
if summary is not None:
summary = prompts.summary_prefix + summary
return [dict(role="user", content=summary)]

View file

@ -6,7 +6,7 @@ import git
import pathspec
from aider import prompts, utils
from aider.sendchat import simple_send_with_retries
from aider.sendchat import send_with_retries
from .dump import dump # noqa: F401
@ -170,7 +170,7 @@ class GitRepo:
]
for model in self.models:
commit_message = simple_send_with_retries(model.name, messages)
commit_message = send_with_retries(model.name, messages)
if commit_message:
break

View file

@ -66,7 +66,13 @@ def lazy_litellm_retry_decorator(func):
@lazy_litellm_retry_decorator
def send_with_retries(
model_name, messages, functions, stream, temperature=0, extra_headers=None, max_tokens=None
model_name,
messages,
functions=None,
stream=False,
temperature=0,
extra_headers=None,
max_tokens=None,
):
from aider.llm import litellm
@ -99,16 +105,3 @@ def send_with_retries(
CACHE[key] = res
return hash_object, res
def simple_send_with_retries(model_name, messages):
try:
_hash, response = send_with_retries(
model_name=model_name,
messages=messages,
functions=None,
stream=False,
)
return response.choices[0].message.content
except (AttributeError, litellm.exceptions.BadRequestError):
return

View file

@ -34,7 +34,7 @@ class TestChatSummary(TestCase):
tokenized = self.chat_summary.tokenize(messages)
self.assertEqual(tokenized, [(2, messages[0]), (2, messages[1])])
@mock.patch("aider.history.simple_send_with_retries")
@mock.patch("aider.history.send_with_retries")
def test_summarize_all(self, mock_send):
mock_send.return_value = "This is a summary"
messages = [
@ -69,7 +69,7 @@ class TestChatSummary(TestCase):
self.assertGreater(len(result), 0)
self.assertLessEqual(len(result), len(messages))
@mock.patch("aider.history.simple_send_with_retries")
@mock.patch("aider.history.send_with_retries")
def test_fallback_to_second_model(self, mock_send):
mock_model1 = mock.Mock(spec=Model)
mock_model1.name = "gpt-4"

View file

@ -106,7 +106,7 @@ class TestRepo(unittest.TestCase):
diffs = git_repo.diff_commits(False, "HEAD~1", "HEAD")
self.assertIn("two", diffs)
@patch("aider.repo.simple_send_with_retries")
@patch("aider.repo.send_with_retries")
def test_get_commit_message(self, mock_send):
mock_send.side_effect = ["", "a good commit message"]
@ -120,14 +120,14 @@ class TestRepo(unittest.TestCase):
# Assert that the returned message is the expected one from the second model
self.assertEqual(result, "a good commit message")
# Check that simple_send_with_retries was called twice
# Check that send_with_retries was called twice
self.assertEqual(mock_send.call_count, 2)
# Check that it was called with the correct model names
mock_send.assert_any_call(model1.name, mock_send.call_args[0][1])
mock_send.assert_any_call(model2.name, mock_send.call_args[0][1])
@patch("aider.repo.simple_send_with_retries")
@patch("aider.repo.send_with_retries")
def test_get_commit_message_strip_quotes(self, mock_send):
mock_send.return_value = '"a good commit message"'
@ -138,7 +138,7 @@ class TestRepo(unittest.TestCase):
# Assert that the returned message is the expected one
self.assertEqual(result, "a good commit message")
@patch("aider.repo.simple_send_with_retries")
@patch("aider.repo.send_with_retries")
def test_get_commit_message_no_strip_unmatched_quotes(self, mock_send):
mock_send.return_value = 'a good "commit message"'
@ -149,7 +149,7 @@ class TestRepo(unittest.TestCase):
# Assert that the returned message is the expected one
self.assertEqual(result, 'a good "commit message"')
@patch("aider.repo.simple_send_with_retries")
@patch("aider.repo.send_with_retries")
def test_get_commit_message_with_custom_prompt(self, mock_send):
mock_send.return_value = "Custom commit message"
custom_prompt = "Generate a commit message in the style of Shakespeare"
@ -349,7 +349,7 @@ class TestRepo(unittest.TestCase):
fnames = git_repo.get_tracked_files()
self.assertIn(str(fname), fnames)
@patch("aider.repo.simple_send_with_retries")
@patch("aider.repo.send_with_retries")
def test_noop_commit(self, mock_send):
mock_send.return_value = '"a good commit message"'