MatteoScript commited on
Commit
83ed783
·
verified ·
1 Parent(s): f244966

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -6
main.py CHANGED
@@ -199,20 +199,21 @@ async def make_request(session, token, data, url, index, semaphore, max_retries=
199
  data['max_new_tokens'] = max(200, data['max_new_tokens'] - 200)
200
  else:
201
  data['max_new_tokens'] = data['max_new_tokens'] + 200
 
202
  for _ in range(max_retries):
203
  try:
204
- async with session.post(url, headers=headers, json=data) as response:
205
  response.raise_for_status()
206
  try:
207
  result_data = await response.json()
208
  except aiohttp.ContentTypeError:
209
- result_data = await response.text()
210
  return result_data
211
- except (asyncio.TimeoutError, aiohttp.ClientError, requests.exceptions.HTTPError) as e:
212
- LoggaTesto("ERRORE ASYNC", {e}, False)
213
- if isinstance(e, (asyncio.TimeoutError, requests.exceptions.HTTPError)) and e.response.status in [502, 504]:
214
  break
215
- await asyncio.sleep(3)
216
  raise Exception("Max retries reached or skipping retries. Unable to make the request.")
217
 
218
  async def CreaListaInput(input_data):
 
199
  data['max_new_tokens'] = max(200, data['max_new_tokens'] - 200)
200
  else:
201
  data['max_new_tokens'] = data['max_new_tokens'] + 200
202
+ timeout = aiohttp.ClientTimeout(total=1000)
203
  for _ in range(max_retries):
204
  try:
205
+ async with session.post(url, headers=headers, json=data, timeout=timeout) as response:
206
  response.raise_for_status()
207
  try:
208
  result_data = await response.json()
209
  except aiohttp.ContentTypeError:
210
+ result_data = await response.text()
211
  return result_data
212
+ except (asyncio.TimeoutError, aiohttp.ClientError) as e:
213
+ LoggaTesto("ERRORE ASYNC", {str(e)}, False)
214
+ if isinstance(e, aiohttp.ClientError) and e.status in [502, 504]:
215
  break
216
+ await asyncio.sleep(3)
217
  raise Exception("Max retries reached or skipping retries. Unable to make the request.")
218
 
219
  async def CreaListaInput(input_data):