Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions demos/pizza-maker/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,35 @@ if (window.navigator.modelContext) {
return `Share URL: ${url}`;
},
});

if (new URLSearchParams(location.search).has('eval_tool')) {
navigator.modelContext.registerTool({
name: 'eval_code',
description:
'Use this tool to AUTOMATE pizza making by writing a JavaScript algorithm. ' +
'This is the best tool to use if you have to call multiple tools. ' +
'CRITICAL: All tool calls MUST follow this exact syntax: ' +
'await navigator.modelContextTesting.executeTool("tool_name", args); ' +
'Always end the script with an explicit return statement.',
inputSchema: {
type: 'object',
properties: {
code: {
type: 'string',
description:
'JavaScript code to execute. ' +
'REQUIRED SYNTAX: executeTool(name, args). ' +
'The "args" parameter MUST be passed as a JSON string. ' +
'Example: await navigator.modelContextTesting.executeTool("add_topping", JSON.stringify({ topping: "🍍" }));',
},
},
required: ['code'],
},
async execute({ code }) {
return new Function(`return (async () => { ${code} })();`)();
},
});
}
}

// Expose functions to global scope for HTML onclick handlers
Expand Down
Loading