Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): llm conversation about error #34750

Merged
merged 38 commits into from
Feb 14, 2025

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Feb 12, 2025

Screen.Recording.2025-02-12.at.14.40.31.mov

@Skn0tt Skn0tt requested a review from agg23 February 12, 2025 13:43
@Skn0tt Skn0tt self-assigned this Feb 12, 2025
@Skn0tt Skn0tt requested a review from dgozman February 12, 2025 13:52
packages/playwright-core/src/utils/isomorphic/llm.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/utils/isomorphic/llm.ts Outdated Show resolved Hide resolved
tests/playwright-test/ui-mode-llm.spec.ts Outdated Show resolved Hide resolved
packages/trace-viewer/src/sw/main.ts Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/errorsTab.tsx Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/llm.tsx Show resolved Hide resolved
packages/trace-viewer/src/ui/aiConversation.css Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/llm.tsx Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/aiConversation.tsx Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/aiConversation.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@agg23 agg23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good. Mostly nitpicking things or asking questions.

packages/playwright-core/src/utils/isomorphic/llm.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/utils/isomorphic/llm.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/utils/isomorphic/llm.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/utils/isomorphic/llm.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/utils/isomorphic/llm.ts Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/aiConversation.css Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/aiConversation.css Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/aiConversation.css Outdated Show resolved Hide resolved
packages/web/src/uiUtils.ts Outdated Show resolved Hide resolved
@@ -142,6 +142,16 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
server.routePath('/', (_, response) => {
response.statusCode = 302;
response.setHeader('Location', urlPath);

if (process.env.OPENAI_API_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to not work with PW_HMR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me follow up on that

</div>}
<span style={{ position: 'absolute', right: '5px' }}>
{llmAvailable
? <ToolbarButton onClick={() => setShowLLM(v => !v)} style={{ width: '96px', justifyContent: 'center' }} title='Fix with AI' className='copy-to-clipboard-text-button'>{showLLM ? 'Hide AI' : 'Fix with AI'}</ToolbarButton>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiding then pressing this button again should not re-execute the conversation (I believe it's sending all existing messages, plus the system prompt again as the last message). There should be a separate button somewhere to restart the conversation when AI mode is visible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's follow up on that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do feel strongly about this. It's surprising that showing a component sends a message to llm. I'd much prefer if the first send was right here, as a reaction to the Fix with AI button click. This way we'll also be able to make it only do that once.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've refactored it to create the conversation and send the first message only on click, not on component mount

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

12 flaky ⚠️ [firefox-page] › tests/page/page-evaluate.spec.ts:403:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [playwright-test] › tests/ui-mode-test-ct.spec.ts:117:5 › should run component tests after editing test and component @ubuntu-latest-node22-1
⚠️ [playwright-test] › tests/ui-mode-test-watch.spec.ts:145:5 › should watch all @ubuntu-latest-node22-1
⚠️ [webkit-library] › tests/library/browsercontext-fetchFailOnStatusCode.spec.ts:43:3 › should throw when apiRequestFailsOnErrorStatus is set to true inside browserType.launchPersistentContext options @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/selector-generator.spec.ts:352:5 › selector generator › should match in shadow dom @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/trace-viewer.spec.ts:355:1 › should have network requests @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/tracing.spec.ts:545:5 › should export trace concurrently to second navigation @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:82:5 › click should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:107:5 › fill should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:161:5 › waitFor should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-screenshot.spec.ts:345:5 › page screenshot › should work while navigating @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-set-input-files.spec.ts:204:5 › should upload large file with relative path @webkit-ubuntu-22.04-node18

38562 passed, 793 skipped
✔️✔️✔️

Merge workflow run.

</div>}
<span style={{ position: 'absolute', right: '5px' }}>
{llmAvailable
? <ToolbarButton onClick={() => setShowLLM(v => !v)} style={{ width: '96px', justifyContent: 'center' }} title='Fix with AI' className='copy-to-clipboard-text-button'>{showLLM ? 'Hide AI' : 'Fix with AI'}</ToolbarButton>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do feel strongly about this. It's surprising that showing a component sends a message to llm. I'd much prefer if the first send was right here, as a reaction to the Fix with AI button click. This way we'll also be able to make it only do that once.

packages/trace-viewer/src/ui/errorsTab.tsx Outdated Show resolved Hide resolved
const chat = useLLMChat();
if (!chat)
throw new Error('No LLM chat available, make sure theres a LLMProvider above');
const conversation = React.useMemo(() => chat.getConversation(id, systemPrompt), [chat, id]); // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience, linter was always correct and I was always incorrect, so I always doubt disabling this rule 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out that a little refactoring made it disappear :D

package.json Outdated
@@ -102,6 +102,7 @@
"node-stream-zip": "^1.15.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-markdown": "^9.0.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's look for a smaller dependency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After briefly trying to adapt https://github.com/developit/snarkdown to write our own React component for this, I gave up and used https://github.com/quantizor/markdown-to-jsx instead. It's 6kb gzipped.

packages/trace-viewer/src/ui/llm.tsx Show resolved Hide resolved
onClick={() => {
if (!chat.getConversation(conversationId)) {
const conversation = chat.startConversation(conversationId, [
`My Playwright test failed. What's going wrong?`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different from fixTestPrompt? I feel like we should probably reuse them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is different, because we can make a difference between system prompts, visible prompt contents and actual prompt contents. None of that works with the copy prompt buttons.

packages/trace-viewer/src/ui/llm.tsx Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/aiConversation.tsx Outdated Show resolved Hide resolved
@Skn0tt Skn0tt merged commit fe0b327 into microsoft:main Feb 14, 2025
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants