Use single-tool required choice for reliable forced search arguments

This commit is contained in:
pewdiepie-archdaemon
2026-09-17 21:31:09 +00:00
parent a23d709056
commit a80a090d37
4 changed files with 59 additions and 8 deletions
+18 -2
View File
@@ -8,16 +8,32 @@ const model = process.env.MODEL || 'model-f';
const endpoint = process.env.ENDPOINT_URL || (() => { throw new Error("ENDPOINT_URL is required"); })();
const prompts = ['Catch me up on the biggest AI developments this week. Explain why they matter and link your sources.', 'serch latest ai news pls'];
const results = [];
let system = 'You are Odysseus. Use web_search to find current information relevant to the user request.';
if (process.env.CANONICAL_SYSTEM === '1') {
system = execFileSync((process.env.PYTHON || "python3"), ['-c', `
import ast, sys
from datetime import datetime, timezone
from src.clean_agent_preview import native_input_files_clause
tree = ast.parse(sys.stdin.read())
fn = next(n for n in tree.body if isinstance(n, ast.AsyncFunctionDef) and n.name == 'stream_preview')
assignment = next(n for n in fn.body if isinstance(n, ast.Assign) and any(isinstance(t, ast.Name) and t.id == 'system' for t in n.targets))
runtime_scope_clause = 'This is a tool preview connected to the authenticated user’s real data. '
native_workspace_enabled = False
client_runtime_context = None
shell_clause = 'Shell commands are disabled. '
print(eval(compile(ast.Expression(assignment.value), '<canonical-system-expression>', 'eval')))
`], {input:fs.readFileSync('src/clean_agent_preview.py','utf8'),encoding:'utf8'}).trim();
}
for (const prompt of prompts) {
for (const choice of ['auto', 'required', {type:'function', function:{name:'web_search'}}]) {
const started = performance.now();
const response = await fetch(endpoint, {method:'POST', headers:{'Content-Type':'application/json'}, signal:AbortSignal.timeout(90000),
body:JSON.stringify({model, messages:[{role:'system',content:'You are Odysseus. Use web_search to find current information relevant to the user request.'},{role:'user',content:prompt}], tools, tool_choice:choice, temperature:0, max_tokens:256, stream:false, chat_template_kwargs:{enable_thinking:false}})});
body:JSON.stringify({model, messages:[{role:'system',content:system},{role:'user',content:prompt}], tools, tool_choice:choice, temperature:0, max_tokens:256, stream:false, chat_template_kwargs:{enable_thinking:false}})});
const data = await response.json();
const result = {prompt,choice,status:response.status,seconds:(performance.now()-started)/1000,message:data.choices?.[0]?.message,error:data.error};
results.push(result); console.log(JSON.stringify(result));
}
}
const target = `reports/search-tool-choice-probe-${Date.now()}.json`;
fs.writeFileSync(target, JSON.stringify({model,tools,results},null,2)+'\n');
fs.writeFileSync(target, JSON.stringify({model,system,tools,results},null,2)+'\n');
console.log(target);