mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 04:35:00 +00:00
Merge branch 'main' into call-graph
This commit is contained in:
commit
106eab7a7a
2 changed files with 21 additions and 25 deletions
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import traceback
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import backoff
|
||||||
import git
|
import git
|
||||||
import openai
|
import openai
|
||||||
import requests
|
import requests
|
||||||
|
@ -393,23 +393,19 @@ class Coder:
|
||||||
|
|
||||||
return prompts.added_files.format(fnames=", ".join(mentioned_rel_fnames))
|
return prompts.added_files.format(fnames=", ".join(mentioned_rel_fnames))
|
||||||
|
|
||||||
|
@backoff.on_exception(
|
||||||
|
backoff.expo,
|
||||||
|
(RateLimitError, requests.exceptions.ConnectionError),
|
||||||
|
max_tries=5,
|
||||||
|
on_backoff=lambda details: print(f"Retry in {details['wait']} seconds."),
|
||||||
|
)
|
||||||
def send_with_retries(self, model, messages):
|
def send_with_retries(self, model, messages):
|
||||||
while True:
|
return openai.ChatCompletion.create(
|
||||||
try:
|
model=model,
|
||||||
return openai.ChatCompletion.create(
|
messages=messages,
|
||||||
model=model,
|
temperature=0,
|
||||||
messages=messages,
|
stream=True,
|
||||||
temperature=0,
|
)
|
||||||
stream=True,
|
|
||||||
)
|
|
||||||
except RateLimitError as err:
|
|
||||||
self.io.tool_error(f"RateLimitError: {err}")
|
|
||||||
except requests.exceptions.ConnectionError as err:
|
|
||||||
self.io.tool_error(f"ConnectionError: {err}")
|
|
||||||
|
|
||||||
retry_after = 1
|
|
||||||
self.io.tool_error(f"Retry in {retry_after} seconds.")
|
|
||||||
time.sleep(retry_after)
|
|
||||||
|
|
||||||
def send(self, messages, model=None, silent=False):
|
def send(self, messages, model=None, silent=False):
|
||||||
if not model:
|
if not model:
|
||||||
|
|
|
@ -121,8 +121,8 @@ class TestCoder(unittest.TestCase):
|
||||||
self.assertEqual(result, 'a good "commit message"')
|
self.assertEqual(result, 'a good "commit message"')
|
||||||
|
|
||||||
@patch("aider.coder.openai.ChatCompletion.create")
|
@patch("aider.coder.openai.ChatCompletion.create")
|
||||||
@patch("aider.coder.time.sleep")
|
@patch("builtins.print")
|
||||||
def test_send_with_retries_rate_limit_error(self, mock_sleep, mock_chat_completion_create):
|
def test_send_with_retries_rate_limit_error(self, mock_print, mock_chat_completion_create):
|
||||||
# Mock the IO object
|
# Mock the IO object
|
||||||
mock_io = MagicMock()
|
mock_io = MagicMock()
|
||||||
|
|
||||||
|
@ -139,12 +139,12 @@ class TestCoder(unittest.TestCase):
|
||||||
# Call the send_with_retries method
|
# Call the send_with_retries method
|
||||||
coder.send_with_retries("model", ["message"])
|
coder.send_with_retries("model", ["message"])
|
||||||
|
|
||||||
# Assert that time.sleep was called once
|
# Assert that print was called once
|
||||||
mock_sleep.assert_called_once()
|
mock_print.assert_called_once()
|
||||||
|
|
||||||
@patch("aider.coder.openai.ChatCompletion.create")
|
@patch("aider.coder.openai.ChatCompletion.create")
|
||||||
@patch("aider.coder.time.sleep")
|
@patch("builtins.print")
|
||||||
def test_send_with_retries_connection_error(self, mock_sleep, mock_chat_completion_create):
|
def test_send_with_retries_connection_error(self, mock_print, mock_chat_completion_create):
|
||||||
# Mock the IO object
|
# Mock the IO object
|
||||||
mock_io = MagicMock()
|
mock_io = MagicMock()
|
||||||
|
|
||||||
|
@ -161,8 +161,8 @@ class TestCoder(unittest.TestCase):
|
||||||
# Call the send_with_retries method
|
# Call the send_with_retries method
|
||||||
coder.send_with_retries("model", ["message"])
|
coder.send_with_retries("model", ["message"])
|
||||||
|
|
||||||
# Assert that time.sleep was called once
|
# Assert that print was called once
|
||||||
mock_sleep.assert_called_once()
|
mock_print.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue