browser-assistant 2.9.42 → 2.9.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extension/answer-requests.js +2 -0
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +28 -4
- package/server/vision_images.py +2 -0
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
return error;
|
|
19
19
|
}
|
|
20
20
|
function temporary(error) {
|
|
21
|
+
if (error.code === 'vision_request_too_large')
|
|
22
|
+
return false;
|
|
21
23
|
// Retry exhausted vision keys only after their explicit cooldown expires.
|
|
22
24
|
if (error.code === 'vision_rate_limited')
|
|
23
25
|
return Number.isFinite(error.retryAfterMs) && error.retryAfterMs > 0;
|
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
package/server/main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import json
|
|
3
|
+
import copy
|
|
3
4
|
import asyncio
|
|
4
5
|
import ast
|
|
5
6
|
import math
|
|
@@ -200,7 +201,7 @@ async def lifespan(_app: FastAPI):
|
|
|
200
201
|
client.close()
|
|
201
202
|
|
|
202
203
|
|
|
203
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
204
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.43", lifespan=lifespan)
|
|
204
205
|
install_local_guards(app)
|
|
205
206
|
|
|
206
207
|
@app.exception_handler(HTTPException)
|
|
@@ -1653,7 +1654,7 @@ async def _solve_vision(content: VisionContent):
|
|
|
1653
1654
|
compressed = []
|
|
1654
1655
|
for index, image in enumerate(inputs, 1):
|
|
1655
1656
|
try:
|
|
1656
|
-
compressed.append(await asyncio.to_thread(compress_image_base64, image, max_dim=
|
|
1657
|
+
compressed.append(await asyncio.to_thread(compress_image_base64, image, max_dim=1600, quality=95))
|
|
1657
1658
|
except ValueError as exc:
|
|
1658
1659
|
raise HTTPException(422, f'Image {index}: {exc}') from exc
|
|
1659
1660
|
is_code_scan = content.practice_type == "code" or (content.practice_type == "auto" and bool(content.language))
|
|
@@ -1690,7 +1691,9 @@ async def _solve_vision(content: VisionContent):
|
|
|
1690
1691
|
def reset_at(key):
|
|
1691
1692
|
return _vision_key_cooldowns.get((vision_model, key), 0.0)
|
|
1692
1693
|
|
|
1693
|
-
attempts = len(clients) +
|
|
1694
|
+
attempts = len(clients) + 3
|
|
1695
|
+
image_sizes = iter((1280, 1024))
|
|
1696
|
+
messages = copy.deepcopy(messages)
|
|
1694
1697
|
for attempt in range(attempts):
|
|
1695
1698
|
now = loop.time()
|
|
1696
1699
|
key = next((index for index in key_order if reset_at(index) <= now), None)
|
|
@@ -1701,7 +1704,7 @@ async def _solve_vision(content: VisionContent):
|
|
|
1701
1704
|
def call_vision_api(c=client, m=vision_model):
|
|
1702
1705
|
return c.chat.completions.create(
|
|
1703
1706
|
model=m,
|
|
1704
|
-
messages=messages,
|
|
1707
|
+
messages=copy.deepcopy(messages),
|
|
1705
1708
|
temperature=0.0,
|
|
1706
1709
|
max_completion_tokens=max(4096, vision_token_limit) if len(image_blocks) > 3 else vision_token_limit,
|
|
1707
1710
|
**options,
|
|
@@ -1720,6 +1723,25 @@ async def _solve_vision(content: VisionContent):
|
|
|
1720
1723
|
except Exception as exc:
|
|
1721
1724
|
error_text = str(exc)
|
|
1722
1725
|
provider_status = getattr(exc, 'status_code', None)
|
|
1726
|
+
if provider_status == 413:
|
|
1727
|
+
size = next(image_sizes, None)
|
|
1728
|
+
if size is None:
|
|
1729
|
+
raise HTTPException(413, detail={
|
|
1730
|
+
'code': 'vision_request_too_large',
|
|
1731
|
+
'message': 'The complete vision request exceeds the provider input limit even after image resizing. Send a smaller clear image or use text input; repeating this request will not help.',
|
|
1732
|
+
}) from exc
|
|
1733
|
+
resized = False
|
|
1734
|
+
for message in messages:
|
|
1735
|
+
for block in message.get('content', []) if isinstance(message.get('content'), list) else []:
|
|
1736
|
+
if block.get('type') == 'image_url':
|
|
1737
|
+
encoded = await asyncio.to_thread(compress_image_base64, block['image_url']['url'], max_dim=size, quality=95)
|
|
1738
|
+
block['image_url']['url'] = 'data:image/jpeg;base64,' + encoded
|
|
1739
|
+
resized = True
|
|
1740
|
+
if not resized:
|
|
1741
|
+
raise HTTPException(413, detail={'code': 'vision_request_too_large',
|
|
1742
|
+
'message': 'The vision text request exceeds the provider input limit. Reduce the supplied context.'}) from exc
|
|
1743
|
+
logger.info('Vision input too large; retrying with complete images limited to %d pixels.', size)
|
|
1744
|
+
continue
|
|
1723
1745
|
if provider_status == 429 or (provider_status is None and re.search(r'\b429\b|\brate[_ ]limit', error_text, re.I)):
|
|
1724
1746
|
delay = vision_retry_after(exc, error_text)
|
|
1725
1747
|
_vision_key_cooldowns[(vision_model, key)] = max(reset_at(key), loop.time() + delay)
|
|
@@ -1880,6 +1902,8 @@ async def _solve_vision(content: VisionContent):
|
|
|
1880
1902
|
unconfirmed = True
|
|
1881
1903
|
errors.append(f"{vision_model}: {exc}")
|
|
1882
1904
|
logger.warning(errors[-1])
|
|
1905
|
+
except HTTPException:
|
|
1906
|
+
raise
|
|
1883
1907
|
except Exception as exc:
|
|
1884
1908
|
errors.append(f"{vision_model}: {exc}")
|
|
1885
1909
|
logger.warning(errors[-1])
|
package/server/vision_images.py
CHANGED
|
@@ -102,6 +102,8 @@ async def collect_image_evidence(blocks, positions, question, model, complete, b
|
|
|
102
102
|
except VisionRateLimitError:
|
|
103
103
|
raise
|
|
104
104
|
except Exception as exc:
|
|
105
|
+
if getattr(exc, 'status_code', None) == 413:
|
|
106
|
+
raise
|
|
105
107
|
raise RuntimeError(f'Image batch {ids} could not be processed: {exc}') from exc
|
|
106
108
|
# Network retries belong to the provider wrapper; completed batches stay intact.
|
|
107
109
|
return json.dumps({'logical_image_positions': positions, 'images': evidence}, ensure_ascii=False)
|