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
|
@ -1,5 +1,6 @@
|
|||
import hashlib
|
||||
import json
|
||||
import time
|
||||
|
||||
import backoff
|
||||
|
||||
|
@ -102,18 +103,27 @@ def send_completion(
|
|||
return hash_object, res
|
||||
|
||||
|
||||
# ai: in this function!
|
||||
def simple_send_with_retries(model_name, messages, extra_params=None):
|
||||
try:
|
||||
kwargs = {
|
||||
"model_name": model_name,
|
||||
"messages": messages,
|
||||
"functions": None,
|
||||
"stream": False,
|
||||
"extra_params": extra_params,
|
||||
}
|
||||
retry_delay = 0.125
|
||||
while True:
|
||||
try:
|
||||
kwargs = {
|
||||
"model_name": model_name,
|
||||
"messages": messages,
|
||||
"functions": None,
|
||||
"stream": False,
|
||||
"extra_params": extra_params,
|
||||
}
|
||||
|
||||
_hash, response = send_completion(**kwargs)
|
||||
return response.choices[0].message.content
|
||||
except AttributeError:
|
||||
return
|
||||
_hash, response = send_completion(**kwargs)
|
||||
return response.choices[0].message.content
|
||||
except retry_exceptions() as err:
|
||||
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