browser-assistant 2.9.34 → 2.9.36
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/manifest.json +1 -1
- package/package.json +1 -1
- package/server/journal.py +4 -1
- package/server/main.py +18 -11
- package/server/vision_images.py +0 -60
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
package/server/journal.py
CHANGED
|
@@ -99,7 +99,10 @@ def register_journal(app, cloud, local):
|
|
|
99
99
|
except Exception:
|
|
100
100
|
raw = await local(messages, temperature=0.2)
|
|
101
101
|
except Exception as exc:
|
|
102
|
-
raise HTTPException(
|
|
102
|
+
raise HTTPException(
|
|
103
|
+
503, 'Journal generation could not get a response from Groq or local Ollama. '
|
|
104
|
+
'Try again shortly. If it keeps failing, check your Groq quota or start Ollama.'
|
|
105
|
+
) from exc
|
|
103
106
|
try:
|
|
104
107
|
raw = re.sub(r'^```(?:json)?\s*|\s*```$', '', raw.strip())
|
|
105
108
|
sections, count = validate_sections(json.loads(raw))
|
package/server/main.py
CHANGED
|
@@ -28,7 +28,7 @@ from vision_images import (compress_image_base64, unique_image_blocks, collect_i
|
|
|
28
28
|
cross_check_visual_answers, relative_percentage_question, RELATIVE_PERCENTAGE_INSTRUCTION,
|
|
29
29
|
answer_permutation, cross_check_text_answers, solve_matrix_choice, solve_row_parallel_choice,
|
|
30
30
|
solve_relu_parallel_choice,
|
|
31
|
-
ordering_question, solve_sorted_list_merge_order, solve_stack_empty_order,
|
|
31
|
+
ordering_question, solve_sorted_list_merge_order, solve_stack_empty_order,
|
|
32
32
|
solve_stack_push_order, solve_stack_pop_order, solve_next_greater_element_order,
|
|
33
33
|
multiple_choice_question, solve_linked_stack_choices, cross_check_multiple_choice, stack_reasoning_guidance,
|
|
34
34
|
reading_response_constraints, free_response_question,
|
|
@@ -195,7 +195,7 @@ async def lifespan(_app: FastAPI):
|
|
|
195
195
|
client.close()
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
198
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.36", lifespan=lifespan)
|
|
199
199
|
install_local_guards(app)
|
|
200
200
|
|
|
201
201
|
@app.exception_handler(HTTPException)
|
|
@@ -429,7 +429,7 @@ def save_automation_history(entry: AutomationHistoryEntry):
|
|
|
429
429
|
|
|
430
430
|
# ── AI providers ──────────────────────────────────────────────────────────────
|
|
431
431
|
|
|
432
|
-
async def try_groq(messages: list, model: str = None, temperature: float = 0.0, _token_limit: int = GROQ_COMPLETION_TOKEN_LIMIT, _review: bool = False) -> str:
|
|
432
|
+
async def try_groq(messages: list, model: str = None, temperature: float = 0.0, _token_limit: int = GROQ_COMPLETION_TOKEN_LIMIT, _review: bool = False, *, structured: bool = False) -> str:
|
|
433
433
|
"""Call Groq with automatic API key rotation on rate limit (429)."""
|
|
434
434
|
global _groq_disabled_until, _groq_key_index
|
|
435
435
|
if time.monotonic() < _groq_disabled_until:
|
|
@@ -441,9 +441,8 @@ async def try_groq(messages: list, model: str = None, temperature: float = 0.0,
|
|
|
441
441
|
use_model = model or GROQ_TEXT_MODEL
|
|
442
442
|
loop = asyncio.get_running_loop()
|
|
443
443
|
review_options = {}
|
|
444
|
-
if _review:
|
|
445
|
-
#
|
|
446
|
-
# bounded so GPT-OSS leaves room for its final JSON verdict.
|
|
444
|
+
if _review or structured:
|
|
445
|
+
# Keep reasoning bounded so GPT-OSS leaves room for the final JSON.
|
|
447
446
|
review_options['response_format'] = {'type': 'json_object'}
|
|
448
447
|
if use_model in {'openai/gpt-oss-20b', 'openai/gpt-oss-120b'}:
|
|
449
448
|
review_options['reasoning_effort'] = 'low'
|
|
@@ -475,7 +474,7 @@ async def try_groq(messages: list, model: str = None, temperature: float = 0.0,
|
|
|
475
474
|
if getattr(choice, "finish_reason", None) == "length":
|
|
476
475
|
if _token_limit < GROQ_RETRY_TOKEN_LIMIT:
|
|
477
476
|
logger.warning(f"{use_model} reached {_token_limit} tokens; retrying once with {GROQ_RETRY_TOKEN_LIMIT}")
|
|
478
|
-
return await try_groq(messages, model=use_model, temperature=temperature, _token_limit=GROQ_RETRY_TOKEN_LIMIT, _review=_review)
|
|
477
|
+
return await try_groq(messages, model=use_model, temperature=temperature, _token_limit=GROQ_RETRY_TOKEN_LIMIT, _review=_review, structured=structured)
|
|
479
478
|
raise RuntimeError(f"{use_model} stopped at the output token limit")
|
|
480
479
|
content = choice.message.content or ""
|
|
481
480
|
if not content.strip():
|
|
@@ -550,6 +549,17 @@ TEXT_MODELS = list(dict.fromkeys([
|
|
|
550
549
|
"openai/gpt-oss-20b",
|
|
551
550
|
]))
|
|
552
551
|
|
|
552
|
+
|
|
553
|
+
async def try_journal_cloud(messages: list, temperature: float = 0.2) -> str:
|
|
554
|
+
for model in TEXT_MODELS:
|
|
555
|
+
if not _groq_clients or time.monotonic() < _groq_disabled_until:
|
|
556
|
+
break
|
|
557
|
+
try:
|
|
558
|
+
return await try_groq(messages, model=model, temperature=temperature, structured=True)
|
|
559
|
+
except Exception as exc:
|
|
560
|
+
logger.warning("Journal model %s failed (%s); trying the next provider.", model, type(exc).__name__)
|
|
561
|
+
raise RuntimeError("No Groq journal model responded.")
|
|
562
|
+
|
|
553
563
|
# Vision model fallback chain
|
|
554
564
|
VISION_MODELS = list(dict.fromkeys([
|
|
555
565
|
GROQ_VISION_MODEL,
|
|
@@ -1327,9 +1337,6 @@ def local_choice_result(text, language):
|
|
|
1327
1337
|
if item is None:
|
|
1328
1338
|
item = solve_relu_parallel_choice(text)
|
|
1329
1339
|
provider = "local ReLU shard check"
|
|
1330
|
-
if item is None:
|
|
1331
|
-
item = solve_pseudocode_choice(text)
|
|
1332
|
-
provider = "local pseudocode check"
|
|
1333
1340
|
if item is not None:
|
|
1334
1341
|
return {"results": json.dumps([item], ensure_ascii=False), "provider": f"{provider} [verified]",
|
|
1335
1342
|
"language": language, "answer_verified": True, "code_reviewed": False}
|
|
@@ -2072,7 +2079,7 @@ def normalize_vision_results(raw: str) -> str:
|
|
|
2072
2079
|
|
|
2073
2080
|
|
|
2074
2081
|
from journal import register_journal, load_syllabus
|
|
2075
|
-
register_journal(app,
|
|
2082
|
+
register_journal(app, try_journal_cloud, try_ollama)
|
|
2076
2083
|
|
|
2077
2084
|
if __name__ == "__main__":
|
|
2078
2085
|
# The extension talks to this API through its background worker. Binding to
|
package/server/vision_images.py
CHANGED
|
@@ -645,52 +645,6 @@ def solve_linked_stack_choices(question):
|
|
|
645
645
|
return {'type': 'mcq', 'question': prompt, 'answer': _format_choice_set(choices, selected), 'reasoning': reasoning}
|
|
646
646
|
|
|
647
647
|
|
|
648
|
-
def solve_pseudocode_choice(text):
|
|
649
|
-
choices = displayed_single_choices(text)
|
|
650
|
-
if not choices:
|
|
651
|
-
return None
|
|
652
|
-
prompt = re.split(r'\n(?:Question format: )?Select one answer\.', text.strip(), maxsplit=1, flags=re.I)[0]
|
|
653
|
-
initial = re.search(r'\binitial value of the\s+\x60?([a-zA-Z_]\w*)\x60?\s+node\s*\?', prompt, re.I)
|
|
654
|
-
if initial:
|
|
655
|
-
variable = re.escape(initial[1])
|
|
656
|
-
constructors = re.findall(rf'^\s*{variable}\s*=\s*new\s+Node\s*\(\s*(-?\d+)\s*\)\s*;?\s*$',
|
|
657
|
-
prompt, re.M)
|
|
658
|
-
if len(constructors) != 1:
|
|
659
|
-
return None
|
|
660
|
-
expected = constructors[0]
|
|
661
|
-
reason = f'The pseudocode initializes {initial[1]} with new Node({expected}).'
|
|
662
|
-
matches = [(letter, option) for letter, option in choices.items()
|
|
663
|
-
if option.strip().strip('\x60').replace('−', '-') == expected]
|
|
664
|
-
elif re.search(r'time complexity of the below pseudo\s*code where size of linked list', prompt, re.I):
|
|
665
|
-
loop = re.search(r'while\s*\(\s*(\w+)\s*!=\s*null\s*\|\|\s*(\w+)\s*!=\s*null\s*\)', prompt)
|
|
666
|
-
if not loop or len(re.findall(r'\b(?:while|for)\s*\(', prompt)) != 1:
|
|
667
|
-
return None
|
|
668
|
-
first, second = loop.groups()
|
|
669
|
-
if first == second or not all(re.search(rf'if\s*\(\s*{re.escape(pointer)}\s*!=\s*null\s*\)' r'[^}]*?'
|
|
670
|
-
rf'\b{re.escape(pointer)}\s*=\s*{re.escape(pointer)}\s*->\s*next\b',
|
|
671
|
-
prompt[loop.end():]) for pointer in (first, second)):
|
|
672
|
-
return None
|
|
673
|
-
matches = [(letter, option) for letter, option in choices.items()
|
|
674
|
-
if re.sub(r'\s+', '', option.strip('\x60')) == 'O(max(m,n))']
|
|
675
|
-
reason = 'Both available pointers advance in each iteration, so the loop runs until the longer list is exhausted.'
|
|
676
|
-
elif 'mergeTwoLists' in prompt and re.search(r'\bwhat happens if\s+temp1\s*(?:->|→)\s*data\s+is less than or equal to\s+'
|
|
677
|
-
r'temp2\s*(?:->|→)\s*data', prompt.replace('\x60', ''), re.I):
|
|
678
|
-
branch = re.search(r'if\s*\(\s*temp1\s*->\s*data\s*<=\s*temp2\s*->\s*data\s*\)\s*\{([^}]+)\}', prompt)
|
|
679
|
-
if not branch or not re.search(r'\bcur\s*->\s*next\s*=\s*temp1?\b', branch[1]) \
|
|
680
|
-
or not re.search(r'\btemp1\s*=\s*temp1\s*->\s*next\b', branch[1]):
|
|
681
|
-
return None
|
|
682
|
-
matches = [(letter, option) for letter, option in choices.items() if re.fullmatch(
|
|
683
|
-
r'temp1 is linked to the merged list and temp1 is moved to the next node\.?',
|
|
684
|
-
' '.join(option.replace('\x60', '').split()), re.I)]
|
|
685
|
-
reason = 'The <= branch links the first-list node and advances temp1 to temp1->next.'
|
|
686
|
-
else:
|
|
687
|
-
return None
|
|
688
|
-
if len(matches) != 1:
|
|
689
|
-
return None
|
|
690
|
-
letter, option = matches[0]
|
|
691
|
-
return {'type': 'mcq', 'question': prompt, 'answer': f'Option {letter}: {option}', 'reasoning': reason}
|
|
692
|
-
|
|
693
|
-
|
|
694
648
|
def solve_row_parallel_choice(text):
|
|
695
649
|
"""Check the shared multiplication dimension in a row-parallel linear layer."""
|
|
696
650
|
choices = displayed_single_choices(text)
|
|
@@ -969,20 +923,6 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
969
923
|
'role': 'user',
|
|
970
924
|
'content': 'Solve again using the original question and its context. Return the full verification JSON with the required ids.',
|
|
971
925
|
}]
|
|
972
|
-
# When both independent verifications failed to parse, prefer delivering the
|
|
973
|
-
# primary answer over blocking the automation entirely. The primary solve was
|
|
974
|
-
# validated and the verification provider returned unusable JSON — a parsing
|
|
975
|
-
# failure, not a disagreement — so a hard 422 is disproportionate.
|
|
976
|
-
if not require_agreement and not step_count and not free_response and current is None and previous is None:
|
|
977
|
-
return results
|
|
978
|
-
# For multi-answer questions (fill-in-the-blank), accept the primary answers
|
|
979
|
-
# when the majority of individual answers agree with any independent solve.
|
|
980
|
-
if not require_agreement and not choices and not step_count and not free_response and first is not None and len(first) > 1:
|
|
981
|
-
best = current or previous
|
|
982
|
-
if best is not None:
|
|
983
|
-
agreed = sum(a == b for a, b in zip(first, best))
|
|
984
|
-
if agreed > len(first) // 2:
|
|
985
|
-
return results
|
|
986
926
|
if step_count:
|
|
987
927
|
raise VisionUnconfirmedError('The independent checks could not confirm a complete order for the displayed steps.')
|
|
988
928
|
if free_response:
|