Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,6 +76,19 @@ model = genai.GenerativeModel(
|
|
| 76 |
generation_config=generation_config,
|
| 77 |
)
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
def extract_notes(filepath):
|
| 81 |
files = [
|
|
@@ -91,17 +104,22 @@ def extract_notes(filepath):
|
|
| 91 |
},
|
| 92 |
]
|
| 93 |
)
|
| 94 |
-
|
|
|
|
| 95 |
current_response_text = response.text
|
| 96 |
while "```json" in response.text:
|
| 97 |
-
response = chat_session
|
| 98 |
current_response_text += "\n" + response.text
|
| 99 |
|
| 100 |
pattern = r"```json(.*?)```"
|
| 101 |
matches = re.findall(pattern, current_response_text, re.DOTALL)
|
| 102 |
results = []
|
| 103 |
for match in matches:
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
return results
|
| 107 |
|
|
|
|
| 76 |
generation_config=generation_config,
|
| 77 |
)
|
| 78 |
|
| 79 |
+
def send_message_with_retry(chat_session, content, max_retries=3, initial_backoff=30):
|
| 80 |
+
for attempt in range(max_retries + 1):
|
| 81 |
+
try:
|
| 82 |
+
response = chat_session.send_message(content=content)
|
| 83 |
+
return response
|
| 84 |
+
except Exception as e:
|
| 85 |
+
if attempt == max_retries:
|
| 86 |
+
raise # Re-raise the exception if max retries reached
|
| 87 |
+
backoff_time = initial_backoff * (2**attempt)
|
| 88 |
+
print(f"Error during LLM call: {e}. Retrying in {backoff_time} seconds (Attempt {attempt + 1}/{max_retries + 1})...")
|
| 89 |
+
time.sleep(backoff_time)
|
| 90 |
+
return None # Should not reach here as exception is re-raised if all retries fail
|
| 91 |
+
|
| 92 |
|
| 93 |
def extract_notes(filepath):
|
| 94 |
files = [
|
|
|
|
| 104 |
},
|
| 105 |
]
|
| 106 |
)
|
| 107 |
+
|
| 108 |
+
response = send_message_with_retry(chat_session, prompt)
|
| 109 |
current_response_text = response.text
|
| 110 |
while "```json" in response.text:
|
| 111 |
+
response = send_message_with_retry(chat_session, "CONTINUE")
|
| 112 |
current_response_text += "\n" + response.text
|
| 113 |
|
| 114 |
pattern = r"```json(.*?)```"
|
| 115 |
matches = re.findall(pattern, current_response_text, re.DOTALL)
|
| 116 |
results = []
|
| 117 |
for match in matches:
|
| 118 |
+
try:
|
| 119 |
+
results.extend(json.loads(match))
|
| 120 |
+
except json.JSONDecodeError as e:
|
| 121 |
+
print(f"JSONDecodeError: {e} for match: {match}")
|
| 122 |
+
# Handle JSON decode error, maybe skip or log the issue
|
| 123 |
|
| 124 |
return results
|
| 125 |
|