Skip to content

Commit ab01dcc

Browse files
authored
chore: clean up tool example (#34512)
1 parent 2c0576e commit ab01dcc

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

packages/playwright-tools/src/examples/browser-openai.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ async function openAIAgentLoop(page: playwright.Page, task: string) {
9191
model: 'gpt-4o',
9292
messages: toOpenAIMessages(history),
9393
tools,
94+
tool_choice: 'required',
9495
store: true,
9596
});
9697

97-
console.log(JSON.stringify(completion, null, 2));
98-
9998
const toolCalls = completion.choices[0]?.message?.tool_calls;
10099
if (!toolCalls || toolCalls.length !== 1 || toolCalls[0].type !== 'function') {
101100
history.push({ role: 'user', content: 'expected exactly one tool call', history: 'expected exactly one tool call' });
@@ -113,7 +112,6 @@ async function openAIAgentLoop(page: playwright.Page, task: string) {
113112
// Run the Playwright tool.
114113
const params = JSON.parse(toolCall.function.arguments);
115114
const { error, snapshot, code } = await browser.call(page, toolCall.function.name, params);
116-
console.log({ error, code, snapshot });
117115
if (code.length)
118116
console.log(code.join('\n'));
119117

@@ -149,9 +147,6 @@ async function main() {
149147
- Go to http://github.com/microsoft
150148
- Search for "playwright" repository
151149
- Navigate to it
152-
- Capture snapshot for toolbar with Code, Issues, etc.
153-
- Capture snapshot for branch selector
154-
- Assert that number of Issues is present
155150
- Switch into the Issues tab
156151
- Report 3 first issues
157152
`);

packages/playwright-tools/src/tools/browser.ts

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ async function performAction(page: playwright.Page, toolName: string, params: Re
126126
if (toolName === 'navigate') {
127127
code.push(`await page.goto(${JSON.stringify(params.url)})`);
128128
await page.goto(params.url as string);
129+
} else if (toolName === 'wait') {
130+
await page.waitForTimeout(Math.min(10000, params.time as number * 1000));
129131
} else if (toolName === 'click') {
130132
code.push(`await page.${await locator._generateLocatorString()}.click()`);
131133
await locator.click();

0 commit comments

Comments
 (0)