JarvisChan630 commited on
Commit
35ec642
1 Parent(s): 62f4f30
Files changed (2) hide show
  1. agents/jar3d_agent.py +1 -1
  2. models/llms.py +22 -3
agents/jar3d_agent.py CHANGED
@@ -2,7 +2,7 @@ import json
2
  import os
3
  from multiprocessing import Pool, cpu_count
4
  # import requests
5
- # from tenacity import RetryError
6
  import concurrent.futures # Add this import at the top of your file
7
  import re
8
  import logging
 
2
  import os
3
  from multiprocessing import Pool, cpu_count
4
  # import requests
5
+ from tenacity import RetryError
6
  import concurrent.futures # Add this import at the top of your file
7
  import re
8
  import logging
models/llms.py CHANGED
@@ -23,9 +23,28 @@ class BaseModel:
23
 
24
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1), retry=retry_if_exception_type(requests.RequestException))
25
  def _make_request(self, url, headers, payload):
26
- response = requests.post(url, headers=headers, data=json.dumps(payload))
27
- response.raise_for_status()
28
- return response.json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  class MistralModel(BaseModel):
31
  def __init__(self, temperature: float, model: str, json_response: bool, max_retries: int = 3, retry_delay: int = 1):
 
23
 
24
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1), retry=retry_if_exception_type(requests.RequestException))
25
  def _make_request(self, url, headers, payload):
26
+ retry_strategy = Retry(
27
+ total=5, # total attempts
28
+ backoff_factor=0.5, # backoff factor to apply
29
+ status_forcelist=[429, 500, 502, 503, 504], # statuses to retry
30
+ method_whitelist=["HEAD", "GET", "OPTIONS", "POST"]
31
+ )
32
+ adapter = HTTPAdapter(max_retries=retry_strategy)
33
+ http = requests.Session()
34
+ http.mount("https://", adapter)
35
+ http.mount("http://", adapter)
36
+
37
+ try:
38
+ response = http.post(url, headers=headers, json=payload, timeout=10)
39
+ response.raise_for_status()
40
+ return response.json()
41
+ except requests.exceptions.RequestException as e:
42
+ print(f"Request failed: {e}")
43
+ raise
44
+
45
+ # response = requests.post(url, headers=headers, data=json.dumps(payload))
46
+ # response.raise_for_status()
47
+ # return response.json()
48
 
49
  class MistralModel(BaseModel):
50
  def __init__(self, temperature: float, model: str, json_response: bool, max_retries: int = 3, retry_delay: int = 1):