AnhLee0 commited on
Commit
4849345
·
verified ·
1 Parent(s): 05ad3cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -24,7 +24,7 @@ class AssistantAgent:
24
  self.headers = {"Content-Type": "application/json"}
25
 
26
  def call_gemini_api(self, prompt: str) -> str:
27
- retry_delay = 60 # Chờ 60 giây nếu gặp lỗi quota
28
  payload = {
29
  "contents": [{
30
  "parts": [{"text": prompt}]
@@ -37,10 +37,10 @@ class AssistantAgent:
37
  return response.json()["candidates"][0]["content"]["parts"][0]["text"].strip()
38
  except requests.exceptions.RequestException as e:
39
  if "429" in str(e):
40
- retry_delay = max(retry_delay, 60)
41
  print(f"Quota error, retrying after {retry_delay} seconds... (Attempt {attempt + 1}/3)")
42
  time.sleep(retry_delay)
43
- retry_delay += 10
44
  else:
45
  return f"Error calling Gemini API: {e}"
46
  return "Error: Exceeded retry attempts due to quota limits."
@@ -130,8 +130,8 @@ class AssistantAgent:
130
  answer = batch_answers[idx].split('. ', 1)[1] if idx < len(batch_answers) and '. ' in batch_answers[idx] else "Error: Could not parse answer."
131
  answers.append(answer)
132
  if i + batch_size < len(questions):
133
- print("Waiting 60 seconds before next batch to avoid rate limit...")
134
- time.sleep(60)
135
  return answers
136
 
137
  def process_file(self, question: str, file_path: str) -> str:
 
24
  self.headers = {"Content-Type": "application/json"}
25
 
26
  def call_gemini_api(self, prompt: str) -> str:
27
+ retry_delay = 5 # Chờ 5 giây nếu gặp lỗi quota
28
  payload = {
29
  "contents": [{
30
  "parts": [{"text": prompt}]
 
37
  return response.json()["candidates"][0]["content"]["parts"][0]["text"].strip()
38
  except requests.exceptions.RequestException as e:
39
  if "429" in str(e):
40
+ retry_delay = max(retry_delay, 5)
41
  print(f"Quota error, retrying after {retry_delay} seconds... (Attempt {attempt + 1}/3)")
42
  time.sleep(retry_delay)
43
+ retry_delay += 5
44
  else:
45
  return f"Error calling Gemini API: {e}"
46
  return "Error: Exceeded retry attempts due to quota limits."
 
130
  answer = batch_answers[idx].split('. ', 1)[1] if idx < len(batch_answers) and '. ' in batch_answers[idx] else "Error: Could not parse answer."
131
  answers.append(answer)
132
  if i + batch_size < len(questions):
133
+ print("Waiting 5 seconds before next batch to avoid rate limit...")
134
+ time.sleep(5) # Giảm từ 60 giây xuống 5 giây
135
  return answers
136
 
137
  def process_file(self, question: str, file_path: str) -> str: