Skip to content

Commit

Permalink
feat: using interaction history to perform assertions and assertion p…
Browse files Browse the repository at this point in the history
…rompt improvements
  • Loading branch information
Ryan Huellen committed Sep 17, 2024
1 parent 5bf1a3b commit b87069c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/common/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Page } from '@playwright/test';
import { type LanguageModel, generateObject } from 'ai';
import { type LanguageModel, type UserContent, generateObject } from 'ai';
import type { TestOptions } from '../types/TestOptions';

import { Assertion } from '../schemas/Assertion';
Expand All @@ -9,10 +9,30 @@ export const _assert = async (
languageModel: LanguageModel,
page: Page,
assertion: string,
{ maxRetries, temperature }: TestOptions['assertions'],
{ maxRetries, temperature, useHistory }: TestOptions['assertions'],
history?: string,
) => {
const screenshot = await fastScreenshot(page);

let userContent: UserContent = [
{
type: 'text',
text: `Desired Outcome:
${assertion}`,
},
];

if (useHistory && history !== undefined) {
userContent = [
...userContent,
{
type: 'text',
text: `Previously Performed Interactions:
${history}`,
},
];
}

const { object } = await generateObject({
model: languageModel,
schema: Assertion,
Expand All @@ -21,16 +41,15 @@ export const _assert = async (
messages: [
{
role: 'system',
content:
'You are an end user trying to achieve a goal. You are interacting with a website. Determine if the desired outcome has been achieved.',
content: `Who:
You are an end-user trying to achieve a goal by interacting with a website.
Task: Determine if the goal has been achieved.`,
},
{
role: 'user',
content: [
{
type: 'text',
text: `Desired Outcome: ${assertion}`,
},
...userContent,
{
type: 'image',
image: screenshot,
Expand Down
1 change: 1 addition & 0 deletions src/common/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const _test = (
page,
assertion,
assertions,
history,
);

if (goalAchieved) {
Expand Down
2 changes: 2 additions & 0 deletions src/types/TestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type TestOptions = {
maxRetries: number;
temperature: number;
immediate: boolean;
useHistory: boolean;
};
decisions: {
maxRetries: number;
Expand Down Expand Up @@ -43,6 +44,7 @@ export const DEFAULT_TEST_OPTIONS: TestOptions = {
maxRetries: 2,
temperature: 0.1,
immediate: false,
useHistory: true,
},
decisions: {
maxRetries: 3,
Expand Down

0 comments on commit b87069c

Please sign in to comment.