Skip to content

Commit

Permalink
feat: add AUTO_PLAYWRIGHT_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
lucgagan committed Nov 14, 2023
1 parent 56b8369 commit 663c8b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ You may pass a `debug` attribute as the third parameter to the `auto` function.
await auto("get the header text", { page, test }, { debug: true });
```
You may also set environment variable `AUTO_PLAYWRIGHT_DEBUG=true`, which will enable debugging for all `auto` calls.
```bash
export AUTO_PLAYWRIGHT_DEBUG=true
```
## Supported Browsers
Every browser that Playwright supports.
Expand Down
10 changes: 7 additions & 3 deletions src/completeTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { prompt } from "./prompt";
import { randomUUID } from "crypto";
import { z } from "zod";

const defaultDebug = process.env.AUTO_PLAYWRIGHT_DEBUG === "true";

export const completeTask = async (
page: Page,
task: TaskMessage
Expand All @@ -25,6 +27,8 @@ export const completeTask = async (
return locator;
};

const debug = task.options?.debug?? defaultDebug;

const runner = openai.beta.chat.completions
.runFunctions({
model: task.options?.model ?? "gpt-4-1106-preview",
Expand Down Expand Up @@ -591,7 +595,7 @@ export const completeTask = async (
],
})
.on("message", (message) => {
if (task.options?.debug) {
if (debug) {
console.log("> message", message);
}

Expand All @@ -605,15 +609,15 @@ export const completeTask = async (

const finalContent = await runner.finalContent();

if (task.options?.debug) {
if (debug) {
console.log("> finalContent", finalContent);
}

if (!lastFunctionResult) {
throw new Error("Expected to have result");
}

if (task.options?.debug) {
if (debug) {
console.log("> lastFunctionResult", lastFunctionResult);
}

Expand Down

0 comments on commit 663c8b2

Please sign in to comment.