test
Browse files- __pycache__/agent.cpython-312.pyc +0 -0
- __pycache__/app.cpython-312.pyc +0 -0
- agent.py +7 -24
- app.py +4 -10
__pycache__/agent.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/agent.cpython-312.pyc and b/__pycache__/agent.cpython-312.pyc differ
|
|
|
__pycache__/app.cpython-312.pyc
ADDED
|
Binary file (13.7 kB). View file
|
|
|
agent.py
CHANGED
|
@@ -523,32 +523,15 @@ CRITICAL RULES:
|
|
| 523 |
if isinstance(msg, HumanMessage) and "[Attached File Local Path:" in msg.content:
|
| 524 |
messages.append(HumanMessage(content="IMPORTANT: I see an image path in the message. I MUST call the analyze_image tool IMMEDIATELY in my next step to see it."))
|
| 525 |
|
| 526 |
-
#
|
| 527 |
-
max_steps = 12
|
| 528 |
draft_response = None
|
| 529 |
current_tier = 0
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
print(f"--- ReAct Step {step + 1} ---")
|
| 537 |
-
|
| 538 |
-
# Max history truncation to avoid 413 Request Too Large errors
|
| 539 |
-
# Keep SystemMessage, first HumanMessage, and the last 6 messages
|
| 540 |
-
safe_messages = messages[:2] + messages[-6:] if len(messages) > 10 else messages
|
| 541 |
-
|
| 542 |
-
ai_msg, current_tier = smart_invoke(safe_messages, use_tools=True, start_tier=current_tier)
|
| 543 |
-
messages.append(ai_msg)
|
| 544 |
-
|
| 545 |
-
# Check if the model requested tools
|
| 546 |
-
tool_calls = getattr(ai_msg, "tool_calls", None) or []
|
| 547 |
-
if not tool_calls:
|
| 548 |
-
# Model decided it has enough info to answer
|
| 549 |
-
draft_response = ai_msg
|
| 550 |
-
print(f"Model found answer or stopped tools: {ai_msg.content}")
|
| 551 |
-
break
|
| 552 |
|
| 553 |
# Execute requested tools and append their text output into the conversation
|
| 554 |
for tool_call in tool_calls:
|
|
|
|
| 523 |
if isinstance(msg, HumanMessage) and "[Attached File Local Path:" in msg.content:
|
| 524 |
messages.append(HumanMessage(content="IMPORTANT: I see an image path in the message. I MUST call the analyze_image tool IMMEDIATELY in my next step to see it."))
|
| 525 |
|
| 526 |
+
# One-shot reasoning for better latency and more consistent accuracy on short QA.
|
|
|
|
| 527 |
draft_response = None
|
| 528 |
current_tier = 0
|
| 529 |
+
|
| 530 |
+
print("--- One-shot response invocation ---")
|
| 531 |
+
ai_msg, current_tier = smart_invoke(messages, use_tools=False, start_tier=current_tier)
|
| 532 |
+
messages.append(ai_msg)
|
| 533 |
+
draft_response = ai_msg
|
| 534 |
+
print(f"Model returned answer: {ai_msg.content}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
# Execute requested tools and append their text output into the conversation
|
| 537 |
for tool_call in tool_calls:
|
app.py
CHANGED
|
@@ -143,13 +143,10 @@ def run_and_submit_all(profile: Optional[gr.OAuthProfile] = None):
|
|
| 143 |
import concurrent.futures
|
| 144 |
import time
|
| 145 |
|
| 146 |
-
#
|
| 147 |
-
|
| 148 |
-
with concurrent.futures.ThreadPoolExecutor(max_workers=
|
| 149 |
-
futures = {}
|
| 150 |
-
for item in questions_data:
|
| 151 |
-
futures[executor.submit(process_item, item)] = item
|
| 152 |
-
time.sleep(3) # Stagger starting requests by 3 seconds to avoid bursting Rate Limits
|
| 153 |
|
| 154 |
for future in concurrent.futures.as_completed(futures):
|
| 155 |
res = future.result()
|
|
@@ -157,9 +154,6 @@ def run_and_submit_all(profile: Optional[gr.OAuthProfile] = None):
|
|
| 157 |
answers_payload.append({"task_id": res["task_id"], "submitted_answer": res["submitted_answer"]})
|
| 158 |
results_log.append({"Task ID": res["task_id"], "Question": res["question"], "Submitted Answer": res["submitted_answer"]})
|
| 159 |
|
| 160 |
-
# Additional delay after finishing a question to let Token bucket refill
|
| 161 |
-
time.sleep(2)
|
| 162 |
-
|
| 163 |
if not answers_payload:
|
| 164 |
print("Agent did not produce any answers to submit.")
|
| 165 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
|
|
| 143 |
import concurrent.futures
|
| 144 |
import time
|
| 145 |
|
| 146 |
+
# Improve throughput while respecting rate limits; avoid fixed sleep delays that slow down the entire run.
|
| 147 |
+
max_workers = min(8, len(questions_data)) if questions_data else 1
|
| 148 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 149 |
+
futures = {executor.submit(process_item, item): item for item in questions_data}
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
for future in concurrent.futures.as_completed(futures):
|
| 152 |
res = future.result()
|
|
|
|
| 154 |
answers_payload.append({"task_id": res["task_id"], "submitted_answer": res["submitted_answer"]})
|
| 155 |
results_log.append({"Task ID": res["task_id"], "Question": res["question"], "Submitted Answer": res["submitted_answer"]})
|
| 156 |
|
|
|
|
|
|
|
|
|
|
| 157 |
if not answers_payload:
|
| 158 |
print("Agent did not produce any answers to submit.")
|
| 159 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|