Spaces:
Sleeping
Sleeping
fix: parse Zhipu rate limit reset time as Beijing time (UTC+8), not UTC
Browse files
scripts/conversation-loop.py
CHANGED
|
@@ -647,7 +647,7 @@ def call_llm(system_prompt, user_prompt):
|
|
| 647 |
now = time.time()
|
| 648 |
if _rate_limit_until > now:
|
| 649 |
wait_secs = _rate_limit_until - now
|
| 650 |
-
print(f"[RATE-LIMIT] Sleeping {wait_secs:.0f}s until reset ({datetime.datetime.utcfromtimestamp(_rate_limit_until).strftime('%H:%M:%S')} UTC)")
|
| 651 |
time.sleep(min(wait_secs + 5, 600)) # cap at 10 min per sleep
|
| 652 |
_rate_limit_until = 0.0 # reset after sleeping
|
| 653 |
|
|
@@ -685,10 +685,12 @@ def call_llm(system_prompt, user_prompt):
|
|
| 685 |
m = re.search(r'(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})', err_msg)
|
| 686 |
if m:
|
| 687 |
try:
|
| 688 |
-
|
| 689 |
-
|
|
|
|
|
|
|
| 690 |
wait = _rate_limit_until - time.time()
|
| 691 |
-
print(f"[RATE-LIMIT] Hit! Reset at {m.group(1)} UTC ({wait:.0f}s). Will sleep on next call.")
|
| 692 |
except ValueError:
|
| 693 |
_rate_limit_until = time.time() + 300 # fallback: 5 min
|
| 694 |
print(f"[RATE-LIMIT] Hit! Could not parse reset time, backing off 5 min.")
|
|
|
|
| 647 |
now = time.time()
|
| 648 |
if _rate_limit_until > now:
|
| 649 |
wait_secs = _rate_limit_until - now
|
| 650 |
+
print(f"[RATE-LIMIT] Sleeping {wait_secs:.0f}s until reset ({datetime.datetime.utcfromtimestamp(_rate_limit_until).strftime('%Y-%m-%d %H:%M:%S')} UTC)")
|
| 651 |
time.sleep(min(wait_secs + 5, 600)) # cap at 10 min per sleep
|
| 652 |
_rate_limit_until = 0.0 # reset after sleeping
|
| 653 |
|
|
|
|
| 685 |
m = re.search(r'(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})', err_msg)
|
| 686 |
if m:
|
| 687 |
try:
|
| 688 |
+
# Zhipu returns Beijing time (UTC+8), convert to UTC
|
| 689 |
+
reset_beijing = datetime.datetime.strptime(m.group(1), "%Y-%m-%d %H:%M:%S")
|
| 690 |
+
reset_utc = reset_beijing - datetime.timedelta(hours=8)
|
| 691 |
+
_rate_limit_until = reset_utc.timestamp()
|
| 692 |
wait = _rate_limit_until - time.time()
|
| 693 |
+
print(f"[RATE-LIMIT] Hit! Reset at {m.group(1)} Beijing = {reset_utc.strftime('%H:%M:%S')} UTC ({wait:.0f}s). Will sleep on next call.")
|
| 694 |
except ValueError:
|
| 695 |
_rate_limit_until = time.time() + 300 # fallback: 5 min
|
| 696 |
print(f"[RATE-LIMIT] Hit! Could not parse reset time, backing off 5 min.")
|