chore: clean up tool example (#34512)
This commit is contained in:
parent
2c0576ea76
commit
ab01dccf9d
|
@ -91,11 +91,10 @@ async function openAIAgentLoop(page: playwright.Page, task: string) {
|
||||||
model: 'gpt-4o',
|
model: 'gpt-4o',
|
||||||
messages: toOpenAIMessages(history),
|
messages: toOpenAIMessages(history),
|
||||||
tools,
|
tools,
|
||||||
|
tool_choice: 'required',
|
||||||
store: true,
|
store: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(JSON.stringify(completion, null, 2));
|
|
||||||
|
|
||||||
const toolCalls = completion.choices[0]?.message?.tool_calls;
|
const toolCalls = completion.choices[0]?.message?.tool_calls;
|
||||||
if (!toolCalls || toolCalls.length !== 1 || toolCalls[0].type !== 'function') {
|
if (!toolCalls || toolCalls.length !== 1 || toolCalls[0].type !== 'function') {
|
||||||
history.push({ role: 'user', content: 'expected exactly one tool call', history: 'expected exactly one tool call' });
|
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) {
|
||||||
// Run the Playwright tool.
|
// Run the Playwright tool.
|
||||||
const params = JSON.parse(toolCall.function.arguments);
|
const params = JSON.parse(toolCall.function.arguments);
|
||||||
const { error, snapshot, code } = await browser.call(page, toolCall.function.name, params);
|
const { error, snapshot, code } = await browser.call(page, toolCall.function.name, params);
|
||||||
console.log({ error, code, snapshot });
|
|
||||||
if (code.length)
|
if (code.length)
|
||||||
console.log(code.join('\n'));
|
console.log(code.join('\n'));
|
||||||
|
|
||||||
|
@ -149,9 +147,6 @@ async function main() {
|
||||||
- Go to http://github.com/microsoft
|
- Go to http://github.com/microsoft
|
||||||
- Search for "playwright" repository
|
- Search for "playwright" repository
|
||||||
- Navigate to it
|
- Navigate to it
|
||||||
- Capture snapshot for toolbar with Code, Issues, etc.
|
|
||||||
- Capture snapshot for branch selector
|
|
||||||
- Assert that number of Issues is present
|
|
||||||
- Switch into the Issues tab
|
- Switch into the Issues tab
|
||||||
- Report 3 first issues
|
- Report 3 first issues
|
||||||
`);
|
`);
|
||||||
|
|
|
@ -126,6 +126,8 @@ async function performAction(page: playwright.Page, toolName: string, params: Re
|
||||||
if (toolName === 'navigate') {
|
if (toolName === 'navigate') {
|
||||||
code.push(`await page.goto(${JSON.stringify(params.url)})`);
|
code.push(`await page.goto(${JSON.stringify(params.url)})`);
|
||||||
await page.goto(params.url as string);
|
await page.goto(params.url as string);
|
||||||
|
} else if (toolName === 'wait') {
|
||||||
|
await page.waitForTimeout(Math.min(10000, params.time as number * 1000));
|
||||||
} else if (toolName === 'click') {
|
} else if (toolName === 'click') {
|
||||||
code.push(`await page.${await locator._generateLocatorString()}.click()`);
|
code.push(`await page.${await locator._generateLocatorString()}.click()`);
|
||||||
await locator.click();
|
await locator.click();
|
||||||
|
|
Loading…
Reference in New Issue