mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 18:25:00 +00:00
refactor: add retry loop to simple_send_with_retries function
This commit is contained in:
parent
f9c45432e6
commit
bc515cf74a
2 changed files with 23 additions and 15 deletions
|
@ -1124,7 +1124,6 @@ class Coder:
|
||||||
exhausted = False
|
exhausted = False
|
||||||
interrupted = False
|
interrupted = False
|
||||||
try:
|
try:
|
||||||
# ai: replicate this try/except retry loop...
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
yield from self.send(messages, functions=self.functions)
|
yield from self.send(messages, functions=self.functions)
|
||||||
|
@ -1137,7 +1136,6 @@ class Coder:
|
||||||
self.io.tool_output(f"Retrying in {retry_delay:.1f} seconds...")
|
self.io.tool_output(f"Retrying in {retry_delay:.1f} seconds...")
|
||||||
time.sleep(retry_delay)
|
time.sleep(retry_delay)
|
||||||
continue
|
continue
|
||||||
# ai: ... down to here
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
interrupted = True
|
interrupted = True
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
import backoff
|
import backoff
|
||||||
|
|
||||||
|
@ -102,18 +103,27 @@ def send_completion(
|
||||||
return hash_object, res
|
return hash_object, res
|
||||||
|
|
||||||
|
|
||||||
# ai: in this function!
|
|
||||||
def simple_send_with_retries(model_name, messages, extra_params=None):
|
def simple_send_with_retries(model_name, messages, extra_params=None):
|
||||||
try:
|
retry_delay = 0.125
|
||||||
kwargs = {
|
while True:
|
||||||
"model_name": model_name,
|
try:
|
||||||
"messages": messages,
|
kwargs = {
|
||||||
"functions": None,
|
"model_name": model_name,
|
||||||
"stream": False,
|
"messages": messages,
|
||||||
"extra_params": extra_params,
|
"functions": None,
|
||||||
}
|
"stream": False,
|
||||||
|
"extra_params": extra_params,
|
||||||
|
}
|
||||||
|
|
||||||
_hash, response = send_completion(**kwargs)
|
_hash, response = send_completion(**kwargs)
|
||||||
return response.choices[0].message.content
|
return response.choices[0].message.content
|
||||||
except AttributeError:
|
except retry_exceptions() as err:
|
||||||
return
|
print(str(err))
|
||||||
|
retry_delay *= 2
|
||||||
|
if retry_delay > RETRY_TIMEOUT:
|
||||||
|
break
|
||||||
|
print(f"Retrying in {retry_delay:.1f} seconds...")
|
||||||
|
time.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
except AttributeError:
|
||||||
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue