Spaces:
Sleeping
Sleeping
Use gemini-2.0-flash-lite + retry
Browse files- backend/agents/delta_agent.py +13 -4
- backend/agents/ihg_agent.py +13 -4
- backend/agents/resy_agent.py +13 -4
backend/agents/delta_agent.py
CHANGED
|
@@ -3,6 +3,7 @@ Delta.com browser agent — finds companion certificate availability.
|
|
| 3 |
Uses google-genai (Gemini Flash free tier) with Playwright browser tools.
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 6 |
import json
|
| 7 |
import os
|
| 8 |
import re
|
|
@@ -14,7 +15,7 @@ from google.genai import types
|
|
| 14 |
from ..models import Cabin, FlightOption, TripSearchRequest
|
| 15 |
from ..tools.browser import BrowserSession
|
| 16 |
|
| 17 |
-
_MODEL = "gemini-2.0-flash"
|
| 18 |
_MAX_ITER = 30
|
| 19 |
_ECONOMY_CLASSES = ["L", "U", "T", "X", "V"]
|
| 20 |
_FIRST_CLASSES = ["Z", "D", "I"]
|
|
@@ -96,9 +97,17 @@ async def search_companion_cert(
|
|
| 96 |
|
| 97 |
last_text = ""
|
| 98 |
for i in range(_MAX_ITER):
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
contents.append(response.candidates[0].content)
|
| 103 |
|
| 104 |
try:
|
|
|
|
| 3 |
Uses google-genai (Gemini Flash free tier) with Playwright browser tools.
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
import asyncio
|
| 7 |
import json
|
| 8 |
import os
|
| 9 |
import re
|
|
|
|
| 15 |
from ..models import Cabin, FlightOption, TripSearchRequest
|
| 16 |
from ..tools.browser import BrowserSession
|
| 17 |
|
| 18 |
+
_MODEL = "gemini-2.0-flash-lite"
|
| 19 |
_MAX_ITER = 30
|
| 20 |
_ECONOMY_CLASSES = ["L", "U", "T", "X", "V"]
|
| 21 |
_FIRST_CLASSES = ["Z", "D", "I"]
|
|
|
|
| 97 |
|
| 98 |
last_text = ""
|
| 99 |
for i in range(_MAX_ITER):
|
| 100 |
+
for attempt in range(4):
|
| 101 |
+
try:
|
| 102 |
+
response = await client.aio.models.generate_content(
|
| 103 |
+
model=_MODEL, contents=contents, config=config
|
| 104 |
+
)
|
| 105 |
+
break
|
| 106 |
+
except Exception as e:
|
| 107 |
+
if "429" in str(e) and attempt < 3:
|
| 108 |
+
await asyncio.sleep(15 * (attempt + 1))
|
| 109 |
+
else:
|
| 110 |
+
raise
|
| 111 |
contents.append(response.candidates[0].content)
|
| 112 |
|
| 113 |
try:
|
backend/agents/ihg_agent.py
CHANGED
|
@@ -5,6 +5,7 @@ Uses google-genai (Gemini Flash free tier) with Playwright browser tools.
|
|
| 5 |
|
| 6 |
from __future__ import annotations
|
| 7 |
|
|
|
|
| 8 |
import json
|
| 9 |
import os
|
| 10 |
import re
|
|
@@ -17,7 +18,7 @@ from google.genai import types
|
|
| 17 |
from ..models import HotelOption
|
| 18 |
from ..tools.browser import BrowserSession
|
| 19 |
|
| 20 |
-
_MODEL = "gemini-2.0-flash"
|
| 21 |
_MAX_ITER = 30
|
| 22 |
|
| 23 |
|
|
@@ -93,9 +94,17 @@ async def _search_one(
|
|
| 93 |
|
| 94 |
last_text = ""
|
| 95 |
for i in range(_MAX_ITER):
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
contents.append(response.candidates[0].content)
|
| 100 |
try:
|
| 101 |
if response.text:
|
|
|
|
| 5 |
|
| 6 |
from __future__ import annotations
|
| 7 |
|
| 8 |
+
import asyncio
|
| 9 |
import json
|
| 10 |
import os
|
| 11 |
import re
|
|
|
|
| 18 |
from ..models import HotelOption
|
| 19 |
from ..tools.browser import BrowserSession
|
| 20 |
|
| 21 |
+
_MODEL = "gemini-2.0-flash-lite"
|
| 22 |
_MAX_ITER = 30
|
| 23 |
|
| 24 |
|
|
|
|
| 94 |
|
| 95 |
last_text = ""
|
| 96 |
for i in range(_MAX_ITER):
|
| 97 |
+
for attempt in range(4):
|
| 98 |
+
try:
|
| 99 |
+
response = await client.aio.models.generate_content(
|
| 100 |
+
model=_MODEL, contents=contents, config=config
|
| 101 |
+
)
|
| 102 |
+
break
|
| 103 |
+
except Exception as e:
|
| 104 |
+
if "429" in str(e) and attempt < 3:
|
| 105 |
+
await asyncio.sleep(15 * (attempt + 1))
|
| 106 |
+
else:
|
| 107 |
+
raise
|
| 108 |
contents.append(response.candidates[0].content)
|
| 109 |
try:
|
| 110 |
if response.text:
|
backend/agents/resy_agent.py
CHANGED
|
@@ -3,6 +3,7 @@ Resy.com browser agent — finds restaurants eligible for the $20 monthly dining
|
|
| 3 |
Uses google-genai (Gemini Flash free tier) with Playwright browser tools.
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 6 |
import json
|
| 7 |
import os
|
| 8 |
import re
|
|
@@ -15,7 +16,7 @@ from google.genai import types
|
|
| 15 |
from ..models import RestaurantOption
|
| 16 |
from ..tools.browser import BrowserSession
|
| 17 |
|
| 18 |
-
_MODEL = "gemini-2.0-flash"
|
| 19 |
_MAX_ITER = 20
|
| 20 |
|
| 21 |
|
|
@@ -92,9 +93,17 @@ async def find_resy_restaurants(
|
|
| 92 |
|
| 93 |
last_text = ""
|
| 94 |
for i in range(_MAX_ITER):
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
contents.append(response.candidates[0].content)
|
| 99 |
try:
|
| 100 |
if response.text:
|
|
|
|
| 3 |
Uses google-genai (Gemini Flash free tier) with Playwright browser tools.
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
import asyncio
|
| 7 |
import json
|
| 8 |
import os
|
| 9 |
import re
|
|
|
|
| 16 |
from ..models import RestaurantOption
|
| 17 |
from ..tools.browser import BrowserSession
|
| 18 |
|
| 19 |
+
_MODEL = "gemini-2.0-flash-lite"
|
| 20 |
_MAX_ITER = 20
|
| 21 |
|
| 22 |
|
|
|
|
| 93 |
|
| 94 |
last_text = ""
|
| 95 |
for i in range(_MAX_ITER):
|
| 96 |
+
for attempt in range(4):
|
| 97 |
+
try:
|
| 98 |
+
response = await client.aio.models.generate_content(
|
| 99 |
+
model=_MODEL, contents=contents, config=config
|
| 100 |
+
)
|
| 101 |
+
break
|
| 102 |
+
except Exception as e:
|
| 103 |
+
if "429" in str(e) and attempt < 3:
|
| 104 |
+
await asyncio.sleep(15 * (attempt + 1))
|
| 105 |
+
else:
|
| 106 |
+
raise
|
| 107 |
contents.append(response.candidates[0].content)
|
| 108 |
try:
|
| 109 |
if response.text:
|